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.
|
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
2003-08-23 00:17:00 +00:00
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
* \author Angus Leeming
|
|
|
|
* \author John Levon
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pönitz
|
2003-08-23 00:17:00 +00:00
|
|
|
* \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.
|
2010-10-23 18:35:13 +00:00
|
|
|
vcs.reset(0);
|
1999-09-27 18:44:28 +00:00
|
|
|
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.
|
2010-01-08 18:48:36 +00:00
|
|
|
if (!RCS::findFile(fn).empty()) {
|
2010-04-21 01:19:09 +00:00
|
|
|
docstring const file = makeDisplayPath(fn.absFileName(), 20);
|
2010-01-08 18:48:36 +00:00
|
|
|
docstring const text =
|
|
|
|
bformat(_("Do you want to retrieve the document"
|
|
|
|
" %1$s from version control?"), file);
|
|
|
|
int const ret = Alert::prompt(_("Retrieve from version control?"),
|
|
|
|
text, 0, 1, _("&Retrieve"), _("&Cancel"));
|
|
|
|
|
|
|
|
if (ret == 0) {
|
|
|
|
// How can we know _how_ to do the checkout?
|
|
|
|
// With the current VC support it has to be an RCS
|
|
|
|
// file since CVS and SVN do not have special ,v files.
|
|
|
|
RCS::retrieve(fn);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 00:14:55 +00:00
|
|
|
bool LyXVC::registrer()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
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."));
|
2009-01-08 00:14:55 +00:00
|
|
|
return false;
|
2002-05-31 01:14:53 +00:00
|
|
|
}
|
|
|
|
|
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
|
2010-04-21 01:19:09 +00:00
|
|
|
FileName const cvs_entries(onlyPath(filename.absFileName()) + "/CVS/Entries");
|
|
|
|
FileName const svn_entries(onlyPath(filename.absFileName()) + "/.svn/entries");
|
2008-07-22 08:59:15 +00:00
|
|
|
|
|
|
|
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");
|
2008-10-27 01:06:24 +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)"));
|
2008-10-30 13:47:41 +00:00
|
|
|
if (!ok) {
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::LYXVC, "LyXVC: user cancelled");
|
2010-10-24 13:26:00 +00:00
|
|
|
vcs.reset(0);
|
2009-01-08 00:14:55 +00:00
|
|
|
return false;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2008-10-30 13:47:41 +00:00
|
|
|
if (response.empty())
|
|
|
|
response = _("(no initial description)");
|
2007-11-13 23:00:36 +00:00
|
|
|
vcs->registrer(to_utf8(response));
|
2009-01-08 00:14:55 +00:00
|
|
|
return true;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-29 13:14:51 +00:00
|
|
|
string LyXVC::checkIn()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::LYXVC, "LyXVC: checkIn");
|
2010-01-10 21:18:41 +00:00
|
|
|
docstring empty(_("(no log message)"));
|
2007-11-13 23:00:36 +00:00
|
|
|
docstring response;
|
2008-07-29 13:14:51 +00:00
|
|
|
string log;
|
2010-10-25 13:27:48 +00:00
|
|
|
bool ok = true;
|
|
|
|
if (vcs->isCheckInWithConfirmation())
|
|
|
|
ok = Alert::askForText(response, _("LyX VC: Log Message"));
|
2007-11-13 23:00:36 +00:00
|
|
|
if (ok) {
|
|
|
|
if (response.empty())
|
2010-01-10 21:18:41 +00:00
|
|
|
response = empty;
|
2008-07-29 13:14:51 +00:00
|
|
|
log = vcs->checkIn(to_utf8(response));
|
2010-01-10 21:18:41 +00:00
|
|
|
|
|
|
|
// Reserve empty string for cancel button
|
|
|
|
if (log.empty())
|
|
|
|
log = to_utf8(empty);
|
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
|
|
|
}
|
2008-07-29 13:14:51 +00:00
|
|
|
return log;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-29 13:14:51 +00:00
|
|
|
string LyXVC::checkOut()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2008-07-22 10:16:12 +00:00
|
|
|
//RCS allows checkOut only in ReadOnly mode
|
2010-03-11 19:40:11 +00:00
|
|
|
if (vcs->toggleReadOnlyEnabled() && !owner_->isReadonly())
|
|
|
|
return string();
|
2008-07-22 10:16:12 +00:00
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::LYXVC, "LyXVC: checkOut");
|
2008-07-29 13:14:51 +00:00
|
|
|
return vcs->checkOut();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-14 19:18:06 +00:00
|
|
|
string LyXVC::repoUpdate()
|
2009-10-06 23:20:52 +00:00
|
|
|
{
|
2009-10-14 19:18:06 +00:00
|
|
|
LYXERR(Debug::LYXVC, "LyXVC: repoUpdate");
|
|
|
|
return vcs->repoUpdate();
|
2009-10-06 23:20:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-25 14:48:11 +00:00
|
|
|
string LyXVC::lockingToggle()
|
|
|
|
{
|
|
|
|
LYXERR(Debug::LYXVC, "LyXVC: toggle locking property");
|
|
|
|
return vcs->lockingToggle();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-06 11:54:08 +00:00
|
|
|
bool LyXVC::revert()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
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 "
|
2008-07-22 10:16:30 +00:00
|
|
|
"document %1$s will lose all current changes.\n\n"
|
|
|
|
"Do you want to revert to the older version?"), file);
|
2010-10-25 13:27:48 +00:00
|
|
|
int ret = 0;
|
|
|
|
if (vcs->isRevertWithConfirmation())
|
|
|
|
ret = Alert::prompt(_("Revert to stored version of document?"),
|
|
|
|
text, 0, 1, _("&Revert"), _("&Cancel"));
|
2003-03-29 07:09:13 +00:00
|
|
|
|
2010-11-06 11:54:08 +00:00
|
|
|
return ret == 0 && 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;
|
2009-02-01 23:46:41 +00:00
|
|
|
case VCS::NOLOCKING:
|
2009-02-01 23:27:58 +00:00
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-31 14:40:02 +00:00
|
|
|
bool LyXVC::inUse() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
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::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
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-12 07:21:11 +00:00
|
|
|
bool LyXVC::locking() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2010-02-12 07:21:11 +00:00
|
|
|
return vcs->status() != VCS::NOLOCKING;
|
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);
|
2010-04-21 01:19:09 +00:00
|
|
|
return tmpf.absFileName();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
2010-09-07 11:29:05 +00:00
|
|
|
string LyXVC::revisionInfo(RevisionInfo const info) const
|
2010-02-12 01:43:59 +00:00
|
|
|
{
|
|
|
|
if (!vcs)
|
|
|
|
return string();
|
|
|
|
|
|
|
|
return vcs->revisionInfo(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-31 14:40:02 +00:00
|
|
|
bool LyXVC::checkOutEnabled() const
|
2008-07-21 01:55:58 +00:00
|
|
|
{
|
|
|
|
return vcs && vcs->checkOutEnabled();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-31 14:40:02 +00:00
|
|
|
bool LyXVC::checkInEnabled() const
|
2008-07-21 01:55:58 +00:00
|
|
|
{
|
|
|
|
return vcs && vcs->checkInEnabled();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-31 14:40:02 +00:00
|
|
|
bool LyXVC::lockingToggleEnabled() const
|
2009-06-25 14:48:11 +00:00
|
|
|
{
|
|
|
|
return vcs && vcs->lockingToggleEnabled();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-31 14:40:02 +00:00
|
|
|
bool LyXVC::undoLastEnabled() const
|
2008-07-21 01:55:58 +00:00
|
|
|
{
|
|
|
|
return vcs && vcs->undoLastEnabled();
|
|
|
|
}
|
|
|
|
|
2010-10-08 05:26:12 +00:00
|
|
|
|
|
|
|
bool LyXVC::repoUpdateEnabled() const
|
|
|
|
{
|
|
|
|
return vcs && vcs->repoUpdateEnabled();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-15 07:10:59 +00:00
|
|
|
bool LyXVC::prepareFileRevision(string const & rev, std::string & f)
|
2010-02-12 12:16:34 +00:00
|
|
|
{
|
|
|
|
return vcs && vcs->prepareFileRevision(rev, f);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LyXVC::prepareFileRevisionEnabled()
|
|
|
|
{
|
|
|
|
return vcs && vcs->prepareFileRevisionEnabled();
|
|
|
|
}
|
2008-07-21 01:55:58 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|