2003-08-23 00:17:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file lyxvc.C
|
|
|
|
|
* 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>
|
|
|
|
|
|
|
|
|
|
#include "lyxvc.h"
|
1999-11-09 23:52:04 +00:00
|
|
|
|
#include "vc-backend.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
|
#include "debug.h"
|
1999-11-09 23:52:04 +00:00
|
|
|
|
#include "buffer.h"
|
2002-05-27 00:41:32 +00:00
|
|
|
|
#include "gettext.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-03-25 22:07:48 +00:00
|
|
|
|
#include "frontends/Alert.h"
|
|
|
|
|
|
|
|
|
|
#include "support/filetools.h"
|
|
|
|
|
#include "support/lyxlib.h"
|
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
|
using support::bformat;
|
2006-11-26 21:30:39 +00:00
|
|
|
|
using support::FileName;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
using support::isFileReadable;
|
2006-11-26 21:30:39 +00:00
|
|
|
|
using support::makeAbsPath;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
using support::makeDisplayPath;
|
|
|
|
|
using support::tempName;
|
2006-09-11 08:54:10 +00:00
|
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
|
using std::endl;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2000-04-04 00:19:15 +00:00
|
|
|
|
using std::pair;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
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
|
|
|
|
|
if (!(found_file = RCS::find_file(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
|
|
|
|
|
if (!(found_file = CVS::find_file(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;
|
|
|
|
|
}
|
|
|
|
|
// 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
|
|
|
|
{
|
2000-01-11 08:23:07 +00:00
|
|
|
|
// Check if file is under RCS
|
|
|
|
|
if (!RCS::find_file(fn).empty())
|
|
|
|
|
return true;
|
|
|
|
|
if (!CVS::find_file(fn).empty())
|
|
|
|
|
return true;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-11-09 23:52:04 +00:00
|
|
|
|
void LyXVC::buffer(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()
|
|
|
|
|
{
|
2006-12-02 16:07:15 +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
|
2006-12-02 16:07:15 +00:00
|
|
|
|
if (!isFileReadable(filename)) {
|
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) {
|
2006-12-02 16:07:15 +00:00
|
|
|
|
FileName const cvs_entries(makeAbsPath("CVS/Entries"));
|
2002-03-26 12:11:43 +00:00
|
|
|
|
|
2006-12-02 16:07:15 +00:00
|
|
|
|
if (isFileReadable(cvs_entries)) {
|
2002-03-26 12:11:43 +00:00
|
|
|
|
lyxerr[Debug::LYXVC]
|
|
|
|
|
<< "LyXVC: registering "
|
2006-12-02 16:07:15 +00:00
|
|
|
|
<< to_utf8(makeDisplayPath(filename.absFilename()))
|
2002-03-26 12:11:43 +00:00
|
|
|
|
<< " with CVS" << endl;
|
2003-11-03 17:47:28 +00:00
|
|
|
|
vcs.reset(new CVS(cvs_entries, filename));
|
2002-03-26 12:11:43 +00:00
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr[Debug::LYXVC]
|
|
|
|
|
<< "LyXVC: registering "
|
2006-12-02 16:07:15 +00:00
|
|
|
|
<< to_utf8(makeDisplayPath(filename.absFilename()))
|
2002-03-26 12:11:43 +00:00
|
|
|
|
<< " with RCS" << endl;
|
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
|
|
|
|
|
1999-10-07 18:44:17 +00:00
|
|
|
|
lyxerr[Debug::LYXVC] << "LyXVC: registrer" << endl;
|
2006-09-11 08:54:10 +00:00
|
|
|
|
pair<bool, docstring> tmp =
|
|
|
|
|
Alert::askForText(_("LyX VC: Initial description"),
|
|
|
|
|
_("(no initial description)"));
|
1999-12-30 02:35:43 +00:00
|
|
|
|
if (!tmp.first || tmp.second.empty()) {
|
|
|
|
|
// should we insist on checking tmp.second.empty()?
|
1999-10-07 18:44:17 +00:00
|
|
|
|
lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
vcs->registrer(to_utf8(tmp.second));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXVC::checkIn()
|
|
|
|
|
{
|
|
|
|
|
|
1999-10-07 18:44:17 +00:00
|
|
|
|
lyxerr[Debug::LYXVC] << "LyXVC: checkIn" << endl;
|
2006-09-11 08:54:10 +00:00
|
|
|
|
pair<bool, docstring> tmp = Alert::askForText(_("LyX VC: Log Message"));
|
1999-12-30 02:35:43 +00:00
|
|
|
|
if (tmp.first) {
|
|
|
|
|
if (tmp.second.empty()) {
|
2006-09-11 08:54:10 +00:00
|
|
|
|
tmp.second = _("(no log message)");
|
1999-12-30 02:35:43 +00:00
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
vcs->checkIn(to_utf8(tmp.second));
|
1999-12-30 02:35:43 +00:00
|
|
|
|
} else {
|
|
|
|
|
lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXVC::checkOut()
|
|
|
|
|
{
|
1999-10-07 18:44:17 +00:00
|
|
|
|
lyxerr[Debug::LYXVC] << "LyXVC: checkOut" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-11-09 23:52:04 +00:00
|
|
|
|
vcs->checkOut();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXVC::revert()
|
|
|
|
|
{
|
1999-10-07 18:44:17 +00:00
|
|
|
|
lyxerr[Debug::LYXVC] << "LyXVC: revert" << endl;
|
1999-11-09 23:52:04 +00:00
|
|
|
|
|
2006-09-11 08:54:10 +00:00
|
|
|
|
docstring const file = makeDisplayPath(owner_->fileName(), 20);
|
|
|
|
|
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()
|
|
|
|
|
{
|
2000-05-17 16:42:35 +00:00
|
|
|
|
switch (vcs->status()) {
|
1999-11-09 23:52:04 +00:00
|
|
|
|
case VCS::UNLOCKED:
|
|
|
|
|
lyxerr[Debug::LYXVC] << "LyXVC: toggle to locked" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
checkOut();
|
|
|
|
|
break;
|
1999-11-09 23:52:04 +00:00
|
|
|
|
case VCS::LOCKED:
|
|
|
|
|
lyxerr[Debug::LYXVC] << "LyXVC: toggle to unlocked" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
checkIn();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool LyXVC::inUse()
|
|
|
|
|
{
|
1999-11-09 23:52:04 +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();
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2006-12-02 16:07:15 +00:00
|
|
|
|
FileName const tmpf(tempName(string(), "lyxvclog"));
|
2004-02-25 12:00:53 +00:00
|
|
|
|
if (tmpf.empty()) {
|
|
|
|
|
lyxerr[Debug::LYXVC] << "Could not generate logfile "
|
2006-04-05 23:56:29 +00:00
|
|
|
|
<< tmpf << endl;
|
2004-02-25 12:00:53 +00:00
|
|
|
|
return string();
|
|
|
|
|
}
|
2001-02-06 17:41:42 +00:00
|
|
|
|
lyxerr[Debug::LYXVC] << "Generating logfile " << tmpf << endl;
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|