3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
9 * Full author contact details are available in file CREDITS.
14 #include "VCBackend.h"
16 #include "DispatchResult.h"
18 #include "FuncRequest.h"
20 #include "frontends/alert.h"
21 #include "frontends/Application.h"
23 #include "support/convert.h"
24 #include "support/debug.h"
25 #include "support/filetools.h"
26 #include "support/gettext.h"
27 #include "support/lstrings.h"
28 #include "support/PathChanger.h"
29 #include "support/Systemcall.h"
30 #include "support/regex.h"
31 #include "support/TempFile.h"
36 using namespace lyx::support;
42 int VCS::doVCCommandCall(string const & cmd, FileName const & path)
44 LYXERR(Debug::LYXVC, "doVCCommandCall: " << cmd);
46 support::PathChanger p(path);
47 return one.startscript(Systemcall::Wait, cmd, string(), string(), false);
51 int VCS::doVCCommand(string const & cmd, FileName const & path, bool reportError)
54 owner_->setBusy(true);
56 int const ret = doVCCommandCall(cmd, path);
59 owner_->setBusy(false);
60 if (ret && reportError)
61 frontend::Alert::error(_("Revision control error."),
62 bformat(_("Some problem occurred while running the command:\n"
69 bool VCS::makeRCSRevision(string const &version, string &revis) const
74 int back = convert<int>(rev);
75 // if positive use as the last number in the whole revision string
78 rsplit(version, base , '.');
79 rev = base + '.' + rev;
83 // we care about the last number from revision string
84 // in case of backward indexing
87 cur = rsplit(version, base , '.');
90 int want = convert<int>(cur) + back;
94 rev = base + '.' + convert<string>(want);
103 bool VCS::checkparentdirs(FileName const & file, std::string const & vcsdir)
105 FileName dirname = file.onlyPath();
107 FileName tocheck = FileName(addName(dirname.absFileName(), vcsdir));
108 LYXERR(Debug::LYXVC, "check file: " << tocheck.absFileName());
109 if (tocheck.exists())
111 //this construct because of #8295
112 dirname = FileName(dirname.absFileName()).parentPath();
113 } while (!dirname.empty());
118 /////////////////////////////////////////////////////////////////////
122 /////////////////////////////////////////////////////////////////////
124 RCS::RCS(FileName const & m, Buffer * b) : VCS(b)
126 // Here we know that the buffer file is either already in RCS or
127 // about to be registered
133 FileName const RCS::findFile(FileName const & file)
135 // Check if *,v exists.
136 FileName tmp(file.absFileName() + ",v");
137 LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under rcs: " << tmp);
138 if (tmp.isReadableFile()) {
139 LYXERR(Debug::LYXVC, "Yes, " << file << " is under rcs.");
143 // Check if RCS/*,v exists.
144 tmp = FileName(addName(addPath(onlyPath(file.absFileName()), "RCS"), file.absFileName()) + ",v");
145 LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under rcs: " << tmp);
146 if (tmp.isReadableFile()) {
147 LYXERR(Debug::LYXVC, "Yes, " << file << " is under rcs.");
155 bool RCS::retrieve(FileName const & file)
157 LYXERR(Debug::LYXVC, "LyXVC::RCS: retrieve.\n\t" << file);
158 // The caller ensures that file does not exist, so no need to check that.
159 return doVCCommandCall("co -q -r " + quoteName(file.toFilesystemEncoding()),
164 void RCS::scanMaster()
169 LYXERR(Debug::LYXVC, "LyXVC::RCS: scanMaster: " << master_);
171 ifstream ifs(master_.toFilesystemEncoding().c_str());
174 bool read_enough = false;
176 while (!read_enough && ifs >> token) {
177 LYXERR(Debug::LYXVC, "LyXVC::scanMaster: current lex text: `"
182 else if (token == "head") {
186 tmv = rtrim(tmv, ";");
188 LYXERR(Debug::LYXVC, "LyXVC: version found to be " << tmv);
189 } else if (contains(token, "access")
190 || contains(token, "symbols")
191 || contains(token, "strict")) {
193 } else if (contains(token, "locks")) {
195 if (contains(token, ';')) {
196 locker_ = "Unlocked";
205 s1 = rtrim(tmpt, ";");
206 // tmp is now in the format <user>:<version>
207 s1 = split(s1, s2, ':');
208 // s2 is user, and s1 is version
209 if (s1 == version_) {
214 } while (!contains(tmpt, ';'));
216 } else if (token == "comment") {
217 // we don't need to read any further than this.
221 LYXERR(Debug::LYXVC, "LyXVC::scanMaster(): unexpected token");
227 void RCS::registrer(string const & msg)
229 string cmd = "ci -q -u -i -t-\"";
232 cmd += quoteName(onlyFileName(owner_->absFileName()));
233 doVCCommand(cmd, FileName(owner_->filePath()));
237 bool RCS::renameEnabled()
243 string RCS::rename(support::FileName const & /*newFile*/, string const & /*msg*/)
245 // not implemented, since a left-over file.lyx,v would be confusing.
250 bool RCS::copyEnabled()
256 string RCS::copy(support::FileName const & newFile, string const & msg)
258 // RCS has no real copy command, so we create a poor mans version
259 support::FileName const oldFile(owner_->absFileName());
260 if (!oldFile.copyTo(newFile))
262 FileName path(oldFile.onlyPath());
263 string relFile(to_utf8(newFile.relPath(path.absFileName())));
264 string cmd = "ci -q -u -i -t-\"";
267 cmd += quoteName(relFile);
268 return doVCCommand(cmd, path) ? string() : "RCS: Proceeded";
272 LyXVC::CommandResult RCS::checkIn(string const & msg, string & log)
274 int ret = doVCCommand("ci -q -u -m\"" + msg + "\" "
275 + quoteName(onlyFileName(owner_->absFileName())),
276 FileName(owner_->filePath()));
278 return LyXVC::ErrorCommand;
279 log = "RCS: Proceeded";
280 return LyXVC::VCSuccess;
284 bool RCS::checkInEnabled()
286 return owner_ && !owner_->isReadonly();
290 bool RCS::isCheckInWithConfirmation()
292 // FIXME one day common getDiff for all backends
294 // if (getDiff(file, diff) && diff.empty())
297 TempFile tempfile("lyxvcout");
298 FileName tmpf = tempfile.name();
300 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
304 doVCCommandCall("rcsdiff " + quoteName(owner_->absFileName())
305 + " > " + quoteName(tmpf.toFilesystemEncoding()),
306 FileName(owner_->filePath()));
308 docstring diff = tmpf.fileContents("UTF-8");
317 string RCS::checkOut()
320 int ret = doVCCommand("co -q -l " + quoteName(onlyFileName(owner_->absFileName())),
321 FileName(owner_->filePath()));
322 return ret ? string() : "RCS: Proceeded";
326 bool RCS::checkOutEnabled()
328 return owner_ && owner_->isReadonly();
332 string RCS::repoUpdate()
334 lyxerr << "Sorry, not implemented." << endl;
339 bool RCS::repoUpdateEnabled()
345 string RCS::lockingToggle()
347 //FIXME this might be actually possible, study rcs -U, rcs -L.
348 //State should be easy to get inside scanMaster.
349 //It would fix #4370 and make rcs/svn usage even more closer.
350 lyxerr << "Sorry, not implemented." << endl;
355 bool RCS::lockingToggleEnabled()
363 if (doVCCommand("co -f -u" + version_ + ' '
364 + quoteName(onlyFileName(owner_->absFileName())),
365 FileName(owner_->filePath())))
367 // We ignore changes and just reload!
373 bool RCS::isRevertWithConfirmation()
375 //FIXME owner && diff ?
382 LYXERR(Debug::LYXVC, "LyXVC: undoLast");
383 doVCCommand("rcs -o" + version_ + ' '
384 + quoteName(onlyFileName(owner_->absFileName())),
385 FileName(owner_->filePath()));
389 bool RCS::undoLastEnabled()
395 void RCS::getLog(FileName const & tmpf)
397 doVCCommand("rlog " + quoteName(onlyFileName(owner_->absFileName()))
398 + " > " + quoteName(tmpf.toFilesystemEncoding()),
399 FileName(owner_->filePath()));
403 bool RCS::toggleReadOnlyEnabled()
405 // This got broken somewhere along lfuns dispatch reorganization.
406 // reloadBuffer would be needed after this, but thats problematic
407 // since we are inside Buffer::dispatch.
413 string RCS::revisionInfo(LyXVC::RevisionInfo const info)
415 if (info == LyXVC::File)
417 // fill the rest of the attributes for a single file
418 if (rev_date_cache_.empty())
419 if (!getRevisionInfo())
424 return rev_author_cache_;
426 return rev_date_cache_;
428 return rev_time_cache_;
436 bool RCS::getRevisionInfo()
438 TempFile tempfile("lyxvcout");
439 FileName tmpf = tempfile.name();
441 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
444 doVCCommand("rlog -r " + quoteName(onlyFileName(owner_->absFileName()))
445 + " > " + quoteName(tmpf.toFilesystemEncoding()),
446 FileName(owner_->filePath()));
451 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
454 // we reached to the entry, i.e. after initial log message
456 // line with critical info, e.g:
457 //"date: 2011/07/02 11:02:54; author: sanda; state: Exp; lines: +17 -2"
462 LYXERR(Debug::LYXVC, line);
463 if (entry && prefixIs(line, "date:")) {
467 if (prefixIs(line, "revision"))
473 rev_date_cache_ = token(result, ' ', 1);
474 rev_time_cache_ = rtrim(token(result, ' ', 2), ";");
475 rev_author_cache_ = trim(token(token(result, ';', 1), ':', 1));
477 return !rev_author_cache_.empty();
480 bool RCS::prepareFileRevision(string const &revis, string & f)
483 if (!VCS::makeRCSRevision(version_, rev))
486 TempFile tempfile("lyxvcrev_" + rev + '_');
487 tempfile.setAutoRemove(false);
488 FileName tmpf = tempfile.name();
490 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
494 doVCCommand("co -p" + rev + ' '
495 + quoteName(onlyFileName(owner_->absFileName()))
496 + " > " + quoteName(tmpf.toFilesystemEncoding()),
497 FileName(owner_->filePath()));
499 if (tmpf.isFileEmpty())
502 f = tmpf.absFileName();
507 bool RCS::prepareFileRevisionEnabled()
513 /////////////////////////////////////////////////////////////////////
517 /////////////////////////////////////////////////////////////////////
519 CVS::CVS(FileName const & m, Buffer * b) : VCS(b)
521 // Here we know that the buffer file is either already in CVS or
522 // about to be registered
524 have_rev_info_ = false;
529 FileName const CVS::findFile(FileName const & file)
531 // First we look for the CVS/Entries in the same dir
532 // where we have file.
533 FileName const entries(onlyPath(file.absFileName()) + "/CVS/Entries");
534 string const tmpf = '/' + onlyFileName(file.absFileName()) + '/';
535 LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under cvs in `" << entries
536 << "' for `" << tmpf << '\'');
537 if (entries.isReadableFile()) {
538 // Ok we are at least in a CVS dir. Parse the CVS/Entries
539 // and see if we can find this file. We do a fast and
541 ifstream ifs(entries.toFilesystemEncoding().c_str());
543 while (getline(ifs, line)) {
544 LYXERR(Debug::LYXVC, "\tEntries: " << line);
545 if (contains(line, tmpf))
553 void CVS::scanMaster()
555 LYXERR(Debug::LYXVC, "LyXVC::CVS: scanMaster. \n Checking: " << master_);
556 // Ok now we do the real scan...
557 ifstream ifs(master_.toFilesystemEncoding().c_str());
558 string name = onlyFileName(owner_->absFileName());
559 string tmpf = '/' + name + '/';
560 LYXERR(Debug::LYXVC, "\tlooking for `" << tmpf << '\'');
562 static regex const reg("/(.*)/(.*)/(.*)/(.*)/(.*)");
563 while (getline(ifs, line)) {
564 LYXERR(Debug::LYXVC, "\t line: " << line);
565 if (contains(line, tmpf)) {
566 // Ok extract the fields.
569 // false positive from coverity
570 // coverity[CHECKED_RETURN]
571 regex_match(line, sm, reg);
573 //sm[0]; // whole matched string
575 version_ = sm.str(2);
576 string const file_date = sm.str(3);
579 //sm[5]; // tag or tagdate
580 FileName file(owner_->absFileName());
581 if (file.isReadableFile()) {
582 time_t mod = file.lastModified();
583 string mod_date = rtrim(asctime(gmtime(&mod)), "\n");
584 LYXERR(Debug::LYXVC, "Date in Entries: `" << file_date
585 << "'\nModification date of file: `" << mod_date << '\'');
586 if (file.isReadOnly()) {
587 // readonly checkout is unlocked
590 FileName bdir(addPath(master_.onlyPath().absFileName(),"Base"));
591 FileName base(addName(bdir.absFileName(),name));
592 // if base version is existent "cvs edit" was used to lock
593 vcstatus = base.isReadableFile() ? LOCKED : NOLOCKING;
596 vcstatus = NOLOCKING;
604 bool CVS::retrieve(FileName const & file)
606 LYXERR(Debug::LYXVC, "LyXVC::CVS: retrieve.\n\t" << file);
607 // The caller ensures that file does not exist, so no need to check that.
608 return doVCCommandCall("cvs -q update " + quoteName(file.toFilesystemEncoding()),
609 file.onlyPath()) == 0;
613 string const CVS::getTarget(OperationMode opmode) const
617 // in client server mode CVS does not like full path operand for directory operation
618 // since LyX switches to the repo dir "." is good enough as target
621 return quoteName(onlyFileName(owner_->absFileName()));
627 docstring CVS::toString(CvsStatus status) const
631 return _("Up-to-date");
632 case LocallyModified:
633 return _("Locally Modified");
635 return _("Locally Added");
637 return _("Needs Merge");
639 return _("Needs Checkout");
641 return _("No CVS file");
643 return _("Cannot retrieve CVS status");
649 int CVS::doVCCommandWithOutput(string const & cmd, FileName const & path,
650 FileName const & output, bool reportError)
652 string redirection = output.empty() ? "" : " > " + quoteName(output.toFilesystemEncoding());
653 return doVCCommand(cmd + redirection, path, reportError);
657 int CVS::doVCCommandCallWithOutput(std::string const & cmd,
658 support::FileName const & path,
659 support::FileName const & output)
661 string redirection = output.empty() ? "" : " > " + quoteName(output.toFilesystemEncoding());
662 return doVCCommandCall(cmd + redirection, path);
666 CVS::CvsStatus CVS::getStatus()
668 TempFile tempfile("lyxvout");
669 FileName tmpf = tempfile.name();
671 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
675 if (doVCCommandCallWithOutput("cvs status " + getTarget(File),
676 FileName(owner_->filePath()), tmpf)) {
680 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
681 CvsStatus status = NoCvsFile;
686 LYXERR(Debug::LYXVC, line << '\n');
687 if (prefixIs(line, "File:")) {
688 if (contains(line, "Up-to-date"))
690 else if (contains(line, "Locally Modified"))
691 status = LocallyModified;
692 else if (contains(line, "Locally Added"))
693 status = LocallyAdded;
694 else if (contains(line, "Needs Merge"))
696 else if (contains(line, "Needs Checkout"))
697 status = NeedsCheckout;
703 void CVS::getRevisionInfo()
707 have_rev_info_ = true;
708 TempFile tempfile("lyxvout");
709 FileName tmpf = tempfile.name();
711 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
715 int rc = doVCCommandCallWithOutput("cvs log -r" + version_
716 + ' ' + getTarget(File),
717 FileName(owner_->filePath()), tmpf);
719 LYXERR(Debug::LYXVC, "cvs log failed with exit code " << rc);
723 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
724 static regex const reg("date: (.*) (.*) (.*); author: (.*); state: (.*);(.*)");
729 LYXERR(Debug::LYXVC, line << '\n');
730 if (prefixIs(line, "date:")) {
732 regex_match(line, sm, reg);
733 //sm[0]; // whole matched string
734 rev_date_cache_ = sm[1];
735 rev_time_cache_ = sm[2];
736 //sm[3]; // GMT offset
737 rev_author_cache_ = sm[4];
741 if (rev_author_cache_.empty())
743 "Could not retrieve revision info for " << version_ <<
744 " of " << getTarget(File));
748 void CVS::registrer(string const & msg)
750 doVCCommand("cvs -q add -m \"" + msg + "\" "
752 FileName(owner_->filePath()));
756 bool CVS::renameEnabled()
762 string CVS::rename(support::FileName const & newFile, string const & msg)
764 // CVS has no real rename command, so we create a poor mans version
765 support::FileName const oldFile(owner_->absFileName());
766 string ret = copy(newFile, msg);
769 string cmd = "cvs -q remove -m \"" + msg + "\" " +
770 quoteName(oldFile.onlyFileName());
771 FileName path(oldFile.onlyPath());
772 return doVCCommand(cmd, path) ? string() : ret;
776 bool CVS::copyEnabled()
782 string CVS::copy(support::FileName const & newFile, string const & msg)
784 // CVS has no real copy command, so we create a poor mans version
785 support::FileName const oldFile(owner_->absFileName());
786 if (!oldFile.copyTo(newFile))
788 FileName path(oldFile.onlyPath());
789 string relFile(to_utf8(newFile.relPath(path.absFileName())));
790 string cmd("cvs -q add -m \"" + msg + "\" " + quoteName(relFile));
791 return doVCCommand(cmd, path) ? string() : "CVS: Proceeded";
795 void CVS::getDiff(OperationMode opmode, FileName const & tmpf)
797 doVCCommandWithOutput("cvs diff " + getTarget(opmode),
798 FileName(owner_->filePath()), tmpf, false);
805 return doVCCommand("cvs -q edit " + getTarget(File),
806 FileName(owner_->filePath()));
813 return doVCCommand("cvs -q unedit " + getTarget(File),
814 FileName(owner_->filePath()));
818 int CVS::update(OperationMode opmode, FileName const & tmpf)
820 return doVCCommandWithOutput("cvs -q update "
822 FileName(owner_->filePath()), tmpf, false);
826 string CVS::scanLogFile(FileName const & f, string & status)
828 ifstream ifs(f.toFilesystemEncoding().c_str());
833 LYXERR(Debug::LYXVC, line << '\n');
835 status += line + "; ";
836 if (prefixIs(line, "C ")) {
846 LyXVC::CommandResult CVS::checkIn(string const & msg, string & log)
848 CvsStatus status = getStatus();
851 if (vcstatus != NOLOCKING)
853 return LyXVC::ErrorCommand;
854 log = "CVS: Proceeded";
855 return LyXVC::VCSuccess;
856 case LocallyModified:
858 int rc = doVCCommand("cvs -q commit -m \"" + msg + "\" "
860 FileName(owner_->filePath()));
862 return LyXVC::ErrorCommand;
863 log = "CVS: Proceeded";
864 return LyXVC::VCSuccess;
868 frontend::Alert::error(_("Revision control error."),
869 _("The repository version is newer then the current check out.\n"
870 "You have to update from repository first or revert your changes.")) ;
873 frontend::Alert::error(_("Revision control error."),
874 bformat(_("Bad status when checking in changes.\n"
879 return LyXVC::ErrorBefore;
883 bool CVS::isLocked() const
885 FileName fn(owner_->absFileName());
887 return !fn.isReadOnly();
891 bool CVS::checkInEnabled()
893 if (vcstatus != NOLOCKING)
900 bool CVS::isCheckInWithConfirmation()
902 CvsStatus status = getStatus();
903 return status == LocallyModified || status == LocallyAdded;
907 string CVS::checkOut()
909 if (vcstatus != NOLOCKING && edit())
911 TempFile tempfile("lyxvout");
912 FileName tmpf = tempfile.name();
914 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
918 int rc = update(File, tmpf);
920 string const res = scanLogFile(tmpf, log);
922 frontend::Alert::error(_("Revision control error."),
923 bformat(_("Error when updating from repository.\n"
924 "You have to manually resolve the conflicts NOW!\n'%1$s'.\n\n"
925 "After pressing OK, LyX will try to reopen the resolved document."),
926 from_local8bit(res)));
930 return rc ? string() : log.empty() ? "CVS: Proceeded" : "CVS: " + log;
934 bool CVS::checkOutEnabled()
936 if (vcstatus != NOLOCKING)
943 string CVS::repoUpdate()
945 TempFile tempfile("lyxvout");
946 FileName tmpf = tempfile.name();
948 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
952 getDiff(Directory, tmpf);
953 docstring res = tmpf.fileContents("UTF-8");
955 LYXERR(Debug::LYXVC, "Diff detected:\n" << res);
956 docstring const file = from_utf8(owner_->filePath());
957 docstring text = bformat(_("There were detected changes "
958 "in the working directory:\n%1$s\n\n"
959 "Possible file conflicts must be then resolved manually "
960 "or you will need to revert back to the repository version."), file);
961 int ret = frontend::Alert::prompt(_("Changes detected"),
962 text, 0, 1, _("&Continue"), _("&Abort"), _("View &Log ..."));
964 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + tmpf.absFileName()));
965 ret = frontend::Alert::prompt(_("Changes detected"),
966 text, 0, 1, _("&Continue"), _("&Abort"));
967 hideDialogs("file", 0);
973 int rc = update(Directory, tmpf);
974 res += "Update log:\n" + tmpf.fileContents("UTF-8");
975 LYXERR(Debug::LYXVC, res);
978 string sres = scanLogFile(tmpf, log);
980 docstring const file = owner_->fileName().displayName(20);
981 frontend::Alert::error(_("Revision control error."),
982 bformat(_("Error when updating document %1$s from repository.\n"
983 "You have to manually resolve the conflicts NOW!\n'%2$s'.\n\n"
984 "After pressing OK, LyX will try to reopen the resolved document."),
985 file, from_local8bit(sres)));
989 return rc ? string() : log.empty() ? "CVS: Proceeded" : "CVS: " + log;
993 bool CVS::repoUpdateEnabled()
999 string CVS::lockingToggle()
1001 lyxerr << "Sorry, not implemented." << endl;
1006 bool CVS::lockingToggleEnabled()
1012 bool CVS::isRevertWithConfirmation()
1014 CvsStatus status = getStatus();
1015 return !owner_->isClean() || status == LocallyModified || status == NeedsMerge;
1021 // Reverts to the version in CVS repository and
1022 // gets the updated version from the repository.
1023 CvsStatus status = getStatus();
1026 if (vcstatus != NOLOCKING)
1027 return 0 == unedit();
1031 case LocallyModified: {
1032 FileName f(owner_->absFileName());
1034 update(File, FileName());
1035 owner_->markClean();
1038 case LocallyAdded: {
1039 docstring const file = owner_->fileName().displayName(20);
1040 frontend::Alert::error(_("Revision control error."),
1041 bformat(_("The document %1$s is not in repository.\n"
1042 "You have to check in the first revision before you can revert."),
1047 docstring const file = owner_->fileName().displayName(20);
1048 frontend::Alert::error(_("Revision control error."),
1049 bformat(_("Cannot revert document %1$s to repository version.\n"
1050 "The status '%2$s' is unexpected."),
1051 file, toString(status)));
1059 void CVS::undoLast()
1061 // merge the current with the previous version
1062 // in a reverse patch kind of way, so that the
1063 // result is to revert the last changes.
1064 lyxerr << "Sorry, not implemented." << endl;
1068 bool CVS::undoLastEnabled()
1074 void CVS::getLog(FileName const & tmpf)
1076 doVCCommandWithOutput("cvs log " + getTarget(File),
1077 FileName(owner_->filePath()),
1082 bool CVS::toggleReadOnlyEnabled()
1088 string CVS::revisionInfo(LyXVC::RevisionInfo const info)
1090 if (!version_.empty()) {
1096 return rev_author_cache_;
1098 return rev_date_cache_;
1100 return rev_time_cache_;
1108 bool CVS::prepareFileRevision(string const & revis, string & f)
1111 if (!VCS::makeRCSRevision(version_, rev))
1114 TempFile tempfile("lyxvcrev_" + rev + '_');
1115 tempfile.setAutoRemove(false);
1116 FileName tmpf = tempfile.name();
1118 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1122 doVCCommandWithOutput("cvs update -p -r" + rev + ' '
1124 FileName(owner_->filePath()), tmpf);
1126 if (tmpf.isFileEmpty())
1129 f = tmpf.absFileName();
1134 bool CVS::prepareFileRevisionEnabled()
1140 /////////////////////////////////////////////////////////////////////
1144 /////////////////////////////////////////////////////////////////////
1146 SVN::SVN(FileName const & m, Buffer * b) : VCS(b)
1148 // Here we know that the buffer file is either already in SVN or
1149 // about to be registered
1156 FileName const SVN::findFile(FileName const & file)
1158 // First we check the existence of repository meta data.
1159 if (!VCS::checkparentdirs(file, ".svn")) {
1160 LYXERR(Debug::LYXVC, "Cannot find SVN meta data for " << file);
1164 // Now we check the status of the file.
1165 TempFile tempfile("lyxvcout");
1166 FileName tmpf = tempfile.name();
1168 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1172 string const fname = onlyFileName(file.absFileName());
1173 LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under svn control for `" << fname << '\'');
1174 bool found = 0 == doVCCommandCall("svn info " + quoteName(fname)
1175 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1177 LYXERR(Debug::LYXVC, "SVN control: " << (found ? "enabled" : "disabled"));
1178 return found ? file : FileName();
1182 void SVN::scanMaster()
1184 // vcstatus code is somewhat superflous,
1185 // until we want to implement read-only toggle for svn.
1186 vcstatus = NOLOCKING;
1187 if (checkLockMode()) {
1191 vcstatus = UNLOCKED;
1196 bool SVN::checkLockMode()
1198 TempFile tempfile("lyxvcout");
1199 FileName tmpf = tempfile.name();
1201 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1205 LYXERR(Debug::LYXVC, "Detecting locking mode...");
1206 if (doVCCommandCall("svn proplist " + quoteName(onlyFileName(owner_->absFileName()))
1207 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1208 FileName(owner_->filePath())))
1211 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1215 while (ifs && !ret) {
1217 LYXERR(Debug::LYXVC, line);
1218 if (contains(line, "svn:needs-lock"))
1221 LYXERR(Debug::LYXVC, "Locking enabled: " << ret);
1229 bool SVN::isLocked() const
1231 FileName file(owner_->absFileName());
1233 return !file.isReadOnly();
1237 bool SVN::retrieve(FileName const & file)
1239 LYXERR(Debug::LYXVC, "LyXVC::SVN: retrieve.\n\t" << file);
1240 // The caller ensures that file does not exist, so no need to check that.
1241 return doVCCommandCall("svn update -q --non-interactive " + quoteName(file.onlyFileName()),
1242 file.onlyPath()) == 0;
1246 void SVN::registrer(string const & /*msg*/)
1248 doVCCommand("svn add -q " + quoteName(onlyFileName(owner_->absFileName())),
1249 FileName(owner_->filePath()));
1253 bool SVN::renameEnabled()
1259 string SVN::rename(support::FileName const & newFile, string const & msg)
1261 // svn move does not require a log message, since it does not commit.
1262 // In LyX we commit immediately afterwards, otherwise it could be
1263 // confusing to the user to have two uncommitted files.
1264 FileName path(owner_->filePath());
1265 string relFile(to_utf8(newFile.relPath(path.absFileName())));
1266 string cmd("svn move -q " + quoteName(onlyFileName(owner_->absFileName())) +
1267 ' ' + quoteName(relFile));
1268 if (doVCCommand(cmd, path)) {
1269 cmd = "svn revert -q " +
1270 quoteName(onlyFileName(owner_->absFileName())) + ' ' +
1272 doVCCommand(cmd, path);
1273 if (newFile.exists())
1274 newFile.removeFile();
1277 vector<support::FileName> f;
1278 f.push_back(owner_->fileName());
1279 f.push_back(newFile);
1281 if (checkIn(f, msg, log) != LyXVC::VCSuccess) {
1282 cmd = "svn revert -q " +
1283 quoteName(onlyFileName(owner_->absFileName())) + ' ' +
1285 doVCCommand(cmd, path);
1286 if (newFile.exists())
1287 newFile.removeFile();
1294 bool SVN::copyEnabled()
1300 string SVN::copy(support::FileName const & newFile, string const & msg)
1302 // svn copy does not require a log message, since it does not commit.
1303 // In LyX we commit immediately afterwards, otherwise it could be
1304 // confusing to the user to have an uncommitted file.
1305 FileName path(owner_->filePath());
1306 string relFile(to_utf8(newFile.relPath(path.absFileName())));
1307 string cmd("svn copy -q " + quoteName(onlyFileName(owner_->absFileName())) +
1308 ' ' + quoteName(relFile));
1309 if (doVCCommand(cmd, path))
1311 vector<support::FileName> f(1, newFile);
1313 if (checkIn(f, msg, log) == LyXVC::VCSuccess)
1319 LyXVC::CommandResult SVN::checkIn(string const & msg, string & log)
1321 vector<support::FileName> f(1, owner_->fileName());
1322 return checkIn(f, msg, log);
1326 LyXVC::CommandResult
1327 SVN::checkIn(vector<support::FileName> const & f, string const & msg, string & log)
1329 TempFile tempfile("lyxvcout");
1330 FileName tmpf = tempfile.name();
1332 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1333 log = N_("Error: Could not generate logfile.");
1334 return LyXVC::ErrorBefore;
1338 os << "svn commit -m \"" << msg << '"';
1339 for (size_t i = 0; i < f.size(); ++i)
1340 os << ' ' << quoteName(f[i].onlyFileName());
1341 os << " > " << quoteName(tmpf.toFilesystemEncoding());
1342 LyXVC::CommandResult ret =
1343 doVCCommand(os.str(), FileName(owner_->filePath())) ?
1344 LyXVC::ErrorCommand : LyXVC::VCSuccess;
1346 string res = scanLogFile(tmpf, log);
1348 frontend::Alert::error(_("Revision control error."),
1349 _("Error when committing to repository.\n"
1350 "You have to manually resolve the problem.\n"
1351 "LyX will reopen the document after you press OK."));
1352 ret = LyXVC::ErrorCommand;
1355 if (!fileLock(false, tmpf, log))
1356 ret = LyXVC::ErrorCommand;
1359 log.insert(0, "SVN: ");
1360 if (ret == LyXVC::VCSuccess && log.empty())
1361 log = "SVN: Proceeded";
1366 bool SVN::checkInEnabled()
1375 bool SVN::isCheckInWithConfirmation()
1377 // FIXME one day common getDiff and perhaps OpMode for all backends
1379 TempFile tempfile("lyxvcout");
1380 FileName tmpf = tempfile.name();
1382 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1386 doVCCommandCall("svn diff " + quoteName(owner_->absFileName())
1387 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1388 FileName(owner_->filePath()));
1390 docstring diff = tmpf.fileContents("UTF-8");
1399 // FIXME Correctly return code should be checked instead of this.
1400 // This would need another solution than just plain startscript.
1401 // Hint from Andre': QProcess::readAllStandardError()...
1402 string SVN::scanLogFile(FileName const & f, string & status)
1404 ifstream ifs(f.toFilesystemEncoding().c_str());
1409 LYXERR(Debug::LYXVC, line << '\n');
1411 status += line + "; ";
1412 if (prefixIs(line, "C ") || prefixIs(line, "CU ")
1413 || contains(line, "Commit failed")) {
1417 if (contains(line, "svn:needs-lock")) {
1427 bool SVN::fileLock(bool lock, FileName const & tmpf, string &status)
1429 if (!locked_mode_ || (isLocked() == lock))
1432 string const arg = lock ? "lock " : "unlock ";
1433 doVCCommand("svn "+ arg + quoteName(onlyFileName(owner_->absFileName()))
1434 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1435 FileName(owner_->filePath()));
1437 // Lock error messages go unfortunately on stderr and are unreachible this way.
1438 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1442 if (!line.empty()) status += line + "; ";
1446 if (isLocked() == lock)
1450 frontend::Alert::error(_("Revision control error."),
1451 _("Error while acquiring write lock.\n"
1452 "Another user is most probably editing\n"
1453 "the current document now!\n"
1454 "Also check the access to the repository."));
1456 frontend::Alert::error(_("Revision control error."),
1457 _("Error while releasing write lock.\n"
1458 "Check the access to the repository."));
1463 string SVN::checkOut()
1465 TempFile tempfile("lyxvcout");
1466 FileName tmpf = tempfile.name();
1468 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1469 return N_("Error: Could not generate logfile.");
1472 doVCCommand("svn update --non-interactive " + quoteName(onlyFileName(owner_->absFileName()))
1473 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1474 FileName(owner_->filePath()));
1477 string const res = scanLogFile(tmpf, log);
1479 frontend::Alert::error(_("Revision control error."),
1480 bformat(_("Error when updating from repository.\n"
1481 "You have to manually resolve the conflicts NOW!\n'%1$s'.\n\n"
1482 "After pressing OK, LyX will try to reopen the resolved document."),
1483 from_local8bit(res)));
1485 fileLock(true, tmpf, log);
1487 return log.empty() ? string() : "SVN: " + log;
1491 bool SVN::checkOutEnabled()
1500 string SVN::repoUpdate()
1502 TempFile tempfile("lyxvcout");
1503 FileName tmpf = tempfile.name();
1505 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1506 return N_("Error: Could not generate logfile.");
1509 doVCCommand("svn diff " + quoteName(owner_->filePath())
1510 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1511 FileName(owner_->filePath()));
1512 docstring res = tmpf.fileContents("UTF-8");
1514 LYXERR(Debug::LYXVC, "Diff detected:\n" << res);
1515 docstring const file = from_utf8(owner_->filePath());
1516 docstring text = bformat(_("There were detected changes "
1517 "in the working directory:\n%1$s\n\n"
1518 "In case of file conflict version of the local directory files "
1519 "will be preferred."
1520 "\n\nContinue?"), file);
1521 int ret = frontend::Alert::prompt(_("Changes detected"),
1522 text, 0, 1, _("&Yes"), _("&No"), _("View &Log ..."));
1524 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + tmpf.absFileName()));
1525 ret = frontend::Alert::prompt(_("Changes detected"),
1526 text, 0, 1, _("&Yes"), _("&No"));
1527 hideDialogs("file", 0);
1533 // Reverting looks too harsh, see bug #6255.
1534 // doVCCommand("svn revert -R " + quoteName(owner_->filePath())
1535 // + " > " + quoteName(tmpf.toFilesystemEncoding()),
1536 // FileName(owner_->filePath()));
1537 // res = "Revert log:\n" + tmpf.fileContents("UTF-8");
1538 doVCCommand("svn update --accept mine-full " + quoteName(owner_->filePath())
1539 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1540 FileName(owner_->filePath()));
1541 res += "Update log:\n" + tmpf.fileContents("UTF-8");
1543 LYXERR(Debug::LYXVC, res);
1544 return to_utf8(res);
1548 bool SVN::repoUpdateEnabled()
1554 string SVN::lockingToggle()
1556 TempFile tempfile("lyxvcout");
1557 FileName tmpf = tempfile.name();
1559 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1560 return N_("Error: Could not generate logfile.");
1563 int ret = doVCCommand("svn proplist " + quoteName(onlyFileName(owner_->absFileName()))
1564 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1565 FileName(owner_->filePath()));
1570 string res = scanLogFile(tmpf, log);
1571 bool locking = contains(res, "svn:needs-lock");
1573 ret = doVCCommand("svn propset svn:needs-lock ON "
1574 + quoteName(onlyFileName(owner_->absFileName()))
1575 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1576 FileName(owner_->filePath()));
1578 ret = doVCCommand("svn propdel svn:needs-lock "
1579 + quoteName(onlyFileName(owner_->absFileName()))
1580 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1581 FileName(owner_->filePath()));
1585 frontend::Alert::warning(_("SVN File Locking"),
1586 (locking ? _("Locking property unset.") : _("Locking property set.")) + '\n'
1587 + _("Do not forget to commit the locking property into the repository."),
1590 return string("SVN: ") + (locking ?
1591 N_("Locking property unset.") : N_("Locking property set."));
1595 bool SVN::lockingToggleEnabled()
1603 // Reverts to the version in SVN repository and
1604 // gets the updated version from the repository.
1605 string const fil = quoteName(onlyFileName(owner_->absFileName()));
1607 if (doVCCommand("svn revert -q " + fil,
1608 FileName(owner_->filePath())))
1610 owner_->markClean();
1615 bool SVN::isRevertWithConfirmation()
1617 //FIXME owner && diff
1622 void SVN::undoLast()
1624 // merge the current with the previous version
1625 // in a reverse patch kind of way, so that the
1626 // result is to revert the last changes.
1627 lyxerr << "Sorry, not implemented." << endl;
1631 bool SVN::undoLastEnabled()
1637 string SVN::revisionInfo(LyXVC::RevisionInfo const info)
1639 if (info == LyXVC::Tree) {
1640 if (rev_tree_cache_.empty())
1641 if (!getTreeRevisionInfo())
1642 rev_tree_cache_ = "?";
1643 if (rev_tree_cache_ == "?")
1646 return rev_tree_cache_;
1649 // fill the rest of the attributes for a single file
1650 if (rev_file_cache_.empty())
1651 if (!getFileRevisionInfo())
1652 rev_file_cache_ = "?";
1656 if (rev_file_cache_ == "?")
1658 return rev_file_cache_;
1660 return rev_author_cache_;
1662 return rev_date_cache_;
1664 return rev_time_cache_;
1673 bool SVN::getFileRevisionInfo()
1675 TempFile tempfile("lyxvcout");
1676 FileName tmpf = tempfile.name();
1678 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1682 doVCCommand("svn info --xml " + quoteName(onlyFileName(owner_->absFileName()))
1683 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1684 FileName(owner_->filePath()));
1689 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1697 LYXERR(Debug::LYXVC, line);
1698 if (prefixIs(line, "<commit"))
1700 if (c && prefixIs(line, " revision=\"") && suffixIs(line, "\">")) {
1701 string l1 = subst(line, "revision=\"", "");
1702 string l2 = trim(subst(l1, "\">", ""));
1704 rev_file_cache_ = rev = l2;
1706 if (c && prefixIs(line, "<author>") && suffixIs(line, "</author>")) {
1707 string l1 = subst(line, "<author>", "");
1708 string l2 = subst(l1, "</author>", "");
1709 rev_author_cache_ = l2;
1711 if (c && prefixIs(line, "<date>") && suffixIs(line, "</date>")) {
1712 string l1 = subst(line, "<date>", "");
1713 string l2 = subst(l1, "</date>", "");
1714 l2 = split(l2, l1, 'T');
1715 rev_date_cache_ = l1;
1716 l2 = split(l2, l1, '.');
1717 rev_time_cache_ = l1;
1722 return !rev.empty();
1726 bool SVN::getTreeRevisionInfo()
1728 TempFile tempfile("lyxvcout");
1729 FileName tmpf = tempfile.name();
1731 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1735 doVCCommand("svnversion -n . > " + quoteName(tmpf.toFilesystemEncoding()),
1736 FileName(owner_->filePath()));
1741 // only first line in case something bad happens.
1742 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1747 rev_tree_cache_ = line;
1748 return !line.empty();
1752 void SVN::getLog(FileName const & tmpf)
1754 doVCCommand("svn log " + quoteName(onlyFileName(owner_->absFileName()))
1755 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1756 FileName(owner_->filePath()));
1760 bool SVN::prepareFileRevision(string const & revis, string & f)
1762 if (!isStrInt(revis))
1765 int rev = convert<int>(revis);
1767 if (!getFileRevisionInfo())
1770 rev = convert<int>(rev_file_cache_);
1771 // go back for minus rev
1773 rev = rev + convert<int>(rev_file_cache_);
1778 string revname = convert<string>(rev);
1779 TempFile tempfile("lyxvcrev_" + revname + '_');
1780 tempfile.setAutoRemove(false);
1781 FileName tmpf = tempfile.name();
1783 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1787 doVCCommand("svn cat -r " + revname + ' '
1788 + quoteName(onlyFileName(owner_->absFileName()))
1789 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1790 FileName(owner_->filePath()));
1792 if (tmpf.isFileEmpty())
1795 f = tmpf.absFileName();
1800 bool SVN::prepareFileRevisionEnabled()
1807 bool SVN::toggleReadOnlyEnabled()
1813 /////////////////////////////////////////////////////////////////////
1817 /////////////////////////////////////////////////////////////////////
1819 GIT::GIT(FileName const & m, Buffer * b) : VCS(b)
1821 // Here we know that the buffer file is either already in GIT or
1822 // about to be registered
1828 FileName const GIT::findFile(FileName const & file)
1830 // First we check the existence of repository meta data.
1831 if (!VCS::checkparentdirs(file, ".git")) {
1832 LYXERR(Debug::LYXVC, "Cannot find GIT meta data for " << file);
1836 // Now we check the status of the file.
1837 TempFile tempfile("lyxvcout");
1838 FileName tmpf = tempfile.name();
1840 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1844 string const fname = onlyFileName(file.absFileName());
1845 LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under git control for `"
1847 doVCCommandCall("git ls-files " +
1848 quoteName(fname) + " > " +
1849 quoteName(tmpf.toFilesystemEncoding()),
1852 bool found = !tmpf.isFileEmpty();
1853 LYXERR(Debug::LYXVC, "GIT control: " << (found ? "enabled" : "disabled"));
1854 return found ? file : FileName();
1858 void GIT::scanMaster()
1860 // vcstatus code is somewhat superflous,
1861 // until we want to implement read-only toggle for git.
1862 vcstatus = NOLOCKING;
1866 bool GIT::retrieve(FileName const & file)
1868 LYXERR(Debug::LYXVC, "LyXVC::GIT: retrieve.\n\t" << file);
1869 // The caller ensures that file does not exist, so no need to check that.
1870 return doVCCommandCall("git checkout -q " + quoteName(file.onlyFileName()),
1871 file.onlyPath()) == 0;
1875 void GIT::registrer(string const & /*msg*/)
1877 doVCCommand("git add " + quoteName(onlyFileName(owner_->absFileName())),
1878 FileName(owner_->filePath()));
1882 bool GIT::renameEnabled()
1888 string GIT::rename(support::FileName const & newFile, string const & msg)
1890 // git mv does not require a log message, since it does not commit.
1891 // In LyX we commit immediately afterwards, otherwise it could be
1892 // confusing to the user to have two uncommitted files.
1893 FileName path(owner_->filePath());
1894 string relFile(to_utf8(newFile.relPath(path.absFileName())));
1895 string cmd("git mv " + quoteName(onlyFileName(owner_->absFileName())) +
1896 ' ' + quoteName(relFile));
1897 if (doVCCommand(cmd, path)) {
1898 cmd = "git checkout -q " +
1899 quoteName(onlyFileName(owner_->absFileName())) + ' ' +
1901 doVCCommand(cmd, path);
1902 if (newFile.exists())
1903 newFile.removeFile();
1906 vector<support::FileName> f;
1907 f.push_back(owner_->fileName());
1908 f.push_back(newFile);
1910 if (checkIn(f, msg, log) != LyXVC::VCSuccess) {
1911 cmd = "git checkout -q " +
1912 quoteName(onlyFileName(owner_->absFileName())) + ' ' +
1914 doVCCommand(cmd, path);
1915 if (newFile.exists())
1916 newFile.removeFile();
1923 bool GIT::copyEnabled()
1929 string GIT::copy(support::FileName const & /*newFile*/, string const & /*msg*/)
1931 // git does not support copy with history preservation
1936 LyXVC::CommandResult GIT::checkIn(string const & msg, string & log)
1938 vector<support::FileName> f(1, owner_->fileName());
1939 return checkIn(f, msg, log);
1943 LyXVC::CommandResult
1944 GIT::checkIn(vector<support::FileName> const & f, string const & msg, string & log)
1946 TempFile tempfile("lyxvcout");
1947 FileName tmpf = tempfile.name();
1949 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1950 log = N_("Error: Could not generate logfile.");
1951 return LyXVC::ErrorBefore;
1955 os << "git commit -m \"" << msg << '"';
1956 for (size_t i = 0; i < f.size(); ++i)
1957 os << ' ' << quoteName(f[i].onlyFileName());
1958 os << " > " << quoteName(tmpf.toFilesystemEncoding());
1959 LyXVC::CommandResult ret =
1960 doVCCommand(os.str(), FileName(owner_->filePath())) ?
1961 LyXVC::ErrorCommand : LyXVC::VCSuccess;
1963 string res = scanLogFile(tmpf, log);
1965 frontend::Alert::error(_("Revision control error."),
1966 _("Error when committing to repository.\n"
1967 "You have to manually resolve the problem.\n"
1968 "LyX will reopen the document after you press OK."));
1969 ret = LyXVC::ErrorCommand;
1973 log.insert(0, "GIT: ");
1974 if (ret == LyXVC::VCSuccess && log.empty())
1975 log = "GIT: Proceeded";
1980 bool GIT::checkInEnabled()
1986 bool GIT::isCheckInWithConfirmation()
1988 // FIXME one day common getDiff and perhaps OpMode for all backends
1990 TempFile tempfile("lyxvcout");
1991 FileName tmpf = tempfile.name();
1993 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1997 doVCCommandCall("git diff " + quoteName(owner_->absFileName())
1998 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1999 FileName(owner_->filePath()));
2001 docstring diff = tmpf.fileContents("UTF-8");
2010 // FIXME Correctly return code should be checked instead of this.
2011 // This would need another solution than just plain startscript.
2012 // Hint from Andre': QProcess::readAllStandardError()...
2013 string GIT::scanLogFile(FileName const & f, string & status)
2015 ifstream ifs(f.toFilesystemEncoding().c_str());
2020 LYXERR(Debug::LYXVC, line << "\n");
2022 status += line + "; ";
2023 if (prefixIs(line, "C ") || prefixIs(line, "CU ")
2024 || contains(line, "Commit failed")) {
2034 string GIT::checkOut()
2040 bool GIT::checkOutEnabled()
2046 string GIT::repoUpdate()
2052 bool GIT::repoUpdateEnabled()
2058 string GIT::lockingToggle()
2064 bool GIT::lockingToggleEnabled()
2072 // Reverts to the version in GIT repository and
2073 // gets the updated version from the repository.
2074 string const fil = quoteName(onlyFileName(owner_->absFileName()));
2076 if (doVCCommand("git checkout -q " + fil,
2077 FileName(owner_->filePath())))
2079 owner_->markClean();
2084 bool GIT::isRevertWithConfirmation()
2086 //FIXME owner && diff
2091 void GIT::undoLast()
2093 // merge the current with the previous version
2094 // in a reverse patch kind of way, so that the
2095 // result is to revert the last changes.
2096 lyxerr << "Sorry, not implemented." << endl;
2100 bool GIT::undoLastEnabled()
2106 string GIT::revisionInfo(LyXVC::RevisionInfo const info)
2108 if (info == LyXVC::Tree) {
2109 if (rev_tree_cache_.empty())
2110 if (!getTreeRevisionInfo())
2111 rev_tree_cache_ = "?";
2112 if (rev_tree_cache_ == "?")
2115 return rev_tree_cache_;
2118 // fill the rest of the attributes for a single file
2119 if (rev_file_cache_.empty())
2120 if (!getFileRevisionInfo())
2121 rev_file_cache_ = "?";
2125 if (rev_file_cache_ == "?")
2127 return rev_file_cache_;
2129 return rev_author_cache_;
2131 return rev_date_cache_;
2133 return rev_time_cache_;
2142 bool GIT::getFileRevisionInfo()
2144 TempFile tempfile("lyxvcout");
2145 FileName tmpf = tempfile.name();
2147 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
2151 doVCCommand("git log -n 1 --pretty=format:%H%n%an%n%ai " + quoteName(onlyFileName(owner_->absFileName()))
2152 + " > " + quoteName(tmpf.toFilesystemEncoding()),
2153 FileName(owner_->filePath()));
2158 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
2161 getline(ifs, rev_file_cache_);
2163 getline(ifs, rev_author_cache_);
2167 rev_time_cache_ = split(line, rev_date_cache_, ' ');
2171 return !rev_file_cache_.empty();
2175 bool GIT::getTreeRevisionInfo()
2177 TempFile tempfile("lyxvcout");
2178 FileName tmpf = tempfile.name();
2180 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
2184 doVCCommand("git describe --abbrev --dirty --long > " + quoteName(tmpf.toFilesystemEncoding()),
2185 FileName(owner_->filePath()));
2190 // only first line in case something bad happens.
2191 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
2192 getline(ifs, rev_tree_cache_);
2195 return !rev_tree_cache_.empty();
2199 void GIT::getLog(FileName const & tmpf)
2201 doVCCommand("git log " + quoteName(onlyFileName(owner_->absFileName()))
2202 + " > " + quoteName(tmpf.toFilesystemEncoding()),
2203 FileName(owner_->filePath()));
2207 //at this moment we don't accept revision SHA, but just number of revision steps back
2208 //GUI and infrastucture needs to be changed first
2209 bool GIT::prepareFileRevision(string const & revis, string & f)
2211 // anything positive means we got hash, not "0" or minus revision
2214 // hash is rarely number and should be long
2215 if (isStrInt(revis) && revis.length()<20)
2216 rev = convert<int>(revis);
2218 // revision and filename
2221 // go back for "minus" revisions
2223 pointer = "HEAD~" + convert<string>(-rev);
2230 TempFile tempfile("lyxvcrev_" + revis + '_');
2231 tempfile.setAutoRemove(false);
2232 FileName tmpf = tempfile.name();
2234 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
2238 doVCCommand("git show " + pointer + "./"
2239 + quoteName(onlyFileName(owner_->absFileName()))
2240 + " > " + quoteName(tmpf.toFilesystemEncoding()),
2241 FileName(owner_->filePath()));
2243 if (tmpf.isFileEmpty())
2246 f = tmpf.absFileName();
2251 bool GIT::prepareFileRevisionEnabled()
2257 bool GIT::toggleReadOnlyEnabled()