2003-08-23 00:17:00 +00:00
|
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
|
* \file LyXVC.cpp
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
|
* \author Angus Leeming
|
|
|
|
|
* \author John Levon
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
* \author Allan Rae
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "LyXVC.h"
|
|
|
|
|
#include "VCBackend.h"
|
|
|
|
|
#include "Buffer.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2007-04-28 20:44:46 +00:00
|
|
|
|
#include "frontends/alert.h"
|
2002-03-25 22:07:48 +00:00
|
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
|
#include "support/debug.h"
|
2002-03-25 22:07:48 +00:00
|
|
|
|
#include "support/filetools.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
|
#include "support/gettext.h"
|
2007-11-13 23:50:28 +00:00
|
|
|
|
#include "support/lstrings.h"
|
2002-03-25 22:07:48 +00:00
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
|
using namespace lyx::support;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
|
namespace Alert = frontend::Alert;
|
2006-10-07 16:47:54 +00:00
|
|
|
|
|
2003-05-13 09:48:57 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
LyXVC::LyXVC()
|
|
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
|
owner_ = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-03 17:47:28 +00:00
|
|
|
|
// for the sake of boost::scoped_ptr
|
1999-09-27 18:44:28 +00:00
|
|
|
|
LyXVC::~LyXVC()
|
2003-11-03 17:47:28 +00:00
|
|
|
|
{}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
2006-12-02 16:07:15 +00:00
|
|
|
|
bool LyXVC::file_found_hook(FileName const & fn)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2006-12-02 16:07:15 +00:00
|
|
|
|
FileName found_file;
|
1999-11-09 23:52:04 +00:00
|
|
|
|
// Check if file is under RCS
|
2007-11-25 11:18:16 +00:00
|
|
|
|
if (!(found_file = RCS::findFile(fn)).empty()) {
|
2003-11-03 17:47:28 +00:00
|
|
|
|
vcs.reset(new RCS(found_file));
|
1999-11-09 23:52:04 +00:00
|
|
|
|
vcs->owner(owner_);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
// Check if file is under CVS
|
2007-11-25 11:18:16 +00:00
|
|
|
|
if (!(found_file = CVS::findFile(fn)).empty()) {
|
2003-11-03 17:47:28 +00:00
|
|
|
|
vcs.reset(new CVS(found_file, fn));
|
1999-11-09 23:52:04 +00:00
|
|
|
|
vcs->owner(owner_);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2008-07-22 08:59:15 +00:00
|
|
|
|
// Check if file is under SVN
|
|
|
|
|
if (!(found_file = SVN::findFile(fn)).empty()) {
|
|
|
|
|
vcs.reset(new SVN(found_file, fn));
|
|
|
|
|
vcs->owner(owner_);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// file is not under any VCS.
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-12-02 16:07:15 +00:00
|
|
|
|
bool LyXVC::file_not_found_hook(FileName const & fn)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2008-07-22 08:59:47 +00:00
|
|
|
|
// Check if file is under RCS.
|
|
|
|
|
// This happens if we are trying to load non existent
|
|
|
|
|
// file on disk, but existent in ,v version.
|
|
|
|
|
// Seems there is no reasonable scenario for adding implementation
|
|
|
|
|
// of retrieve for cvs or svn.
|
2007-11-25 11:18:16 +00:00
|
|
|
|
if (!RCS::findFile(fn).empty())
|
2000-01-11 08:23:07 +00:00
|
|
|
|
return true;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-10-20 17:35:27 +00:00
|
|
|
|
void LyXVC::setBuffer(Buffer * buf)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
|
owner_ = buf;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXVC::registrer()
|
|
|
|
|
{
|
2007-11-03 17:37:37 +00:00
|
|
|
|
FileName const filename = owner_->fileName();
|
2002-12-01 22:59:25 +00:00
|
|
|
|
|
2002-05-31 01:14:53 +00:00
|
|
|
|
// there must be a file to save
|
2007-11-25 11:18:16 +00:00
|
|
|
|
if (!filename.isReadableFile()) {
|
2006-09-11 08:54:10 +00:00
|
|
|
|
Alert::error(_("Document not saved"),
|
|
|
|
|
_("You must save the document "
|
|
|
|
|
"before it can be registered."));
|
2002-05-31 01:14:53 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
1999-11-09 23:52:04 +00:00
|
|
|
|
// it is very likely here that the vcs is not created yet...
|
|
|
|
|
if (!vcs) {
|
2008-07-21 00:18:19 +00:00
|
|
|
|
//check in the root directory of the document
|
|
|
|
|
FileName const cvs_entries(onlyPath(filename.absFilename()) + "/CVS/Entries");
|
2008-07-22 08:59:15 +00:00
|
|
|
|
FileName const svn_entries(onlyPath(filename.absFilename()) + "/.svn/entries");
|
|
|
|
|
|
|
|
|
|
if (svn_entries.isReadableFile()) {
|
|
|
|
|
LYXERR(Debug::LYXVC, "LyXVC: registering "
|
|
|
|
|
<< to_utf8(filename.displayName()) << " with SVN");
|
|
|
|
|
vcs.reset(new SVN(cvs_entries, filename));
|
2002-03-26 12:11:43 +00:00
|
|
|
|
|
2008-07-22 08:59:15 +00:00
|
|
|
|
} else if (cvs_entries.isReadableFile()) {
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::LYXVC, "LyXVC: registering "
|
|
|
|
|
<< to_utf8(filename.displayName()) << " with CVS");
|
2003-11-03 17:47:28 +00:00
|
|
|
|
vcs.reset(new CVS(cvs_entries, filename));
|
2002-03-26 12:11:43 +00:00
|
|
|
|
|
|
|
|
|
} else {
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::LYXVC, "LyXVC: registering "
|
|
|
|
|
<< to_utf8(filename.displayName()) << " with RCS");
|
2003-11-03 17:47:28 +00:00
|
|
|
|
vcs.reset(new RCS(filename));
|
2002-03-26 12:11:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-11-09 23:52:04 +00:00
|
|
|
|
vcs->owner(owner_);
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::LYXVC, "LyXVC: registrer");
|
2007-11-13 23:00:36 +00:00
|
|
|
|
docstring response;
|
|
|
|
|
bool ok = Alert::askForText(response, _("LyX VC: Initial description"),
|
|
|
|
|
_("(no initial description)"));
|
|
|
|
|
if (!ok || response.empty()) {
|
|
|
|
|
// should we insist on checking response.empty()?
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::LYXVC, "LyXVC: user cancelled");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2007-11-13 23:00:36 +00:00
|
|
|
|
vcs->registrer(to_utf8(response));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXVC::checkIn()
|
|
|
|
|
{
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::LYXVC, "LyXVC: checkIn");
|
2007-11-13 23:00:36 +00:00
|
|
|
|
docstring response;
|
|
|
|
|
bool ok = Alert::askForText(response, _("LyX VC: Log Message"));
|
|
|
|
|
if (ok) {
|
|
|
|
|
if (response.empty())
|
|
|
|
|
response = _("(no log message)");
|
|
|
|
|
vcs->checkIn(to_utf8(response));
|
1999-12-30 02:35:43 +00:00
|
|
|
|
} else {
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::LYXVC, "LyXVC: user cancelled");
|
1999-12-30 02:35:43 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXVC::checkOut()
|
|
|
|
|
{
|
2008-07-22 10:16:12 +00:00
|
|
|
|
//RCS allows checkOut only in ReadOnly mode
|
|
|
|
|
if (vcs->toggleReadOnlyEnabled() && !owner_->isReadonly()) return;
|
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::LYXVC, "LyXVC: checkOut");
|
1999-11-09 23:52:04 +00:00
|
|
|
|
vcs->checkOut();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXVC::revert()
|
|
|
|
|
{
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::LYXVC, "LyXVC: revert");
|
1999-11-09 23:52:04 +00:00
|
|
|
|
|
2007-11-03 17:37:37 +00:00
|
|
|
|
docstring const file = owner_->fileName().displayName(20);
|
2006-09-11 08:54:10 +00:00
|
|
|
|
docstring text = bformat(_("Reverting to the stored version of the "
|
2003-05-13 09:48:57 +00:00
|
|
|
|
"document %1$s will lose all current changes.\n\n"
|
2006-09-11 08:54:10 +00:00
|
|
|
|
"Do you want to revert to the saved version?"), file);
|
|
|
|
|
int const ret = Alert::prompt(_("Revert to stored version of document?"),
|
|
|
|
|
text, 0, 1, _("&Revert"), _("&Cancel"));
|
2003-03-29 07:09:13 +00:00
|
|
|
|
|
|
|
|
|
if (ret == 0)
|
1999-11-09 23:52:04 +00:00
|
|
|
|
vcs->revert();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXVC::undoLast()
|
|
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
|
vcs->undoLast();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXVC::toggleReadOnly()
|
|
|
|
|
{
|
2008-07-22 09:00:05 +00:00
|
|
|
|
if (!vcs->toggleReadOnlyEnabled())
|
|
|
|
|
return;
|
|
|
|
|
|
2000-05-17 16:42:35 +00:00
|
|
|
|
switch (vcs->status()) {
|
1999-11-09 23:52:04 +00:00
|
|
|
|
case VCS::UNLOCKED:
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::LYXVC, "LyXVC: toggle to locked");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
checkOut();
|
|
|
|
|
break;
|
1999-11-09 23:52:04 +00:00
|
|
|
|
case VCS::LOCKED:
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::LYXVC, "LyXVC: toggle to unlocked");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
checkIn();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool LyXVC::inUse()
|
|
|
|
|
{
|
2007-10-20 17:35:27 +00:00
|
|
|
|
if (vcs)
|
|
|
|
|
return true;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-08-19 14:06:27 +00:00
|
|
|
|
//string const & LyXVC::version() const
|
|
|
|
|
//{
|
|
|
|
|
// return vcs->version();
|
|
|
|
|
//}
|
|
|
|
|
|
2007-10-20 17:35:27 +00:00
|
|
|
|
|
2001-08-19 14:06:27 +00:00
|
|
|
|
string const LyXVC::versionString() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-08-19 14:06:27 +00:00
|
|
|
|
return vcs->versionString();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-11-09 23:52:04 +00:00
|
|
|
|
string const & LyXVC::locker() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
|
return vcs->locker();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-11-09 23:52:04 +00:00
|
|
|
|
|
2003-06-28 01:23:11 +00:00
|
|
|
|
string const LyXVC::getLogFile() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-02-06 17:41:42 +00:00
|
|
|
|
if (!vcs)
|
|
|
|
|
return string();
|
1999-10-25 14:18:30 +00:00
|
|
|
|
|
2007-12-16 09:52:36 +00:00
|
|
|
|
FileName const tmpf = FileName::tempName("lyxvclog");
|
2004-02-25 12:00:53 +00:00
|
|
|
|
if (tmpf.empty()) {
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
|
2004-02-25 12:00:53 +00:00
|
|
|
|
return string();
|
|
|
|
|
}
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::LYXVC, "Generating logfile " << tmpf);
|
1999-11-09 23:52:04 +00:00
|
|
|
|
vcs->getLog(tmpf);
|
2006-12-02 16:07:15 +00:00
|
|
|
|
return tmpf.absFilename();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
2008-07-21 01:55:58 +00:00
|
|
|
|
bool LyXVC::checkOutEnabled()
|
|
|
|
|
{
|
|
|
|
|
return vcs && vcs->checkOutEnabled();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool LyXVC::checkInEnabled()
|
|
|
|
|
{
|
|
|
|
|
return vcs && vcs->checkInEnabled();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool LyXVC::undoLastEnabled()
|
|
|
|
|
{
|
|
|
|
|
return vcs && vcs->undoLastEnabled();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
} // namespace lyx
|