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"
17 #include "FuncRequest.h"
19 #include "frontends/alert.h"
20 #include "frontends/Application.h"
22 #include "support/convert.h"
23 #include "support/debug.h"
24 #include "support/filetools.h"
25 #include "support/gettext.h"
26 #include "support/lstrings.h"
27 #include "support/PathChanger.h"
28 #include "support/Systemcall.h"
29 #include "support/regex.h"
34 using namespace lyx::support;
41 int VCS::doVCCommandCall(string const & cmd, FileName const & path)
43 LYXERR(Debug::LYXVC, "doVCCommandCall: " << cmd);
45 support::PathChanger p(path);
46 return one.startscript(Systemcall::Wait, cmd, string(), false);
50 int VCS::doVCCommand(string const & cmd, FileName const & path, bool reportError)
53 owner_->setBusy(true);
55 int const ret = doVCCommandCall(cmd, path);
58 owner_->setBusy(false);
59 if (ret && reportError)
60 frontend::Alert::error(_("Revision control error."),
61 bformat(_("Some problem occured while running the command:\n"
68 bool VCS::makeRCSRevision(string const &version, string &revis) const
73 int back = convert<int>(rev);
74 // if positive use as the last number in the whole revision string
77 rsplit(version, base , '.' );
78 rev = base + "." + rev;
82 // we care about the last number from revision string
83 // in case of backward indexing
86 cur = rsplit(version, base , '.' );
89 int want = convert<int>(cur) + back;
93 rev = base + "." + convert<string>(want);
102 bool VCS::checkparentdirs(FileName const & file, std::string const & pathname)
104 FileName dirname = file.onlyPath();
105 FileName tocheck = FileName(addName(dirname.absFileName(),pathname));
106 LYXERR(Debug::LYXVC, "check file: " << tocheck.absFileName());
107 bool result = tocheck.exists();
108 while ( !result && !dirname.empty() ) {
109 //this construct because of #8295
110 dirname = FileName(dirname.absFileName()).parentPath();
111 LYXERR(Debug::LYXVC, "check directory: " << dirname.absFileName());
112 tocheck = FileName(addName(dirname.absFileName(),pathname));
113 result = tocheck.exists();
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_->isReadonly();
291 bool RCS::isCheckInWithConfirmation()
293 // FIXME one day common getDiff for all backends
295 // if (getDiff(file, diff) && diff.empty())
298 FileName tmpf = FileName::tempName("lyxvcout");
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");
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_->isReadonly();
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 FileName tmpf = FileName::tempName("lyxvcout");
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 FileName tmpf = FileName::tempName("lyxvcrev_" + rev + "_");
488 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
492 doVCCommand("co -p" + rev + " "
493 + quoteName(onlyFileName(owner_->absFileName()))
494 + " > " + quoteName(tmpf.toFilesystemEncoding()),
495 FileName(owner_->filePath()));
496 if (tmpf.isFileEmpty())
499 f = tmpf.absFileName();
504 bool RCS::prepareFileRevisionEnabled()
510 /////////////////////////////////////////////////////////////////////
514 /////////////////////////////////////////////////////////////////////
516 CVS::CVS(FileName const & m, Buffer * b) : VCS(b)
518 // Here we know that the buffer file is either already in CVS or
519 // about to be registered
521 have_rev_info_ = false;
526 FileName const CVS::findFile(FileName const & file)
528 // First we look for the CVS/Entries in the same dir
529 // where we have file.
530 FileName const entries(onlyPath(file.absFileName()) + "/CVS/Entries");
531 string const tmpf = '/' + onlyFileName(file.absFileName()) + '/';
532 LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under cvs in `" << entries
533 << "' for `" << tmpf << '\'');
534 if (entries.isReadableFile()) {
535 // Ok we are at least in a CVS dir. Parse the CVS/Entries
536 // and see if we can find this file. We do a fast and
538 ifstream ifs(entries.toFilesystemEncoding().c_str());
540 while (getline(ifs, line)) {
541 LYXERR(Debug::LYXVC, "\tEntries: " << line);
542 if (contains(line, tmpf))
550 void CVS::scanMaster()
552 LYXERR(Debug::LYXVC, "LyXVC::CVS: scanMaster. \n Checking: " << master_);
553 // Ok now we do the real scan...
554 ifstream ifs(master_.toFilesystemEncoding().c_str());
555 string name = onlyFileName(owner_->absFileName());
556 string tmpf = '/' + name + '/';
557 LYXERR(Debug::LYXVC, "\tlooking for `" << tmpf << '\'');
559 static regex const reg("/(.*)/(.*)/(.*)/(.*)/(.*)");
560 while (getline(ifs, line)) {
561 LYXERR(Debug::LYXVC, "\t line: " << line);
562 if (contains(line, tmpf)) {
563 // Ok extract the fields.
566 regex_match(line, sm, reg);
568 //sm[0]; // whole matched string
570 version_ = sm.str(2);
571 string const file_date = sm.str(3);
574 //sm[5]; // tag or tagdate
575 FileName file(owner_->absFileName());
576 if (file.isReadableFile()) {
577 time_t mod = file.lastModified();
578 string mod_date = rtrim(asctime(gmtime(&mod)), "\n");
579 LYXERR(Debug::LYXVC, "Date in Entries: `" << file_date
580 << "'\nModification date of file: `" << mod_date << '\'');
581 if (file.isReadOnly()) {
582 // readonly checkout is unlocked
585 FileName bdir(addPath(master_.onlyPath().absFileName(),"Base"));
586 FileName base(addName(bdir.absFileName(),name));
587 // if base version is existent "cvs edit" was used to lock
588 vcstatus = base.isReadableFile() ? LOCKED : NOLOCKING;
591 vcstatus = NOLOCKING;
599 bool CVS::retrieve(FileName const & file)
601 LYXERR(Debug::LYXVC, "LyXVC::CVS: retrieve.\n\t" << file);
602 // The caller ensures that file does not exist, so no need to check that.
603 return doVCCommandCall("cvs -q update " + quoteName(file.toFilesystemEncoding()),
604 file.onlyPath()) == 0;
608 string const CVS::getTarget(OperationMode opmode) const
612 // in client server mode CVS does not like full path operand for directory operation
613 // since LyX switches to the repo dir "." is good enough as target
616 return quoteName(onlyFileName(owner_->absFileName()));
622 docstring CVS::toString(CvsStatus status) const
626 return _("Up-to-date");
627 case LocallyModified:
628 return _("Locally Modified");
630 return _("Locally Added");
632 return _("Needs Merge");
634 return _("Needs Checkout");
636 return _("No CVS file");
638 return _("Cannot retrieve CVS status");
644 int CVS::doVCCommandWithOutput(string const & cmd, FileName const & path,
645 FileName const & output, bool reportError)
647 string redirection = output.empty() ? "" : " > " + quoteName(output.toFilesystemEncoding());
648 return doVCCommand(cmd + redirection, path, reportError);
652 int CVS::doVCCommandCallWithOutput(std::string const & cmd,
653 support::FileName const & path,
654 support::FileName const & output)
656 string redirection = output.empty() ? "" : " > " + quoteName(output.toFilesystemEncoding());
657 return doVCCommandCall(cmd + redirection, path);
661 CVS::CvsStatus CVS::getStatus()
663 FileName tmpf = FileName::tempName("lyxvcout");
665 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
669 if (doVCCommandCallWithOutput("cvs status " + getTarget(File),
670 FileName(owner_->filePath()), tmpf)) {
675 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
676 CvsStatus status = NoCvsFile;
681 LYXERR(Debug::LYXVC, line << "\n");
682 if (prefixIs(line, "File:")) {
683 if (contains(line, "Up-to-date"))
685 else if (contains(line, "Locally Modified"))
686 status = LocallyModified;
687 else if (contains(line, "Locally Added"))
688 status = LocallyAdded;
689 else if (contains(line, "Needs Merge"))
691 else if (contains(line, "Needs Checkout"))
692 status = NeedsCheckout;
699 void CVS::getRevisionInfo()
703 have_rev_info_ = true;
704 FileName tmpf = FileName::tempName("lyxvcout");
706 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
710 int rc = doVCCommandCallWithOutput("cvs log -r" + version_
711 + " " + getTarget(File),
712 FileName(owner_->filePath()), tmpf);
715 LYXERR(Debug::LYXVC, "cvs log failed with exit code " << rc);
719 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
720 static regex const reg("date: (.*) (.*) (.*); author: (.*); state: (.*);(.*)");
725 LYXERR(Debug::LYXVC, line << "\n");
726 if (prefixIs(line, "date:")) {
728 regex_match(line, sm, reg);
729 //sm[0]; // whole matched string
730 rev_date_cache_ = sm[1];
731 rev_time_cache_ = sm[2];
732 //sm[3]; // GMT offset
733 rev_author_cache_ = sm[4];
738 if (rev_author_cache_.empty())
740 "Could not retrieve revision info for " << version_ <<
741 " of " << getTarget(File));
745 void CVS::registrer(string const & msg)
747 doVCCommand("cvs -q add -m \"" + msg + "\" "
749 FileName(owner_->filePath()));
753 bool CVS::renameEnabled()
759 string CVS::rename(support::FileName const & newFile, string const & msg)
761 // CVS has no real rename command, so we create a poor mans version
762 support::FileName const oldFile(owner_->absFileName());
763 string ret = copy(newFile, msg);
766 string cmd = "cvs -q remove -m \"" + msg + "\" " +
767 quoteName(oldFile.onlyFileName());
768 FileName path(oldFile.onlyPath());
769 return doVCCommand(cmd, path) ? string() : ret;
773 bool CVS::copyEnabled()
779 string CVS::copy(support::FileName const & newFile, string const & msg)
781 // CVS has no real copy command, so we create a poor mans version
782 support::FileName const oldFile(owner_->absFileName());
783 if (!oldFile.copyTo(newFile))
785 FileName path(oldFile.onlyPath());
786 string relFile(to_utf8(newFile.relPath(path.absFileName())));
787 string cmd("cvs -q add -m \"" + msg + "\" " + quoteName(relFile));
788 return doVCCommand(cmd, path) ? string() : "CVS: Proceeded";
792 void CVS::getDiff(OperationMode opmode, FileName const & tmpf)
794 doVCCommandWithOutput("cvs diff " + getTarget(opmode),
795 FileName(owner_->filePath()), tmpf, false);
802 return doVCCommand("cvs -q edit " + getTarget(File),
803 FileName(owner_->filePath()));
810 return doVCCommand("cvs -q unedit " + getTarget(File),
811 FileName(owner_->filePath()));
815 int CVS::update(OperationMode opmode, FileName const & tmpf)
817 return doVCCommandWithOutput("cvs -q update "
819 FileName(owner_->filePath()), tmpf, false);
823 string CVS::scanLogFile(FileName const & f, string & status)
825 ifstream ifs(f.toFilesystemEncoding().c_str());
830 LYXERR(Debug::LYXVC, line << "\n");
832 status += line + "; ";
833 if (prefixIs(line, "C ")) {
843 LyXVC::CommandResult CVS::checkIn(string const & msg, string & log)
845 CvsStatus status = getStatus();
848 if (vcstatus != NOLOCKING)
850 return LyXVC::ErrorCommand;
851 log = "CVS: Proceeded";
852 return LyXVC::VCSuccess;
853 case LocallyModified:
855 int rc = doVCCommand("cvs -q commit -m \"" + msg + "\" "
857 FileName(owner_->filePath()));
859 return LyXVC::ErrorCommand;
860 log = "CVS: Proceeded";
861 return LyXVC::VCSuccess;
865 frontend::Alert::error(_("Revision control error."),
866 _("The repository version is newer then the current check out.\n"
867 "You have to update from repository first or revert your changes.")) ;
870 frontend::Alert::error(_("Revision control error."),
871 bformat(_("Bad status when checking in changes.\n"
876 return LyXVC::ErrorBefore;
880 bool CVS::isLocked() const
882 FileName fn(owner_->absFileName());
884 return !fn.isReadOnly();
888 bool CVS::checkInEnabled()
890 if (vcstatus != NOLOCKING)
897 bool CVS::isCheckInWithConfirmation()
899 CvsStatus status = getStatus();
900 return status == LocallyModified || status == LocallyAdded;
904 string CVS::checkOut()
906 if (vcstatus != NOLOCKING && edit())
908 FileName tmpf = FileName::tempName("lyxvcout");
910 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
914 int rc = update(File, tmpf);
916 string const res = scanLogFile(tmpf, log);
918 frontend::Alert::error(_("Revision control error."),
919 bformat(_("Error when updating from repository.\n"
920 "You have to manually resolve the conflicts NOW!\n'%1$s'.\n\n"
921 "After pressing OK, LyX will try to reopen the resolved document."),
922 from_local8bit(res)));
927 return rc ? string() : log.empty() ? "CVS: Proceeded" : "CVS: " + log;
931 bool CVS::checkOutEnabled()
933 if (vcstatus != NOLOCKING)
940 string CVS::repoUpdate()
942 FileName tmpf = FileName::tempName("lyxvcout");
944 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
948 getDiff(Directory, tmpf);
949 docstring res = tmpf.fileContents("UTF-8");
951 LYXERR(Debug::LYXVC, "Diff detected:\n" << res);
952 docstring const file = from_utf8(owner_->filePath());
953 docstring text = bformat(_("There were detected changes "
954 "in the working directory:\n%1$s\n\n"
955 "Possible file conflicts must be then resolved manually "
956 "or you will need to revert back to the repository version."), file);
957 int ret = frontend::Alert::prompt(_("Changes detected"),
958 text, 0, 1, _("&Continue"), _("&Abort"), _("View &Log ..."));
960 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + tmpf.absFileName()));
961 ret = frontend::Alert::prompt(_("Changes detected"),
962 text, 0, 1, _("&Continue"), _("&Abort"));
963 hideDialogs("file", 0);
971 int rc = update(Directory, tmpf);
972 res += "Update log:\n" + tmpf.fileContents("UTF-8");
973 LYXERR(Debug::LYXVC, res);
976 string sres = scanLogFile(tmpf, log);
978 docstring const file = owner_->fileName().displayName(20);
979 frontend::Alert::error(_("Revision control error."),
980 bformat(_("Error when updating document %1$s from repository.\n"
981 "You have to manually resolve the conflicts NOW!\n'%2$s'.\n\n"
982 "After pressing OK, LyX will try to reopen the resolved document."),
983 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 FileName tmpf = FileName::tempName("lyxvcrev_" + rev + "_");
1116 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1120 doVCCommandWithOutput("cvs update -p -r" + rev + " "
1122 FileName(owner_->filePath()), tmpf);
1123 if (tmpf.isFileEmpty())
1126 f = tmpf.absFileName();
1131 bool CVS::prepareFileRevisionEnabled()
1137 /////////////////////////////////////////////////////////////////////
1141 /////////////////////////////////////////////////////////////////////
1143 SVN::SVN(FileName const & m, Buffer * b) : VCS(b)
1145 // Here we know that the buffer file is either already in SVN or
1146 // about to be registered
1153 FileName const SVN::findFile(FileName const & file)
1155 // First we check the existence of repository meta data.
1156 if (!VCS::checkparentdirs(file, ".svn")) {
1157 LYXERR(Debug::LYXVC, "Cannot find SVN meta data for " << file);
1161 // Now we check the status of the file.
1162 FileName tmpf = FileName::tempName("lyxvcout");
1164 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1168 string const fname = onlyFileName(file.absFileName());
1169 LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under svn control for `" << fname << '\'');
1170 bool found = 0 == doVCCommandCall("svn info " + quoteName(fname)
1171 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1174 LYXERR(Debug::LYXVC, "SVN control: " << (found ? "enabled" : "disabled"));
1175 return found ? file : FileName();
1179 void SVN::scanMaster()
1181 // vcstatus code is somewhat superflous,
1182 // until we want to implement read-only toggle for svn.
1183 vcstatus = NOLOCKING;
1184 if (checkLockMode()) {
1188 vcstatus = UNLOCKED;
1193 bool SVN::checkLockMode()
1195 FileName tmpf = FileName::tempName("lyxvcout");
1197 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1201 LYXERR(Debug::LYXVC, "Detecting locking mode...");
1202 if (doVCCommandCall("svn proplist " + quoteName(onlyFileName(owner_->absFileName()))
1203 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1204 FileName(owner_->filePath())))
1207 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1211 while (ifs && !ret) {
1213 LYXERR(Debug::LYXVC, line);
1214 if (contains(line, "svn:needs-lock"))
1217 LYXERR(Debug::LYXVC, "Locking enabled: " << ret);
1225 bool SVN::isLocked() const
1227 FileName file(owner_->absFileName());
1229 return !file.isReadOnly();
1233 bool SVN::retrieve(FileName const & file)
1235 LYXERR(Debug::LYXVC, "LyXVC::SVN: retrieve.\n\t" << file);
1236 // The caller ensures that file does not exist, so no need to check that.
1237 return doVCCommandCall("svn update -q --non-interactive " + quoteName(file.onlyFileName()),
1238 file.onlyPath()) == 0;
1242 void SVN::registrer(string const & /*msg*/)
1244 doVCCommand("svn add -q " + quoteName(onlyFileName(owner_->absFileName())),
1245 FileName(owner_->filePath()));
1249 bool SVN::renameEnabled()
1255 string SVN::rename(support::FileName const & newFile, string const & msg)
1257 // svn move does not require a log message, since it does not commit.
1258 // In LyX we commit immediately afterwards, otherwise it could be
1259 // confusing to the user to have two uncommitted files.
1260 FileName path(owner_->filePath());
1261 string relFile(to_utf8(newFile.relPath(path.absFileName())));
1262 string cmd("svn move -q " + quoteName(onlyFileName(owner_->absFileName())) +
1263 ' ' + quoteName(relFile));
1264 if (doVCCommand(cmd, path)) {
1265 cmd = "svn revert -q " +
1266 quoteName(onlyFileName(owner_->absFileName())) + ' ' +
1268 doVCCommand(cmd, path);
1269 if (newFile.exists())
1270 newFile.removeFile();
1273 vector<support::FileName> f;
1274 f.push_back(owner_->fileName());
1275 f.push_back(newFile);
1277 if (checkIn(f, msg, log) != LyXVC::VCSuccess) {
1278 cmd = "svn revert -q " +
1279 quoteName(onlyFileName(owner_->absFileName())) + ' ' +
1281 doVCCommand(cmd, path);
1282 if (newFile.exists())
1283 newFile.removeFile();
1290 bool SVN::copyEnabled()
1296 string SVN::copy(support::FileName const & newFile, string const & msg)
1298 // svn copy does not require a log message, since it does not commit.
1299 // In LyX we commit immediately afterwards, otherwise it could be
1300 // confusing to the user to have an uncommitted file.
1301 FileName path(owner_->filePath());
1302 string relFile(to_utf8(newFile.relPath(path.absFileName())));
1303 string cmd("svn copy -q " + quoteName(onlyFileName(owner_->absFileName())) +
1304 ' ' + quoteName(relFile));
1305 if (doVCCommand(cmd, path))
1307 vector<support::FileName> f(1, newFile);
1309 if (checkIn(f, msg, log) == LyXVC::VCSuccess)
1315 LyXVC::CommandResult SVN::checkIn(string const & msg, string & log)
1317 vector<support::FileName> f(1, owner_->fileName());
1318 return checkIn(f, msg, log);
1322 LyXVC::CommandResult
1323 SVN::checkIn(vector<support::FileName> const & f, string const & msg, string & log)
1325 FileName tmpf = FileName::tempName("lyxvcout");
1327 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1328 log = N_("Error: Could not generate logfile.");
1329 return LyXVC::ErrorBefore;
1333 os << "svn commit -m \"" << msg << '"';
1334 for (size_t i = 0; i < f.size(); ++i)
1335 os << ' ' << quoteName(f[i].onlyFileName());
1336 os << " > " << quoteName(tmpf.toFilesystemEncoding());
1337 LyXVC::CommandResult ret =
1338 doVCCommand(os.str(), FileName(owner_->filePath())) ?
1339 LyXVC::ErrorCommand : LyXVC::VCSuccess;
1341 string res = scanLogFile(tmpf, log);
1343 frontend::Alert::error(_("Revision control error."),
1344 _("Error when committing to repository.\n"
1345 "You have to manually resolve the problem.\n"
1346 "LyX will reopen the document after you press OK."));
1347 ret = LyXVC::ErrorCommand;
1350 if (!fileLock(false, tmpf, log))
1351 ret = LyXVC::ErrorCommand;
1355 log.insert(0, "SVN: ");
1356 if (ret == LyXVC::VCSuccess && log.empty())
1357 log = "SVN: Proceeded";
1362 bool SVN::checkInEnabled()
1371 bool SVN::isCheckInWithConfirmation()
1373 // FIXME one day common getDiff and perhaps OpMode for all backends
1375 FileName tmpf = FileName::tempName("lyxvcout");
1377 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1381 doVCCommandCall("svn diff " + quoteName(owner_->absFileName())
1382 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1383 FileName(owner_->filePath()));
1385 docstring diff = tmpf.fileContents("UTF-8");
1395 // FIXME Correctly return code should be checked instead of this.
1396 // This would need another solution than just plain startscript.
1397 // Hint from Andre': QProcess::readAllStandardError()...
1398 string SVN::scanLogFile(FileName const & f, string & status)
1400 ifstream ifs(f.toFilesystemEncoding().c_str());
1405 LYXERR(Debug::LYXVC, line << "\n");
1407 status += line + "; ";
1408 if (prefixIs(line, "C ") || prefixIs(line, "CU ")
1409 || contains(line, "Commit failed")) {
1413 if (contains(line, "svn:needs-lock")) {
1423 bool SVN::fileLock(bool lock, FileName const & tmpf, string &status)
1425 if (!locked_mode_ || (isLocked() == lock))
1428 string const arg = lock ? "lock " : "unlock ";
1429 doVCCommand("svn "+ arg + quoteName(onlyFileName(owner_->absFileName()))
1430 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1431 FileName(owner_->filePath()));
1433 // Lock error messages go unfortunately on stderr and are unreachible this way.
1434 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1438 if (!line.empty()) status += line + "; ";
1442 if (isLocked() == lock)
1446 frontend::Alert::error(_("Revision control error."),
1447 _("Error while acquiring write lock.\n"
1448 "Another user is most probably editing\n"
1449 "the current document now!\n"
1450 "Also check the access to the repository."));
1452 frontend::Alert::error(_("Revision control error."),
1453 _("Error while releasing write lock.\n"
1454 "Check the access to the repository."));
1459 string SVN::checkOut()
1461 FileName tmpf = FileName::tempName("lyxvcout");
1463 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1464 return N_("Error: Could not generate logfile.");
1467 doVCCommand("svn update --non-interactive " + quoteName(onlyFileName(owner_->absFileName()))
1468 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1469 FileName(owner_->filePath()));
1472 string const res = scanLogFile(tmpf, log);
1474 frontend::Alert::error(_("Revision control error."),
1475 bformat(_("Error when updating from repository.\n"
1476 "You have to manually resolve the conflicts NOW!\n'%1$s'.\n\n"
1477 "After pressing OK, LyX will try to reopen the resolved document."),
1478 from_local8bit(res)));
1480 fileLock(true, tmpf, log);
1483 return log.empty() ? string() : "SVN: " + log;
1487 bool SVN::checkOutEnabled()
1496 string SVN::repoUpdate()
1498 FileName tmpf = FileName::tempName("lyxvcout");
1500 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1501 return N_("Error: Could not generate logfile.");
1504 doVCCommand("svn diff " + quoteName(owner_->filePath())
1505 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1506 FileName(owner_->filePath()));
1507 docstring res = tmpf.fileContents("UTF-8");
1509 LYXERR(Debug::LYXVC, "Diff detected:\n" << res);
1510 docstring const file = from_utf8(owner_->filePath());
1511 docstring text = bformat(_("There were detected changes "
1512 "in the working directory:\n%1$s\n\n"
1513 "In case of file conflict version of the local directory files "
1514 "will be preferred."
1515 "\n\nContinue?"), file);
1516 int ret = frontend::Alert::prompt(_("Changes detected"),
1517 text, 0, 1, _("&Yes"), _("&No"), _("View &Log ..."));
1519 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + tmpf.absFileName()));
1520 ret = frontend::Alert::prompt(_("Changes detected"),
1521 text, 0, 1, _("&Yes"), _("&No"));
1522 hideDialogs("file", 0);
1530 // Reverting looks too harsh, see bug #6255.
1531 // doVCCommand("svn revert -R " + quoteName(owner_->filePath())
1532 // + " > " + quoteName(tmpf.toFilesystemEncoding()),
1533 // FileName(owner_->filePath()));
1534 // res = "Revert log:\n" + tmpf.fileContents("UTF-8");
1535 doVCCommand("svn update --accept mine-full " + quoteName(owner_->filePath())
1536 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1537 FileName(owner_->filePath()));
1538 res += "Update log:\n" + tmpf.fileContents("UTF-8");
1540 LYXERR(Debug::LYXVC, res);
1542 return to_utf8(res);
1546 bool SVN::repoUpdateEnabled()
1552 string SVN::lockingToggle()
1554 FileName tmpf = FileName::tempName("lyxvcout");
1556 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1557 return N_("Error: Could not generate logfile.");
1560 int ret = doVCCommand("svn proplist " + quoteName(onlyFileName(owner_->absFileName()))
1561 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1562 FileName(owner_->filePath()));
1567 string res = scanLogFile(tmpf, log);
1568 bool locking = contains(res, "svn:needs-lock");
1570 ret = doVCCommand("svn propset svn:needs-lock ON "
1571 + quoteName(onlyFileName(owner_->absFileName()))
1572 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1573 FileName(owner_->filePath()));
1575 ret = doVCCommand("svn propdel svn:needs-lock "
1576 + quoteName(onlyFileName(owner_->absFileName()))
1577 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1578 FileName(owner_->filePath()));
1583 frontend::Alert::warning(_("SVN File Locking"),
1584 (locking ? _("Locking property unset.") : _("Locking property set.")) + "\n"
1585 + _("Do not forget to commit the locking property into the repository."),
1588 return string("SVN: ") + (locking ?
1589 N_("Locking property unset.") : N_("Locking property set."));
1593 bool SVN::lockingToggleEnabled()
1601 // Reverts to the version in SVN repository and
1602 // gets the updated version from the repository.
1603 string const fil = quoteName(onlyFileName(owner_->absFileName()));
1605 if (doVCCommand("svn revert -q " + fil,
1606 FileName(owner_->filePath())))
1608 owner_->markClean();
1613 bool SVN::isRevertWithConfirmation()
1615 //FIXME owner && diff
1620 void SVN::undoLast()
1622 // merge the current with the previous version
1623 // in a reverse patch kind of way, so that the
1624 // result is to revert the last changes.
1625 lyxerr << "Sorry, not implemented." << endl;
1629 bool SVN::undoLastEnabled()
1635 string SVN::revisionInfo(LyXVC::RevisionInfo const info)
1637 if (info == LyXVC::Tree) {
1638 if (rev_tree_cache_.empty())
1639 if (!getTreeRevisionInfo())
1640 rev_tree_cache_ = "?";
1641 if (rev_tree_cache_ == "?")
1644 return rev_tree_cache_;
1647 // fill the rest of the attributes for a single file
1648 if (rev_file_cache_.empty())
1649 if (!getFileRevisionInfo())
1650 rev_file_cache_ = "?";
1654 if (rev_file_cache_ == "?")
1656 return rev_file_cache_;
1658 return rev_author_cache_;
1660 return rev_date_cache_;
1662 return rev_time_cache_;
1671 bool SVN::getFileRevisionInfo()
1673 FileName tmpf = FileName::tempName("lyxvcout");
1675 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1679 doVCCommand("svn info --xml " + quoteName(onlyFileName(owner_->absFileName()))
1680 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1681 FileName(owner_->filePath()));
1686 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1694 LYXERR(Debug::LYXVC, line);
1695 if (prefixIs(line, "<commit"))
1697 if (c && prefixIs(line, " revision=\"") && suffixIs(line, "\">")) {
1698 string l1 = subst(line, "revision=\"", "");
1699 string l2 = trim(subst(l1, "\">", ""));
1701 rev_file_cache_ = rev = l2;
1703 if (c && prefixIs(line, "<author>") && suffixIs(line, "</author>")) {
1704 string l1 = subst(line, "<author>", "");
1705 string l2 = subst(l1, "</author>", "");
1706 rev_author_cache_ = l2;
1708 if (c && prefixIs(line, "<date>") && suffixIs(line, "</date>")) {
1709 string l1 = subst(line, "<date>", "");
1710 string l2 = subst(l1, "</date>", "");
1711 l2 = split(l2, l1, 'T');
1712 rev_date_cache_ = l1;
1713 l2 = split(l2, l1, '.');
1714 rev_time_cache_ = l1;
1720 return !rev.empty();
1724 bool SVN::getTreeRevisionInfo()
1726 FileName tmpf = FileName::tempName("lyxvcout");
1728 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1732 doVCCommand("svnversion -n . > " + quoteName(tmpf.toFilesystemEncoding()),
1733 FileName(owner_->filePath()));
1738 // only first line in case something bad happens.
1739 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1745 rev_tree_cache_ = line;
1746 return !line.empty();
1750 void SVN::getLog(FileName const & tmpf)
1752 doVCCommand("svn log " + quoteName(onlyFileName(owner_->absFileName()))
1753 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1754 FileName(owner_->filePath()));
1758 bool SVN::prepareFileRevision(string const & revis, string & f)
1760 if (!isStrInt(revis))
1763 int rev = convert<int>(revis);
1765 if (!getFileRevisionInfo())
1768 rev = convert<int>(rev_file_cache_);
1769 // go back for minus rev
1771 rev = rev + convert<int>(rev_file_cache_);
1776 string revname = convert<string>(rev);
1777 FileName tmpf = FileName::tempName("lyxvcrev_" + revname + "_");
1779 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1783 doVCCommand("svn cat -r " + revname + " "
1784 + quoteName(onlyFileName(owner_->absFileName()))
1785 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1786 FileName(owner_->filePath()));
1787 if (tmpf.isFileEmpty())
1790 f = tmpf.absFileName();
1795 bool SVN::prepareFileRevisionEnabled()
1802 bool SVN::toggleReadOnlyEnabled()
1808 /////////////////////////////////////////////////////////////////////
1812 /////////////////////////////////////////////////////////////////////
1814 GIT::GIT(FileName const & m, Buffer * b) : VCS(b)
1816 // Here we know that the buffer file is either already in GIT or
1817 // about to be registered
1823 FileName const GIT::findFile(FileName const & file)
1825 // First we check the existence of repository meta data.
1826 if (!VCS::checkparentdirs(file, ".git")) {
1827 LYXERR(Debug::LYXVC, "Cannot find GIT meta data for " << file);
1831 // Now we check the status of the file.
1832 FileName tmpf = FileName::tempName("lyxvcout");
1834 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1838 // --porcelain selects a format that is supposed to be stable across
1840 string const fname = onlyFileName(file.absFileName());
1841 LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under git control for `"
1843 bool found = 0 == doVCCommandCall("git status --porcelain " +
1844 quoteName(fname) + " > " +
1845 quoteName(tmpf.toFilesystemEncoding()),
1849 // The output is empty for file names NOT in repo.
1850 // The output contains a line starting with "??" for unknown
1851 // files, no line for known unmodified files and a line
1852 // starting with "M" or something else for modified/deleted
1854 if (tmpf.isFileEmpty())
1857 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1860 found = (test != "??");
1865 LYXERR(Debug::LYXVC, "GIT control: " << (found ? "enabled" : "disabled"));
1866 return found ? file : FileName();
1870 void GIT::scanMaster()
1872 // vcstatus code is somewhat superflous,
1873 // until we want to implement read-only toggle for git.
1874 vcstatus = NOLOCKING;
1878 bool GIT::retrieve(FileName const & file)
1880 LYXERR(Debug::LYXVC, "LyXVC::GIT: retrieve.\n\t" << file);
1881 // The caller ensures that file does not exist, so no need to check that.
1882 return doVCCommandCall("git checkout -q " + quoteName(file.onlyFileName()),
1883 file.onlyPath()) == 0;
1887 void GIT::registrer(string const & /*msg*/)
1889 doVCCommand("git add " + quoteName(onlyFileName(owner_->absFileName())),
1890 FileName(owner_->filePath()));
1894 bool GIT::renameEnabled()
1900 string GIT::rename(support::FileName const & newFile, string const & msg)
1902 // git mv does not require a log message, since it does not commit.
1903 // In LyX we commit immediately afterwards, otherwise it could be
1904 // confusing to the user to have two uncommitted files.
1905 FileName path(owner_->filePath());
1906 string relFile(to_utf8(newFile.relPath(path.absFileName())));
1907 string cmd("git mv " + quoteName(onlyFileName(owner_->absFileName())) +
1908 ' ' + quoteName(relFile));
1909 if (doVCCommand(cmd, path)) {
1910 cmd = "git checkout -q " +
1911 quoteName(onlyFileName(owner_->absFileName())) + ' ' +
1913 doVCCommand(cmd, path);
1914 if (newFile.exists())
1915 newFile.removeFile();
1918 vector<support::FileName> f;
1919 f.push_back(owner_->fileName());
1920 f.push_back(newFile);
1922 if (checkIn(f, msg, log) != LyXVC::VCSuccess) {
1923 cmd = "git checkout -q " +
1924 quoteName(onlyFileName(owner_->absFileName())) + ' ' +
1926 doVCCommand(cmd, path);
1927 if (newFile.exists())
1928 newFile.removeFile();
1935 bool GIT::copyEnabled()
1941 string GIT::copy(support::FileName const & /*newFile*/, string const & /*msg*/)
1943 // git does not support copy with history preservation
1948 LyXVC::CommandResult GIT::checkIn(string const & msg, string & log)
1950 vector<support::FileName> f(1, owner_->fileName());
1951 return checkIn(f, msg, log);
1955 LyXVC::CommandResult
1956 GIT::checkIn(vector<support::FileName> const & f, string const & msg, string & log)
1958 FileName tmpf = FileName::tempName("lyxvcout");
1960 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1961 log = N_("Error: Could not generate logfile.");
1962 return LyXVC::ErrorBefore;
1966 os << "git commit -m \"" << msg << '"';
1967 for (size_t i = 0; i < f.size(); ++i)
1968 os << ' ' << quoteName(f[i].onlyFileName());
1969 os << " > " << quoteName(tmpf.toFilesystemEncoding());
1970 LyXVC::CommandResult ret =
1971 doVCCommand(os.str(), FileName(owner_->filePath())) ?
1972 LyXVC::ErrorCommand : LyXVC::VCSuccess;
1974 string res = scanLogFile(tmpf, log);
1976 frontend::Alert::error(_("Revision control error."),
1977 _("Error when committing to repository.\n"
1978 "You have to manually resolve the problem.\n"
1979 "LyX will reopen the document after you press OK."));
1980 ret = LyXVC::ErrorCommand;
1985 log.insert(0, "GIT: ");
1986 if (ret == LyXVC::VCSuccess && log.empty())
1987 log = "GIT: Proceeded";
1992 bool GIT::checkInEnabled()
1998 bool GIT::isCheckInWithConfirmation()
2000 // FIXME one day common getDiff and perhaps OpMode for all backends
2002 FileName tmpf = FileName::tempName("lyxvcout");
2004 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
2008 doVCCommandCall("git diff " + quoteName(owner_->absFileName())
2009 + " > " + quoteName(tmpf.toFilesystemEncoding()),
2010 FileName(owner_->filePath()));
2012 docstring diff = tmpf.fileContents("UTF-8");
2022 // FIXME Correctly return code should be checked instead of this.
2023 // This would need another solution than just plain startscript.
2024 // Hint from Andre': QProcess::readAllStandardError()...
2025 string GIT::scanLogFile(FileName const & f, string & status)
2027 ifstream ifs(f.toFilesystemEncoding().c_str());
2032 LYXERR(Debug::LYXVC, line << "\n");
2034 status += line + "; ";
2035 if (prefixIs(line, "C ") || prefixIs(line, "CU ")
2036 || contains(line, "Commit failed")) {
2046 string GIT::checkOut()
2052 bool GIT::checkOutEnabled()
2058 string GIT::repoUpdate()
2064 bool GIT::repoUpdateEnabled()
2070 string GIT::lockingToggle()
2076 bool GIT::lockingToggleEnabled()
2084 // Reverts to the version in GIT repository and
2085 // gets the updated version from the repository.
2086 string const fil = quoteName(onlyFileName(owner_->absFileName()));
2088 if (doVCCommand("git checkout -q " + fil,
2089 FileName(owner_->filePath())))
2091 owner_->markClean();
2096 bool GIT::isRevertWithConfirmation()
2098 //FIXME owner && diff
2103 void GIT::undoLast()
2105 // merge the current with the previous version
2106 // in a reverse patch kind of way, so that the
2107 // result is to revert the last changes.
2108 lyxerr << "Sorry, not implemented." << endl;
2112 bool GIT::undoLastEnabled()
2118 string GIT::revisionInfo(LyXVC::RevisionInfo const info)
2120 if (info == LyXVC::Tree) {
2121 if (rev_tree_cache_.empty())
2122 if (!getTreeRevisionInfo())
2123 rev_tree_cache_ = "?";
2124 if (rev_tree_cache_ == "?")
2127 return rev_tree_cache_;
2130 // fill the rest of the attributes for a single file
2131 if (rev_file_cache_.empty())
2132 if (!getFileRevisionInfo())
2133 rev_file_cache_ = "?";
2137 if (rev_file_cache_ == "?")
2139 return rev_file_cache_;
2141 return rev_author_cache_;
2143 return rev_date_cache_;
2145 return rev_time_cache_;
2154 bool GIT::getFileRevisionInfo()
2156 FileName tmpf = FileName::tempName("lyxvcout");
2158 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
2162 doVCCommand("git log -n 1 --pretty=format:%H%n%an%n%ai " + quoteName(onlyFileName(owner_->absFileName()))
2163 + " > " + quoteName(tmpf.toFilesystemEncoding()),
2164 FileName(owner_->filePath()));
2169 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
2172 getline(ifs, rev_file_cache_);
2174 getline(ifs, rev_author_cache_);
2178 rev_time_cache_ = split(line, rev_date_cache_, ' ');
2183 return !rev_file_cache_.empty();
2187 bool GIT::getTreeRevisionInfo()
2189 FileName tmpf = FileName::tempName("lyxvcout");
2191 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
2195 doVCCommand("git describe --abbrev --dirty --long > " + quoteName(tmpf.toFilesystemEncoding()),
2196 FileName(owner_->filePath()));
2201 // only first line in case something bad happens.
2202 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
2203 getline(ifs, rev_tree_cache_);
2207 return !rev_tree_cache_.empty();
2211 void GIT::getLog(FileName const & tmpf)
2213 doVCCommand("git log " + quoteName(onlyFileName(owner_->absFileName()))
2214 + " > " + quoteName(tmpf.toFilesystemEncoding()),
2215 FileName(owner_->filePath()));
2219 //at this moment we don't accept revision SHA, but just number of revision steps back
2220 //GUI and infrastucture needs to be changed first
2221 bool GIT::prepareFileRevision(string const & revis, string & f)
2223 // anything positive means we got hash, not "0" or minus revision
2226 // hash is rarely number and should be long
2227 if (isStrInt(revis) && revis.length()<20)
2228 rev = convert<int>(revis);
2230 // revision and filename
2233 // go back for "minus" revisions
2235 pointer = "HEAD~" + convert<string>(-rev);
2242 FileName tmpf = FileName::tempName("lyxvcrev_" + revis + "_");
2244 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
2248 doVCCommand("git show " + pointer + "./"
2249 + quoteName(onlyFileName(owner_->absFileName()))
2250 + " > " + quoteName(tmpf.toFilesystemEncoding()),
2251 FileName(owner_->filePath()));
2252 if (tmpf.isFileEmpty())
2255 f = tmpf.absFileName();
2260 bool GIT::prepareFileRevisionEnabled()
2266 bool GIT::toggleReadOnlyEnabled()