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"
37 using namespace lyx::support;
43 int VCS::doVCCommandCall(string const & cmd, FileName const & path)
45 LYXERR(Debug::LYXVC, "doVCCommandCall: " << cmd);
47 support::PathChanger p(path);
48 return one.startscript(Systemcall::Wait, cmd, string(), string(), false);
52 int VCS::doVCCommand(string const & cmd, FileName const & path, bool reportError)
55 owner_->setBusy(true);
57 int const ret = doVCCommandCall(cmd, path);
60 owner_->setBusy(false);
61 if (ret && reportError)
62 frontend::Alert::error(_("Revision control error."),
63 bformat(_("Some problem occurred while running the command:\n"
70 bool VCS::makeRCSRevision(string const &version, string &revis) const
75 int back = convert<int>(rev);
76 // if positive use as the last number in the whole revision string
79 rsplit(version, base , '.');
80 rev = base + '.' + rev;
84 // we care about the last number from revision string
85 // in case of backward indexing
88 cur = rsplit(version, base , '.');
91 int want = convert<int>(cur) + back;
95 rev = base + '.' + convert<string>(want);
104 bool VCS::checkparentdirs(FileName const & file, std::string const & vcsdir)
106 FileName dirname = file.onlyPath();
108 FileName tocheck = FileName(addName(dirname.absFileName(), vcsdir));
109 LYXERR(Debug::LYXVC, "check file: " << tocheck.absFileName());
110 if (tocheck.exists())
112 //this construct because of #8295
113 dirname = FileName(dirname.absFileName()).parentPath();
114 } while (!dirname.empty());
119 /////////////////////////////////////////////////////////////////////
123 /////////////////////////////////////////////////////////////////////
125 RCS::RCS(FileName const & m, Buffer * b) : VCS(b)
127 // Here we know that the buffer file is either already in RCS or
128 // about to be registered
134 FileName const RCS::findFile(FileName const & file)
136 // Check if *,v exists.
137 FileName tmp(file.absFileName() + ",v");
138 LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under rcs: " << tmp);
139 if (tmp.isReadableFile()) {
140 LYXERR(Debug::LYXVC, "Yes, " << file << " is under rcs.");
144 // Check if RCS/*,v exists.
145 tmp = FileName(addName(addPath(onlyPath(file.absFileName()), "RCS"), file.absFileName()) + ",v");
146 LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under rcs: " << tmp);
147 if (tmp.isReadableFile()) {
148 LYXERR(Debug::LYXVC, "Yes, " << file << " is under rcs.");
156 bool RCS::retrieve(FileName const & file)
158 LYXERR(Debug::LYXVC, "LyXVC::RCS: retrieve.\n\t" << file);
159 // The caller ensures that file does not exist, so no need to check that.
160 return doVCCommandCall("co -q -r " + quoteName(file.toFilesystemEncoding()),
165 void RCS::scanMaster()
170 LYXERR(Debug::LYXVC, "LyXVC::RCS: scanMaster: " << master_);
172 ifstream ifs(master_.toFilesystemEncoding().c_str());
175 bool read_enough = false;
177 while (!read_enough && ifs >> token) {
178 LYXERR(Debug::LYXVC, "LyXVC::scanMaster: current lex text: `"
183 else if (token == "head") {
187 tmv = rtrim(tmv, ";");
189 LYXERR(Debug::LYXVC, "LyXVC: version found to be " << tmv);
190 } else if (contains(token, "access")
191 || contains(token, "symbols")
192 || contains(token, "strict")) {
194 } else if (contains(token, "locks")) {
196 if (contains(token, ';')) {
197 locker_ = "Unlocked";
206 s1 = rtrim(tmpt, ";");
207 // tmp is now in the format <user>:<version>
208 s1 = split(s1, s2, ':');
209 // s2 is user, and s1 is version
210 if (s1 == version_) {
215 } while (!contains(tmpt, ';'));
217 } else if (token == "comment") {
218 // we don't need to read any further than this.
222 LYXERR(Debug::LYXVC, "LyXVC::scanMaster(): unexpected token");
228 void RCS::registrer(string const & msg)
230 string cmd = "ci -q -u -i -t-\"";
233 cmd += quoteName(onlyFileName(owner_->absFileName()));
234 doVCCommand(cmd, FileName(owner_->filePath()));
238 bool RCS::renameEnabled()
244 string RCS::rename(support::FileName const & /*newFile*/, string const & /*msg*/)
246 // not implemented, since a left-over file.lyx,v would be confusing.
251 bool RCS::copyEnabled()
257 string RCS::copy(support::FileName const & newFile, string const & msg)
259 // RCS has no real copy command, so we create a poor mans version
260 support::FileName const oldFile(owner_->absFileName());
261 if (!oldFile.copyTo(newFile))
263 FileName path(oldFile.onlyPath());
264 string relFile(to_utf8(newFile.relPath(path.absFileName())));
265 string cmd = "ci -q -u -i -t-\"";
268 cmd += quoteName(relFile);
269 return doVCCommand(cmd, path) ? string() : "RCS: Proceeded";
273 LyXVC::CommandResult RCS::checkIn(string const & msg, string & log)
275 int ret = doVCCommand("ci -q -u -m\"" + msg + "\" "
276 + quoteName(onlyFileName(owner_->absFileName())),
277 FileName(owner_->filePath()));
279 return LyXVC::ErrorCommand;
280 log = "RCS: Proceeded";
281 return LyXVC::VCSuccess;
285 bool RCS::checkInEnabled()
287 return owner_ && !owner_->hasReadonlyFlag();
291 bool RCS::isCheckInWithConfirmation()
293 // FIXME one day common getDiff for all backends
295 // if (getDiff(file, diff) && diff.empty())
298 TempFile tempfile("lyxvcout");
299 FileName tmpf = tempfile.name();
301 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
305 doVCCommandCall("rcsdiff " + quoteName(owner_->absFileName())
306 + " > " + quoteName(tmpf.toFilesystemEncoding()),
307 FileName(owner_->filePath()));
309 docstring diff = tmpf.fileContents("UTF-8");
318 string RCS::checkOut()
321 int ret = doVCCommand("co -q -l " + quoteName(onlyFileName(owner_->absFileName())),
322 FileName(owner_->filePath()));
323 return ret ? string() : "RCS: Proceeded";
327 bool RCS::checkOutEnabled()
329 return owner_ && owner_->hasReadonlyFlag();
333 string RCS::repoUpdate()
335 lyxerr << "Sorry, not implemented." << endl;
340 bool RCS::repoUpdateEnabled()
346 string RCS::lockingToggle()
348 //FIXME this might be actually possible, study rcs -U, rcs -L.
349 //State should be easy to get inside scanMaster.
350 //It would fix #4370 and make rcs/svn usage even more closer.
351 lyxerr << "Sorry, not implemented." << endl;
356 bool RCS::lockingToggleEnabled()
364 if (doVCCommand("co -f -u" + version_ + ' '
365 + quoteName(onlyFileName(owner_->absFileName())),
366 FileName(owner_->filePath())))
368 // We ignore changes and just reload!
374 bool RCS::isRevertWithConfirmation()
376 //FIXME owner && diff ?
383 LYXERR(Debug::LYXVC, "LyXVC: undoLast");
384 doVCCommand("rcs -o" + version_ + ' '
385 + quoteName(onlyFileName(owner_->absFileName())),
386 FileName(owner_->filePath()));
390 bool RCS::undoLastEnabled()
396 void RCS::getLog(FileName const & tmpf)
398 doVCCommand("rlog " + quoteName(onlyFileName(owner_->absFileName()))
399 + " > " + quoteName(tmpf.toFilesystemEncoding()),
400 FileName(owner_->filePath()));
404 bool RCS::toggleReadOnlyEnabled()
406 // This got broken somewhere along lfuns dispatch reorganization.
407 // reloadBuffer would be needed after this, but thats problematic
408 // since we are inside Buffer::dispatch.
414 string RCS::revisionInfo(LyXVC::RevisionInfo const info)
416 if (info == LyXVC::File)
418 // fill the rest of the attributes for a single file
419 if (rev_date_cache_.empty())
420 if (!getRevisionInfo())
425 return rev_author_cache_;
427 return rev_date_cache_;
429 return rev_time_cache_;
437 bool RCS::getRevisionInfo()
439 TempFile tempfile("lyxvcout");
440 FileName tmpf = tempfile.name();
442 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
445 doVCCommand("rlog -r " + quoteName(onlyFileName(owner_->absFileName()))
446 + " > " + quoteName(tmpf.toFilesystemEncoding()),
447 FileName(owner_->filePath()));
452 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
455 // we reached to the entry, i.e. after initial log message
457 // line with critical info, e.g:
458 //"date: 2011/07/02 11:02:54; author: sanda; state: Exp; lines: +17 -2"
463 LYXERR(Debug::LYXVC, line);
464 if (entry && prefixIs(line, "date:")) {
468 if (prefixIs(line, "revision"))
474 rev_date_cache_ = token(result, ' ', 1);
475 rev_time_cache_ = rtrim(token(result, ' ', 2), ";");
476 rev_author_cache_ = trim(token(token(result, ';', 1), ':', 1));
478 return !rev_author_cache_.empty();
481 bool RCS::prepareFileRevision(string const &revis, string & f)
484 if (!VCS::makeRCSRevision(version_, rev))
487 TempFile tempfile("lyxvcrev_" + rev + '_');
488 tempfile.setAutoRemove(false);
489 FileName tmpf = tempfile.name();
491 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
495 doVCCommand("co -p" + rev + ' '
496 + quoteName(onlyFileName(owner_->absFileName()))
497 + " > " + quoteName(tmpf.toFilesystemEncoding()),
498 FileName(owner_->filePath()));
500 if (tmpf.isFileEmpty())
503 f = tmpf.absFileName();
508 bool RCS::prepareFileRevisionEnabled()
514 /////////////////////////////////////////////////////////////////////
518 /////////////////////////////////////////////////////////////////////
520 CVS::CVS(FileName const & m, Buffer * b) : VCS(b)
522 // Here we know that the buffer file is either already in CVS or
523 // about to be registered
525 have_rev_info_ = false;
530 FileName const CVS::findFile(FileName const & file)
532 // First we look for the CVS/Entries in the same dir
533 // where we have file.
534 FileName const entries(onlyPath(file.absFileName()) + "/CVS/Entries");
535 string const tmpf = '/' + onlyFileName(file.absFileName()) + '/';
536 LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under cvs in `" << entries
537 << "' for `" << tmpf << '\'');
538 if (entries.isReadableFile()) {
539 // Ok we are at least in a CVS dir. Parse the CVS/Entries
540 // and see if we can find this file. We do a fast and
542 ifstream ifs(entries.toFilesystemEncoding().c_str());
544 while (getline(ifs, line)) {
545 LYXERR(Debug::LYXVC, "\tEntries: " << line);
546 if (contains(line, tmpf))
554 void CVS::scanMaster()
556 LYXERR(Debug::LYXVC, "LyXVC::CVS: scanMaster. \n Checking: " << master_);
557 // Ok now we do the real scan...
558 ifstream ifs(master_.toFilesystemEncoding().c_str());
559 string name = onlyFileName(owner_->absFileName());
560 string tmpf = '/' + name + '/';
561 LYXERR(Debug::LYXVC, "\tlooking for `" << tmpf << '\'');
563 static regex const reg("/(.*)/(.*)/(.*)/(.*)/(.*)");
564 while (getline(ifs, line)) {
565 LYXERR(Debug::LYXVC, "\t line: " << line);
566 if (contains(line, tmpf)) {
567 // Ok extract the fields.
570 // false positive from coverity
571 // coverity[CHECKED_RETURN]
572 regex_match(line, sm, reg);
574 //sm[0]; // whole matched string
576 version_ = sm.str(2);
577 string const file_date = sm.str(3);
580 //sm[5]; // tag or tagdate
581 FileName file(owner_->absFileName());
582 if (file.isReadableFile()) {
583 time_t mod = file.lastModified();
584 string mod_date = rtrim(asctime(gmtime(&mod)), "\n");
585 LYXERR(Debug::LYXVC, "Date in Entries: `" << file_date
586 << "'\nModification date of file: `" << mod_date << '\'');
587 if (file.isReadOnly()) {
588 // readonly checkout is unlocked
591 FileName bdir(addPath(master_.onlyPath().absFileName(),"Base"));
592 FileName base(addName(bdir.absFileName(),name));
593 // if base version is existent "cvs edit" was used to lock
594 vcstatus = base.isReadableFile() ? LOCKED : NOLOCKING;
597 vcstatus = NOLOCKING;
605 bool CVS::retrieve(FileName const & file)
607 LYXERR(Debug::LYXVC, "LyXVC::CVS: retrieve.\n\t" << file);
608 // The caller ensures that file does not exist, so no need to check that.
609 return doVCCommandCall("cvs -q update " + quoteName(file.toFilesystemEncoding()),
610 file.onlyPath()) == 0;
614 string const CVS::getTarget(OperationMode opmode) const
618 // in client server mode CVS does not like full path operand for directory operation
619 // since LyX switches to the repo dir "." is good enough as target
622 return quoteName(onlyFileName(owner_->absFileName()));
628 docstring CVS::toString(CvsStatus status) const
632 return _("Up-to-date");
633 case LocallyModified:
634 return _("Locally Modified");
636 return _("Locally Added");
638 return _("Needs Merge");
640 return _("Needs Checkout");
642 return _("No CVS file");
644 return _("Cannot retrieve CVS status");
650 int CVS::doVCCommandWithOutput(string const & cmd, FileName const & path,
651 FileName const & output, bool reportError)
653 string redirection = output.empty() ? "" : " > " + quoteName(output.toFilesystemEncoding());
654 return doVCCommand(cmd + redirection, path, reportError);
658 int CVS::doVCCommandCallWithOutput(std::string const & cmd,
659 support::FileName const & path,
660 support::FileName const & output)
662 string redirection = output.empty() ? "" : " > " + quoteName(output.toFilesystemEncoding());
663 return doVCCommandCall(cmd + redirection, path);
667 CVS::CvsStatus CVS::getStatus()
669 TempFile tempfile("lyxvout");
670 FileName tmpf = tempfile.name();
672 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
676 if (doVCCommandCallWithOutput("cvs status " + getTarget(File),
677 FileName(owner_->filePath()), tmpf)) {
681 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
682 CvsStatus status = NoCvsFile;
687 LYXERR(Debug::LYXVC, line << '\n');
688 if (prefixIs(line, "File:")) {
689 if (contains(line, "Up-to-date"))
691 else if (contains(line, "Locally Modified"))
692 status = LocallyModified;
693 else if (contains(line, "Locally Added"))
694 status = LocallyAdded;
695 else if (contains(line, "Needs Merge"))
697 else if (contains(line, "Needs Checkout"))
698 status = NeedsCheckout;
704 void CVS::getRevisionInfo()
708 have_rev_info_ = true;
709 TempFile tempfile("lyxvout");
710 FileName tmpf = tempfile.name();
712 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
716 int rc = doVCCommandCallWithOutput("cvs log -r" + version_
717 + ' ' + getTarget(File),
718 FileName(owner_->filePath()), tmpf);
720 LYXERR(Debug::LYXVC, "cvs log failed with exit code " << rc);
724 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
725 static regex const reg("date: (.*) (.*) (.*); author: (.*); state: (.*);(.*)");
730 LYXERR(Debug::LYXVC, line << '\n');
731 if (prefixIs(line, "date:")) {
733 regex_match(line, sm, reg);
734 //sm[0]; // whole matched string
735 rev_date_cache_ = sm[1];
736 rev_time_cache_ = sm[2];
737 //sm[3]; // GMT offset
738 rev_author_cache_ = sm[4];
742 if (rev_author_cache_.empty())
744 "Could not retrieve revision info for " << version_ <<
745 " of " << getTarget(File));
749 void CVS::registrer(string const & msg)
751 doVCCommand("cvs -q add -m \"" + msg + "\" "
753 FileName(owner_->filePath()));
757 bool CVS::renameEnabled()
763 string CVS::rename(support::FileName const & newFile, string const & msg)
765 // CVS has no real rename command, so we create a poor mans version
766 support::FileName const oldFile(owner_->absFileName());
767 string ret = copy(newFile, msg);
770 string cmd = "cvs -q remove -m \"" + msg + "\" " +
771 quoteName(oldFile.onlyFileName());
772 FileName path(oldFile.onlyPath());
773 return doVCCommand(cmd, path) ? string() : ret;
777 bool CVS::copyEnabled()
783 string CVS::copy(support::FileName const & newFile, string const & msg)
785 // CVS has no real copy command, so we create a poor mans version
786 support::FileName const oldFile(owner_->absFileName());
787 if (!oldFile.copyTo(newFile))
789 FileName path(oldFile.onlyPath());
790 string relFile(to_utf8(newFile.relPath(path.absFileName())));
791 string cmd("cvs -q add -m \"" + msg + "\" " + quoteName(relFile));
792 return doVCCommand(cmd, path) ? string() : "CVS: Proceeded";
796 void CVS::getDiff(OperationMode opmode, FileName const & tmpf)
798 doVCCommandWithOutput("cvs diff " + getTarget(opmode),
799 FileName(owner_->filePath()), tmpf, false);
806 return doVCCommand("cvs -q edit " + getTarget(File),
807 FileName(owner_->filePath()));
814 return doVCCommand("cvs -q unedit " + getTarget(File),
815 FileName(owner_->filePath()));
819 int CVS::update(OperationMode opmode, FileName const & tmpf)
821 return doVCCommandWithOutput("cvs -q update "
823 FileName(owner_->filePath()), tmpf, false);
827 string CVS::scanLogFile(FileName const & f, string & status)
829 ifstream ifs(f.toFilesystemEncoding().c_str());
834 LYXERR(Debug::LYXVC, line << '\n');
836 status += line + "; ";
837 if (prefixIs(line, "C ")) {
847 LyXVC::CommandResult CVS::checkIn(string const & msg, string & log)
849 CvsStatus status = getStatus();
852 if (vcstatus != NOLOCKING)
854 return LyXVC::ErrorCommand;
855 log = "CVS: Proceeded";
856 return LyXVC::VCSuccess;
857 case LocallyModified:
859 int rc = doVCCommand("cvs -q commit -m \"" + msg + "\" "
861 FileName(owner_->filePath()));
863 return LyXVC::ErrorCommand;
864 log = "CVS: Proceeded";
865 return LyXVC::VCSuccess;
869 frontend::Alert::error(_("Revision control error."),
870 _("The repository version is newer then the current check out.\n"
871 "You have to update from repository first or revert your changes.")) ;
874 frontend::Alert::error(_("Revision control error."),
875 bformat(_("Bad status when checking in changes.\n"
880 return LyXVC::ErrorBefore;
884 bool CVS::isLocked() const
886 FileName fn(owner_->absFileName());
888 return !fn.isReadOnly();
892 bool CVS::checkInEnabled()
894 if (vcstatus != NOLOCKING)
901 bool CVS::isCheckInWithConfirmation()
903 CvsStatus status = getStatus();
904 return status == LocallyModified || status == LocallyAdded;
908 string CVS::checkOut()
910 if (vcstatus != NOLOCKING && edit())
912 TempFile tempfile("lyxvout");
913 FileName tmpf = tempfile.name();
915 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
919 int rc = update(File, tmpf);
921 string const res = scanLogFile(tmpf, log);
923 frontend::Alert::error(_("Revision control error."),
924 bformat(_("Error when updating from repository.\n"
925 "You have to manually resolve the conflicts NOW!\n'%1$s'.\n\n"
926 "After pressing OK, LyX will try to reopen the resolved document."),
927 from_local8bit(res)));
931 return rc ? string() : log.empty() ? "CVS: Proceeded" : "CVS: " + log;
935 bool CVS::checkOutEnabled()
937 if (vcstatus != NOLOCKING)
944 string CVS::repoUpdate()
946 TempFile tempfile("lyxvout");
947 FileName tmpf = tempfile.name();
949 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
953 getDiff(Directory, tmpf);
954 docstring res = tmpf.fileContents("UTF-8");
956 LYXERR(Debug::LYXVC, "Diff detected:\n" << res);
957 docstring const file = from_utf8(owner_->filePath());
958 docstring text = bformat(_("There were detected changes "
959 "in the working directory:\n%1$s\n\n"
960 "Possible file conflicts must be then resolved manually "
961 "or you will need to revert back to the repository version."), file);
962 int ret = frontend::Alert::prompt(_("Changes detected"),
963 text, 0, 1, _("&Continue"), _("&Abort"), _("View &Log ..."));
965 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + tmpf.absFileName()));
966 ret = frontend::Alert::prompt(_("Changes detected"),
967 text, 0, 1, _("&Continue"), _("&Abort"));
968 hideDialogs("file", 0);
974 int rc = update(Directory, tmpf);
975 res += "Update log:\n" + tmpf.fileContents("UTF-8");
976 LYXERR(Debug::LYXVC, res);
979 string sres = scanLogFile(tmpf, log);
981 docstring const file = owner_->fileName().displayName(20);
982 frontend::Alert::error(_("Revision control error."),
983 bformat(_("Error when updating document %1$s from repository.\n"
984 "You have to manually resolve the conflicts NOW!\n'%2$s'.\n\n"
985 "After pressing OK, LyX will try to reopen the resolved document."),
986 file, from_local8bit(sres)));
990 return rc ? string() : log.empty() ? "CVS: Proceeded" : "CVS: " + log;
994 bool CVS::repoUpdateEnabled()
1000 string CVS::lockingToggle()
1002 lyxerr << "Sorry, not implemented." << endl;
1007 bool CVS::lockingToggleEnabled()
1013 bool CVS::isRevertWithConfirmation()
1015 CvsStatus status = getStatus();
1016 return !owner_->isClean() || status == LocallyModified || status == NeedsMerge;
1022 // Reverts to the version in CVS repository and
1023 // gets the updated version from the repository.
1024 CvsStatus status = getStatus();
1027 if (vcstatus != NOLOCKING)
1028 return 0 == unedit();
1032 case LocallyModified: {
1033 FileName f(owner_->absFileName());
1035 update(File, FileName());
1036 owner_->markClean();
1039 case LocallyAdded: {
1040 docstring const file = owner_->fileName().displayName(20);
1041 frontend::Alert::error(_("Revision control error."),
1042 bformat(_("The document %1$s is not in repository.\n"
1043 "You have to check in the first revision before you can revert."),
1048 docstring const file = owner_->fileName().displayName(20);
1049 frontend::Alert::error(_("Revision control error."),
1050 bformat(_("Cannot revert document %1$s to repository version.\n"
1051 "The status '%2$s' is unexpected."),
1052 file, toString(status)));
1060 void CVS::undoLast()
1062 // merge the current with the previous version
1063 // in a reverse patch kind of way, so that the
1064 // result is to revert the last changes.
1065 lyxerr << "Sorry, not implemented." << endl;
1069 bool CVS::undoLastEnabled()
1075 void CVS::getLog(FileName const & tmpf)
1077 doVCCommandWithOutput("cvs log " + getTarget(File),
1078 FileName(owner_->filePath()),
1083 bool CVS::toggleReadOnlyEnabled()
1089 string CVS::revisionInfo(LyXVC::RevisionInfo const info)
1091 if (!version_.empty()) {
1097 return rev_author_cache_;
1099 return rev_date_cache_;
1101 return rev_time_cache_;
1109 bool CVS::prepareFileRevision(string const & revis, string & f)
1112 if (!VCS::makeRCSRevision(version_, rev))
1115 TempFile tempfile("lyxvcrev_" + rev + '_');
1116 tempfile.setAutoRemove(false);
1117 FileName tmpf = tempfile.name();
1119 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1123 doVCCommandWithOutput("cvs update -p -r" + rev + ' '
1125 FileName(owner_->filePath()), tmpf);
1127 if (tmpf.isFileEmpty())
1130 f = tmpf.absFileName();
1135 bool CVS::prepareFileRevisionEnabled()
1141 /////////////////////////////////////////////////////////////////////
1145 /////////////////////////////////////////////////////////////////////
1147 SVN::SVN(FileName const & m, Buffer * b) : VCS(b)
1149 // Here we know that the buffer file is either already in SVN or
1150 // about to be registered
1157 FileName const SVN::findFile(FileName const & file)
1159 // First we check the existence of repository meta data.
1160 if (!VCS::checkparentdirs(file, ".svn")) {
1161 LYXERR(Debug::LYXVC, "Cannot find SVN meta data for " << file);
1165 // Now we check the status of the file.
1166 TempFile tempfile("lyxvcout");
1167 FileName tmpf = tempfile.name();
1169 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1173 string const fname = onlyFileName(file.absFileName());
1174 LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under svn control for `" << fname << '\'');
1175 bool found = 0 == doVCCommandCall("svn info " + quoteName(fname)
1176 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1178 LYXERR(Debug::LYXVC, "SVN control: " << (found ? "enabled" : "disabled"));
1179 return found ? file : FileName();
1183 void SVN::scanMaster()
1185 // vcstatus code is somewhat superflous,
1186 // until we want to implement read-only toggle for svn.
1187 vcstatus = NOLOCKING;
1188 if (checkLockMode()) {
1192 vcstatus = UNLOCKED;
1197 bool SVN::checkLockMode()
1199 TempFile tempfile("lyxvcout");
1200 FileName tmpf = tempfile.name();
1202 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1206 LYXERR(Debug::LYXVC, "Detecting locking mode...");
1207 if (doVCCommandCall("svn proplist " + quoteName(onlyFileName(owner_->absFileName()))
1208 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1209 FileName(owner_->filePath())))
1212 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1216 while (ifs && !ret) {
1218 LYXERR(Debug::LYXVC, line);
1219 if (contains(line, "svn:needs-lock"))
1222 LYXERR(Debug::LYXVC, "Locking enabled: " << ret);
1230 bool SVN::isLocked() const
1232 FileName file(owner_->absFileName());
1234 return !file.isReadOnly();
1238 bool SVN::retrieve(FileName const & file)
1240 LYXERR(Debug::LYXVC, "LyXVC::SVN: retrieve.\n\t" << file);
1241 // The caller ensures that file does not exist, so no need to check that.
1242 return doVCCommandCall("svn update -q --non-interactive " + quoteName(file.onlyFileName()),
1243 file.onlyPath()) == 0;
1247 void SVN::registrer(string const & /*msg*/)
1249 doVCCommand("svn add -q " + quoteName(onlyFileName(owner_->absFileName())),
1250 FileName(owner_->filePath()));
1254 bool SVN::renameEnabled()
1260 string SVN::rename(support::FileName const & newFile, string const & msg)
1262 // svn move does not require a log message, since it does not commit.
1263 // In LyX we commit immediately afterwards, otherwise it could be
1264 // confusing to the user to have two uncommitted files.
1265 FileName path(owner_->filePath());
1266 string relFile(to_utf8(newFile.relPath(path.absFileName())));
1267 string cmd("svn move -q " + quoteName(onlyFileName(owner_->absFileName())) +
1268 ' ' + quoteName(relFile));
1269 if (doVCCommand(cmd, path)) {
1270 cmd = "svn revert -q " +
1271 quoteName(onlyFileName(owner_->absFileName())) + ' ' +
1273 doVCCommand(cmd, path);
1274 if (newFile.exists())
1275 newFile.removeFile();
1278 vector<support::FileName> f;
1279 f.push_back(owner_->fileName());
1280 f.push_back(newFile);
1282 if (checkIn(f, msg, log) != LyXVC::VCSuccess) {
1283 cmd = "svn revert -q " +
1284 quoteName(onlyFileName(owner_->absFileName())) + ' ' +
1286 doVCCommand(cmd, path);
1287 if (newFile.exists())
1288 newFile.removeFile();
1295 bool SVN::copyEnabled()
1301 string SVN::copy(support::FileName const & newFile, string const & msg)
1303 // svn copy does not require a log message, since it does not commit.
1304 // In LyX we commit immediately afterwards, otherwise it could be
1305 // confusing to the user to have an uncommitted file.
1306 FileName path(owner_->filePath());
1307 string relFile(to_utf8(newFile.relPath(path.absFileName())));
1308 string cmd("svn copy -q " + quoteName(onlyFileName(owner_->absFileName())) +
1309 ' ' + quoteName(relFile));
1310 if (doVCCommand(cmd, path))
1312 vector<support::FileName> f(1, newFile);
1314 if (checkIn(f, msg, log) == LyXVC::VCSuccess)
1320 LyXVC::CommandResult SVN::checkIn(string const & msg, string & log)
1322 vector<support::FileName> f(1, owner_->fileName());
1323 return checkIn(f, msg, log);
1327 LyXVC::CommandResult
1328 SVN::checkIn(vector<support::FileName> const & f, string const & msg, string & log)
1330 TempFile tempfile("lyxvcout");
1331 FileName tmpf = tempfile.name();
1333 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1334 log = N_("Error: Could not generate logfile.");
1335 return LyXVC::ErrorBefore;
1339 os << "svn commit -m \"" << msg << '"';
1340 for (size_t i = 0; i < f.size(); ++i)
1341 os << ' ' << quoteName(f[i].onlyFileName());
1342 os << " > " << quoteName(tmpf.toFilesystemEncoding());
1343 LyXVC::CommandResult ret =
1344 doVCCommand(os.str(), FileName(owner_->filePath())) ?
1345 LyXVC::ErrorCommand : LyXVC::VCSuccess;
1347 string res = scanLogFile(tmpf, log);
1349 frontend::Alert::error(_("Revision control error."),
1350 _("Error when committing to repository.\n"
1351 "You have to manually resolve the problem.\n"
1352 "LyX will reopen the document after you press OK."));
1353 ret = LyXVC::ErrorCommand;
1356 if (!fileLock(false, tmpf, log))
1357 ret = LyXVC::ErrorCommand;
1360 log.insert(0, "SVN: ");
1361 if (ret == LyXVC::VCSuccess && log.empty())
1362 log = "SVN: Proceeded";
1367 bool SVN::checkInEnabled()
1376 bool SVN::isCheckInWithConfirmation()
1378 // FIXME one day common getDiff and perhaps OpMode for all backends
1380 TempFile tempfile("lyxvcout");
1381 FileName tmpf = tempfile.name();
1383 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1387 doVCCommandCall("svn diff " + quoteName(owner_->absFileName())
1388 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1389 FileName(owner_->filePath()));
1391 docstring diff = tmpf.fileContents("UTF-8");
1400 // FIXME Correctly return code should be checked instead of this.
1401 // This would need another solution than just plain startscript.
1402 // Hint from Andre': QProcess::readAllStandardError()...
1403 string SVN::scanLogFile(FileName const & f, string & status)
1405 ifstream ifs(f.toFilesystemEncoding().c_str());
1410 LYXERR(Debug::LYXVC, line << '\n');
1412 status += line + "; ";
1413 if (prefixIs(line, "C ") || prefixIs(line, "CU ")
1414 || contains(line, "Commit failed")) {
1418 if (contains(line, "svn:needs-lock")) {
1428 bool SVN::fileLock(bool lock, FileName const & tmpf, string &status)
1430 if (!locked_mode_ || (isLocked() == lock))
1433 string const arg = lock ? "lock " : "unlock ";
1434 doVCCommand("svn "+ arg + quoteName(onlyFileName(owner_->absFileName()))
1435 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1436 FileName(owner_->filePath()));
1438 // Lock error messages go unfortunately on stderr and are unreachable this way.
1439 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1443 if (!line.empty()) status += line + "; ";
1447 if (isLocked() == lock)
1451 frontend::Alert::error(_("Revision control error."),
1452 _("Error while acquiring write lock.\n"
1453 "Another user is most probably editing\n"
1454 "the current document now!\n"
1455 "Also check the access to the repository."));
1457 frontend::Alert::error(_("Revision control error."),
1458 _("Error while releasing write lock.\n"
1459 "Check the access to the repository."));
1464 string SVN::checkOut()
1466 TempFile tempfile("lyxvcout");
1467 FileName tmpf = tempfile.name();
1469 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1470 return N_("Error: Could not generate logfile.");
1473 doVCCommand("svn update --non-interactive " + quoteName(onlyFileName(owner_->absFileName()))
1474 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1475 FileName(owner_->filePath()));
1478 string const res = scanLogFile(tmpf, log);
1480 frontend::Alert::error(_("Revision control error."),
1481 bformat(_("Error when updating from repository.\n"
1482 "You have to manually resolve the conflicts NOW!\n'%1$s'.\n\n"
1483 "After pressing OK, LyX will try to reopen the resolved document."),
1484 from_local8bit(res)));
1486 fileLock(true, tmpf, log);
1488 return log.empty() ? string() : "SVN: " + log;
1492 bool SVN::checkOutEnabled()
1501 string SVN::repoUpdate()
1503 TempFile tempfile("lyxvcout");
1504 FileName tmpf = tempfile.name();
1506 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1507 return N_("Error: Could not generate logfile.");
1510 doVCCommand("svn diff " + quoteName(owner_->filePath())
1511 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1512 FileName(owner_->filePath()));
1513 docstring res = tmpf.fileContents("UTF-8");
1515 LYXERR(Debug::LYXVC, "Diff detected:\n" << res);
1516 docstring const file = from_utf8(owner_->filePath());
1517 docstring text = bformat(_("There were detected changes "
1518 "in the working directory:\n%1$s\n\n"
1519 "In case of file conflict version of the local directory files "
1520 "will be preferred."
1521 "\n\nContinue?"), file);
1522 int ret = frontend::Alert::prompt(_("Changes detected"),
1523 text, 0, 1, _("&Yes"), _("&No"), _("View &Log ..."));
1525 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + tmpf.absFileName()));
1526 ret = frontend::Alert::prompt(_("Changes detected"),
1527 text, 0, 1, _("&Yes"), _("&No"));
1528 hideDialogs("file", 0);
1534 // Reverting looks too harsh, see bug #6255.
1535 // doVCCommand("svn revert -R " + quoteName(owner_->filePath())
1536 // + " > " + quoteName(tmpf.toFilesystemEncoding()),
1537 // FileName(owner_->filePath()));
1538 // res = "Revert log:\n" + tmpf.fileContents("UTF-8");
1539 doVCCommand("svn update --accept mine-full " + quoteName(owner_->filePath())
1540 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1541 FileName(owner_->filePath()));
1542 res += "Update log:\n" + tmpf.fileContents("UTF-8");
1544 LYXERR(Debug::LYXVC, res);
1545 return to_utf8(res);
1549 bool SVN::repoUpdateEnabled()
1555 string SVN::lockingToggle()
1557 TempFile tempfile("lyxvcout");
1558 FileName tmpf = tempfile.name();
1560 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1561 return N_("Error: Could not generate logfile.");
1564 int ret = doVCCommand("svn proplist " + quoteName(onlyFileName(owner_->absFileName()))
1565 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1566 FileName(owner_->filePath()));
1571 string res = scanLogFile(tmpf, log);
1572 bool locking = contains(res, "svn:needs-lock");
1574 ret = doVCCommand("svn propset svn:needs-lock ON "
1575 + quoteName(onlyFileName(owner_->absFileName()))
1576 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1577 FileName(owner_->filePath()));
1579 ret = doVCCommand("svn propdel svn:needs-lock "
1580 + quoteName(onlyFileName(owner_->absFileName()))
1581 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1582 FileName(owner_->filePath()));
1586 frontend::Alert::warning(_("SVN File Locking"),
1587 (locking ? _("Locking property unset.") : _("Locking property set.")) + '\n'
1588 + _("Do not forget to commit the locking property into the repository."),
1591 return string("SVN: ") + (locking ?
1592 N_("Locking property unset.") : N_("Locking property set."));
1596 bool SVN::lockingToggleEnabled()
1604 // Reverts to the version in SVN repository and
1605 // gets the updated version from the repository.
1606 string const fil = quoteName(onlyFileName(owner_->absFileName()));
1608 if (doVCCommand("svn revert -q " + fil,
1609 FileName(owner_->filePath())))
1611 owner_->markClean();
1616 bool SVN::isRevertWithConfirmation()
1618 //FIXME owner && diff
1623 void SVN::undoLast()
1625 // merge the current with the previous version
1626 // in a reverse patch kind of way, so that the
1627 // result is to revert the last changes.
1628 lyxerr << "Sorry, not implemented." << endl;
1632 bool SVN::undoLastEnabled()
1638 string SVN::revisionInfo(LyXVC::RevisionInfo const info)
1640 if (info == LyXVC::Tree) {
1641 if (rev_tree_cache_.empty())
1642 if (!getTreeRevisionInfo())
1643 rev_tree_cache_ = "?";
1644 if (rev_tree_cache_ == "?")
1647 return rev_tree_cache_;
1650 // fill the rest of the attributes for a single file
1651 if (rev_file_cache_.empty())
1652 if (!getFileRevisionInfo())
1653 rev_file_cache_ = "?";
1657 if (rev_file_cache_ == "?")
1659 return rev_file_cache_;
1661 return rev_author_cache_;
1663 return rev_date_cache_;
1665 return rev_time_cache_;
1674 bool SVN::getFileRevisionInfo()
1676 TempFile tempfile("lyxvcout");
1677 FileName tmpf = tempfile.name();
1679 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1683 doVCCommand("svn info --xml " + quoteName(onlyFileName(owner_->absFileName()))
1684 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1685 FileName(owner_->filePath()));
1690 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1698 LYXERR(Debug::LYXVC, line);
1699 if (prefixIs(line, "<commit"))
1701 if (c && prefixIs(line, " revision=\"") && suffixIs(line, "\">")) {
1702 string l1 = subst(line, "revision=\"", "");
1703 string l2 = trim(subst(l1, "\">", ""));
1705 rev_file_cache_ = rev = l2;
1707 if (c && prefixIs(line, "<author>") && suffixIs(line, "</author>")) {
1708 string l1 = subst(line, "<author>", "");
1709 string l2 = subst(l1, "</author>", "");
1710 rev_author_cache_ = l2;
1712 if (c && prefixIs(line, "<date>") && suffixIs(line, "</date>")) {
1713 string l1 = subst(line, "<date>", "");
1714 string l2 = subst(l1, "</date>", "");
1715 l2 = split(l2, l1, 'T');
1716 rev_date_cache_ = l1;
1717 l2 = split(l2, l1, '.');
1718 rev_time_cache_ = l1;
1723 return !rev.empty();
1727 bool SVN::getTreeRevisionInfo()
1729 TempFile tempfile("lyxvcout");
1730 FileName tmpf = tempfile.name();
1732 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1736 doVCCommand("svnversion -n . > " + quoteName(tmpf.toFilesystemEncoding()),
1737 FileName(owner_->filePath()));
1742 // only first line in case something bad happens.
1743 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1748 rev_tree_cache_ = line;
1749 return !line.empty();
1753 void SVN::getLog(FileName const & tmpf)
1755 doVCCommand("svn log " + quoteName(onlyFileName(owner_->absFileName()))
1756 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1757 FileName(owner_->filePath()));
1761 bool SVN::prepareFileRevision(string const & revis, string & f)
1763 if (!isStrInt(revis))
1766 int rev = convert<int>(revis);
1768 if (!getFileRevisionInfo())
1771 rev = convert<int>(rev_file_cache_);
1772 // go back for minus rev
1774 rev = rev + convert<int>(rev_file_cache_);
1779 string revname = convert<string>(rev);
1780 TempFile tempfile("lyxvcrev_" + revname + '_');
1781 tempfile.setAutoRemove(false);
1782 FileName tmpf = tempfile.name();
1784 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1788 doVCCommand("svn cat -r " + revname + ' '
1789 + quoteName(onlyFileName(owner_->absFileName()))
1790 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1791 FileName(owner_->filePath()));
1793 if (tmpf.isFileEmpty())
1796 f = tmpf.absFileName();
1801 bool SVN::prepareFileRevisionEnabled()
1808 bool SVN::toggleReadOnlyEnabled()
1814 /////////////////////////////////////////////////////////////////////
1818 /////////////////////////////////////////////////////////////////////
1820 GIT::GIT(FileName const & m, Buffer * b) : VCS(b)
1822 // Here we know that the buffer file is either already in GIT or
1823 // about to be registered
1829 FileName const GIT::findFile(FileName const & file)
1831 // First we check the existence of repository meta data.
1832 if (!VCS::checkparentdirs(file, ".git")) {
1833 LYXERR(Debug::LYXVC, "Cannot find GIT meta data for " << file);
1837 // Now we check the status of the file.
1838 TempFile tempfile("lyxvcout");
1839 FileName tmpf = tempfile.name();
1841 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1845 string const fname = onlyFileName(file.absFileName());
1846 LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under git control for `"
1848 doVCCommandCall("git ls-files " +
1849 quoteName(fname) + " > " +
1850 quoteName(tmpf.toFilesystemEncoding()),
1853 bool found = !tmpf.isFileEmpty();
1854 LYXERR(Debug::LYXVC, "GIT control: " << (found ? "enabled" : "disabled"));
1855 return found ? file : FileName();
1859 void GIT::scanMaster()
1861 // vcstatus code is somewhat superflous,
1862 // until we want to implement read-only toggle for git.
1863 vcstatus = NOLOCKING;
1867 bool GIT::retrieve(FileName const & file)
1869 LYXERR(Debug::LYXVC, "LyXVC::GIT: retrieve.\n\t" << file);
1870 // The caller ensures that file does not exist, so no need to check that.
1871 return doVCCommandCall("git checkout -q " + quoteName(file.onlyFileName()),
1872 file.onlyPath()) == 0;
1876 void GIT::registrer(string const & /*msg*/)
1878 doVCCommand("git add " + quoteName(onlyFileName(owner_->absFileName())),
1879 FileName(owner_->filePath()));
1883 bool GIT::renameEnabled()
1889 string GIT::rename(support::FileName const & newFile, string const & msg)
1891 // git mv does not require a log message, since it does not commit.
1892 // In LyX we commit immediately afterwards, otherwise it could be
1893 // confusing to the user to have two uncommitted files.
1894 FileName path(owner_->filePath());
1895 string relFile(to_utf8(newFile.relPath(path.absFileName())));
1896 string cmd("git mv " + quoteName(onlyFileName(owner_->absFileName())) +
1897 ' ' + quoteName(relFile));
1898 if (doVCCommand(cmd, path)) {
1899 cmd = "git checkout -q " +
1900 quoteName(onlyFileName(owner_->absFileName())) + ' ' +
1902 doVCCommand(cmd, path);
1903 if (newFile.exists())
1904 newFile.removeFile();
1907 vector<support::FileName> f;
1908 f.push_back(owner_->fileName());
1909 f.push_back(newFile);
1911 if (checkIn(f, msg, log) != LyXVC::VCSuccess) {
1912 cmd = "git checkout -q " +
1913 quoteName(onlyFileName(owner_->absFileName())) + ' ' +
1915 doVCCommand(cmd, path);
1916 if (newFile.exists())
1917 newFile.removeFile();
1924 bool GIT::copyEnabled()
1930 string GIT::copy(support::FileName const & /*newFile*/, string const & /*msg*/)
1932 // git does not support copy with history preservation
1937 LyXVC::CommandResult GIT::checkIn(string const & msg, string & log)
1939 vector<support::FileName> f(1, owner_->fileName());
1940 return checkIn(f, msg, log);
1944 LyXVC::CommandResult
1945 GIT::checkIn(vector<support::FileName> const & f, string const & msg, string & log)
1947 TempFile tempfile("lyxvcout");
1948 FileName tmpf = tempfile.name();
1950 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1951 log = N_("Error: Could not generate logfile.");
1952 return LyXVC::ErrorBefore;
1956 os << "git commit -m \"" << msg << '"';
1957 for (size_t i = 0; i < f.size(); ++i)
1958 os << ' ' << quoteName(f[i].onlyFileName());
1959 os << " > " << quoteName(tmpf.toFilesystemEncoding());
1960 LyXVC::CommandResult ret =
1961 doVCCommand(os.str(), FileName(owner_->filePath())) ?
1962 LyXVC::ErrorCommand : LyXVC::VCSuccess;
1964 string res = scanLogFile(tmpf, log);
1966 frontend::Alert::error(_("Revision control error."),
1967 _("Error when committing to repository.\n"
1968 "You have to manually resolve the problem.\n"
1969 "LyX will reopen the document after you press OK."));
1970 ret = LyXVC::ErrorCommand;
1974 log.insert(0, "GIT: ");
1975 if (ret == LyXVC::VCSuccess && log.empty())
1976 log = "GIT: Proceeded";
1981 bool GIT::checkInEnabled()
1987 bool GIT::isCheckInWithConfirmation()
1989 // FIXME one day common getDiff and perhaps OpMode for all backends
1991 TempFile tempfile("lyxvcout");
1992 FileName tmpf = tempfile.name();
1994 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1998 doVCCommandCall("git diff " + quoteName(owner_->absFileName())
1999 + " > " + quoteName(tmpf.toFilesystemEncoding()),
2000 FileName(owner_->filePath()));
2002 docstring diff = tmpf.fileContents("UTF-8");
2011 // FIXME Correctly return code should be checked instead of this.
2012 // This would need another solution than just plain startscript.
2013 // Hint from Andre': QProcess::readAllStandardError()...
2014 string GIT::scanLogFile(FileName const & f, string & status)
2016 ifstream ifs(f.toFilesystemEncoding().c_str());
2021 LYXERR(Debug::LYXVC, line << "\n");
2023 status += line + "; ";
2024 if (prefixIs(line, "C ") || prefixIs(line, "CU ")
2025 || contains(line, "Commit failed")) {
2035 string GIT::checkOut()
2041 bool GIT::checkOutEnabled()
2047 string GIT::repoUpdate()
2053 bool GIT::repoUpdateEnabled()
2059 string GIT::lockingToggle()
2065 bool GIT::lockingToggleEnabled()
2073 // Reverts to the version in GIT repository and
2074 // gets the updated version from the repository.
2075 string const fil = quoteName(onlyFileName(owner_->absFileName()));
2077 if (doVCCommand("git checkout -q " + fil,
2078 FileName(owner_->filePath())))
2080 owner_->markClean();
2085 bool GIT::isRevertWithConfirmation()
2087 //FIXME owner && diff
2092 void GIT::undoLast()
2094 // merge the current with the previous version
2095 // in a reverse patch kind of way, so that the
2096 // result is to revert the last changes.
2097 lyxerr << "Sorry, not implemented." << endl;
2101 bool GIT::undoLastEnabled()
2107 string GIT::revisionInfo(LyXVC::RevisionInfo const info)
2109 if (info == LyXVC::Tree) {
2110 if (rev_tree_cache_.empty())
2111 if (!getTreeRevisionInfo())
2112 rev_tree_cache_ = "?";
2113 if (rev_tree_cache_ == "?")
2116 return rev_tree_cache_;
2119 // fill the rest of the attributes for a single file
2120 if (rev_file_cache_.empty())
2121 if (!getFileRevisionInfo())
2122 rev_file_cache_ = "?";
2126 if (rev_file_cache_ == "?")
2128 return rev_file_cache_;
2130 return rev_author_cache_;
2132 return rev_date_cache_;
2134 return rev_time_cache_;
2143 bool GIT::getFileRevisionInfo()
2145 TempFile tempfile("lyxvcout");
2146 FileName tmpf = tempfile.name();
2148 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
2152 doVCCommand("git log -n 1 --pretty=format:%H%n%an%n%ai " + quoteName(onlyFileName(owner_->absFileName()))
2153 + " > " + quoteName(tmpf.toFilesystemEncoding()),
2154 FileName(owner_->filePath()));
2159 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
2162 getline(ifs, rev_file_cache_);
2164 getline(ifs, rev_author_cache_);
2168 rev_time_cache_ = split(line, rev_date_cache_, ' ');
2172 return !rev_file_cache_.empty();
2176 bool GIT::getTreeRevisionInfo()
2178 TempFile tempfile("lyxvcout");
2179 FileName tmpf = tempfile.name();
2181 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
2185 doVCCommand("git describe --abbrev --dirty --long > " + quoteName(tmpf.toFilesystemEncoding()),
2186 FileName(owner_->filePath()));
2191 // only first line in case something bad happens.
2192 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
2193 getline(ifs, rev_tree_cache_);
2196 return !rev_tree_cache_.empty();
2200 void GIT::getLog(FileName const & tmpf)
2202 doVCCommand("git log " + quoteName(onlyFileName(owner_->absFileName()))
2203 + " > " + quoteName(tmpf.toFilesystemEncoding()),
2204 FileName(owner_->filePath()));
2208 //at this moment we don't accept revision SHA, but just number of revision steps back
2209 //GUI and infrastucture needs to be changed first
2210 bool GIT::prepareFileRevision(string const & revis, string & f)
2212 // anything positive means we got hash, not "0" or minus revision
2215 // hash is rarely number and should be long
2216 if (isStrInt(revis) && revis.length()<20)
2217 rev = convert<int>(revis);
2219 // revision and filename
2222 // go back for "minus" revisions
2224 pointer = "HEAD~" + convert<string>(-rev);
2231 TempFile tempfile("lyxvcrev_" + revis + '_');
2232 tempfile.setAutoRemove(false);
2233 FileName tmpf = tempfile.name();
2235 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
2239 doVCCommand("git show " + pointer + "./"
2240 + quoteName(onlyFileName(owner_->absFileName()))
2241 + " > " + quoteName(tmpf.toFilesystemEncoding()),
2242 FileName(owner_->filePath()));
2244 if (tmpf.isFileEmpty())
2247 f = tmpf.absFileName();
2252 bool GIT::prepareFileRevisionEnabled()
2258 bool GIT::toggleReadOnlyEnabled()