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/Path.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, 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 /////////////////////////////////////////////////////////////////////
72 /////////////////////////////////////////////////////////////////////
74 RCS::RCS(FileName const & m)
81 FileName const RCS::findFile(FileName const & file)
83 // Check if *,v exists.
84 FileName tmp(file.absFileName() + ",v");
85 LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under rcs: " << tmp);
86 if (tmp.isReadableFile()) {
87 LYXERR(Debug::LYXVC, "Yes, " << file << " is under rcs.");
91 // Check if RCS/*,v exists.
92 tmp = FileName(addName(addPath(onlyPath(file.absFileName()), "RCS"), file.absFileName()) + ",v");
93 LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under rcs: " << tmp);
94 if (tmp.isReadableFile()) {
95 LYXERR(Debug::LYXVC, "Yes, " << file << " is under rcs.");
103 void RCS::retrieve(FileName const & file)
105 LYXERR(Debug::LYXVC, "LyXVC::RCS: retrieve.\n\t" << file);
106 doVCCommandCall("co -q -r " + quoteName(file.toFilesystemEncoding()),
111 void RCS::scanMaster()
116 LYXERR(Debug::LYXVC, "LyXVC::RCS: scanMaster: " << master_);
118 ifstream ifs(master_.toFilesystemEncoding().c_str());
121 bool read_enough = false;
123 while (!read_enough && ifs >> token) {
124 LYXERR(Debug::LYXVC, "LyXVC::scanMaster: current lex text: `"
129 else if (token == "head") {
133 tmv = rtrim(tmv, ";");
135 LYXERR(Debug::LYXVC, "LyXVC: version found to be " << tmv);
136 } else if (contains(token, "access")
137 || contains(token, "symbols")
138 || contains(token, "strict")) {
140 } else if (contains(token, "locks")) {
142 if (contains(token, ';')) {
143 locker_ = "Unlocked";
152 s1 = rtrim(tmpt, ";");
153 // tmp is now in the format <user>:<version>
154 s1 = split(s1, s2, ':');
155 // s2 is user, and s1 is version
156 if (s1 == version_) {
161 } while (!contains(tmpt, ';'));
163 } else if (token == "comment") {
164 // we don't need to read any further than this.
168 LYXERR(Debug::LYXVC, "LyXVC::scanMaster(): unexpected token");
174 void RCS::registrer(string const & msg)
176 string cmd = "ci -q -u -i -t-\"";
179 cmd += quoteName(onlyFileName(owner_->absFileName()));
180 doVCCommand(cmd, FileName(owner_->filePath()));
184 string RCS::checkIn(string const & msg)
186 int ret = doVCCommand("ci -q -u -m\"" + msg + "\" "
187 + quoteName(onlyFileName(owner_->absFileName())),
188 FileName(owner_->filePath()));
189 return ret ? string() : "RCS: Proceeded";
193 bool RCS::checkInEnabled()
195 return owner_ && !owner_->isReadonly();
199 bool RCS::isCheckInWithConfirmation()
201 // FIXME one day common getDiff for all backends
203 // if (getDiff(file, diff) && diff.empty())
206 FileName tmpf = FileName::tempName("lyxvcout");
208 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
212 doVCCommandCall("rcsdiff " + quoteName(owner_->absFileName())
213 + " > " + quoteName(tmpf.toFilesystemEncoding()),
214 FileName(owner_->filePath()));
216 if (tmpf.fileContents("UTF-8").empty())
223 string RCS::checkOut()
226 int ret = doVCCommand("co -q -l " + quoteName(onlyFileName(owner_->absFileName())),
227 FileName(owner_->filePath()));
228 return ret ? string() : "RCS: Proceeded";
232 bool RCS::checkOutEnabled()
234 return owner_ && owner_->isReadonly();
238 string RCS::repoUpdate()
240 lyxerr << "Sorry, not implemented." << endl;
245 bool RCS::repoUpdateEnabled()
251 string RCS::lockingToggle()
253 //FIXME this might be actually possible, study rcs -U, rcs -L.
254 //State should be easy to get inside scanMaster.
255 //It would fix #4370 and make rcs/svn usage even more closer.
256 lyxerr << "Sorry, not implemented." << endl;
261 bool RCS::lockingToggleEnabled()
269 doVCCommand("co -f -u" + version_ + " "
270 + quoteName(onlyFileName(owner_->absFileName())),
271 FileName(owner_->filePath()));
272 // We ignore changes and just reload!
277 bool RCS::isRevertWithConfirmation()
279 //FIXME owner && diff ?
286 LYXERR(Debug::LYXVC, "LyXVC: undoLast");
287 doVCCommand("rcs -o" + version_ + " "
288 + quoteName(onlyFileName(owner_->absFileName())),
289 FileName(owner_->filePath()));
293 bool RCS::undoLastEnabled()
299 void RCS::getLog(FileName const & tmpf)
301 doVCCommand("rlog " + quoteName(onlyFileName(owner_->absFileName()))
302 + " > " + quoteName(tmpf.toFilesystemEncoding()),
303 FileName(owner_->filePath()));
307 bool RCS::toggleReadOnlyEnabled()
309 // This got broken somewhere along lfuns dispatch reorganization.
310 // reloadBuffer would be needed after this, but thats problematic
311 // since we are inside Buffer::dispatch.
316 string RCS::revisionInfo(LyXVC::RevisionInfo const info)
318 if (info == LyXVC::File)
324 bool RCS::prepareFileRevision(string const &revis, string & f)
329 int back = convert<int>(rev);
330 // if positive use as the last number in the whole revision string
333 rsplit(version_, base , '.' );
334 rev = base + "." + rev;
338 // we care about the last number from revision string
339 // in case of backward indexing
342 cur = rsplit(version_, base , '.' );
345 int want = convert<int>(cur) + back;
349 rev = base + "." + convert<string>(want);
353 FileName tmpf = FileName::tempName("lyxvcrev_" + rev + "_");
355 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
356 return N_("Error: Could not generate logfile.");
359 doVCCommand("co -p" + rev + " "
360 + quoteName(onlyFileName(owner_->absFileName()))
361 + " > " + quoteName(tmpf.toFilesystemEncoding()),
362 FileName(owner_->filePath()));
363 if (tmpf.isFileEmpty())
366 f = tmpf.absFileName();
371 bool RCS::prepareFileRevisionEnabled()
377 /////////////////////////////////////////////////////////////////////
381 /////////////////////////////////////////////////////////////////////
383 CVS::CVS(FileName const & m, FileName const & f)
387 have_rev_info_ = false;
392 FileName const CVS::findFile(FileName const & file)
394 // First we look for the CVS/Entries in the same dir
395 // where we have file.
396 FileName const entries(onlyPath(file.absFileName()) + "/CVS/Entries");
397 string const tmpf = '/' + onlyFileName(file.absFileName()) + '/';
398 LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under cvs in `" << entries
399 << "' for `" << tmpf << '\'');
400 if (entries.isReadableFile()) {
401 // Ok we are at least in a CVS dir. Parse the CVS/Entries
402 // and see if we can find this file. We do a fast and
404 ifstream ifs(entries.toFilesystemEncoding().c_str());
406 while (getline(ifs, line)) {
407 LYXERR(Debug::LYXVC, "\tEntries: " << line);
408 if (contains(line, tmpf))
416 void CVS::scanMaster()
418 LYXERR(Debug::LYXVC, "LyXVC::CVS: scanMaster. \n Checking: " << master_);
419 // Ok now we do the real scan...
420 ifstream ifs(master_.toFilesystemEncoding().c_str());
421 string name = onlyFileName(file_.absFileName());
422 string tmpf = '/' + name + '/';
423 LYXERR(Debug::LYXVC, "\tlooking for `" << tmpf << '\'');
425 static regex const reg("/(.*)/(.*)/(.*)/(.*)/(.*)");
426 while (getline(ifs, line)) {
427 LYXERR(Debug::LYXVC, "\t line: " << line);
428 if (contains(line, tmpf)) {
429 // Ok extract the fields.
432 regex_match(line, sm, reg);
434 //sm[0]; // whole matched string
436 version_ = sm.str(2);
437 string const file_date = sm.str(3);
440 //sm[5]; // tag or tagdate
441 if (file_.isReadableFile()) {
442 time_t mod = file_.lastModified();
443 string mod_date = rtrim(asctime(gmtime(&mod)), "\n");
444 LYXERR(Debug::LYXVC, "Date in Entries: `" << file_date
445 << "'\nModification date of file: `" << mod_date << '\'');
446 if (file_.isReadOnly()) {
447 // readonly checkout is unlocked
450 FileName bdir(addPath(master_.onlyPath().absFileName(),"Base"));
451 FileName base(addName(bdir.absFileName(),name));
452 // if base version is existent "cvs edit" was used to lock
453 vcstatus = base.isReadableFile() ? LOCKED : NOLOCKING;
456 vcstatus = NOLOCKING;
464 string const CVS::getTarget(OperationMode opmode) const
468 // in client server mode CVS does not like full path operand for directory operation
469 // since LyX switches to the repo dir "." is good enough as target
472 return quoteName(onlyFileName(owner_->absFileName()));
478 docstring CVS::toString(CvsStatus status) const
482 return _("Up-to-date");
483 case LocallyModified:
484 return _("Locally Modified");
486 return _("Locally Added");
488 return _("Needs Merge");
490 return _("Needs Checkout");
492 return _("No CVS file");
494 return _("Cannot retrieve CVS status");
500 int CVS::doVCCommandWithOutput(string const & cmd, FileName const & path,
501 FileName const & output, bool reportError)
503 string redirection = output.empty() ? "" : " > " + quoteName(output.toFilesystemEncoding());
504 return doVCCommand(cmd + redirection, path, reportError);
508 int CVS::doVCCommandCallWithOutput(std::string const & cmd,
509 support::FileName const & path,
510 support::FileName const & output)
512 string redirection = output.empty() ? "" : " > " + quoteName(output.toFilesystemEncoding());
513 return doVCCommandCall(cmd + redirection, path);
517 CVS::CvsStatus CVS::getStatus()
519 FileName tmpf = FileName::tempName("lyxvcout");
521 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
525 if (doVCCommandCallWithOutput("cvs status " + getTarget(File),
526 FileName(owner_->filePath()), tmpf)) {
531 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
532 CvsStatus status = NoCvsFile;
537 LYXERR(Debug::LYXVC, line << "\n");
538 if (prefixIs(line, "File:")) {
539 if (contains(line, "Up-to-date"))
541 else if (contains(line, "Locally Modified"))
542 status = LocallyModified;
543 else if (contains(line, "Locally Added"))
544 status = LocallyAdded;
545 else if (contains(line, "Needs Merge"))
547 else if (contains(line, "Needs Checkout"))
548 status = NeedsCheckout;
555 void CVS::getRevisionInfo()
559 have_rev_info_ = true;
560 FileName tmpf = FileName::tempName("lyxvcout");
562 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
566 int rc = doVCCommandCallWithOutput("cvs log -r" + version_
567 + " " + getTarget(File),
568 FileName(owner_->filePath()), tmpf);
571 LYXERR(Debug::LYXVC, "cvs log failed with exit code " << rc);
575 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
576 static regex const reg("date: (.*) (.*) (.*); author: (.*); state: (.*);(.*)");
581 LYXERR(Debug::LYXVC, line << "\n");
582 if (prefixIs(line, "date:")) {
584 regex_match(line, sm, reg);
585 //sm[0]; // whole matched string
586 rev_date_cache_ = sm[1];
587 rev_time_cache_ = sm[2];
588 //sm[3]; // GMT offset
589 rev_author_cache_ = sm[4];
594 if (rev_author_cache_.empty())
596 "Could not retrieve revision info for " << version_ <<
597 " of " << getTarget(File));
601 void CVS::registrer(string const & msg)
603 doVCCommand("cvs -q add -m \"" + msg + "\" "
605 FileName(owner_->filePath()));
609 void CVS::getDiff(OperationMode opmode, FileName const & tmpf)
611 doVCCommandWithOutput("cvs diff " + getTarget(opmode),
612 FileName(owner_->filePath()), tmpf, false);
619 return doVCCommand("cvs -q edit " + getTarget(File),
620 FileName(owner_->filePath()));
627 return doVCCommand("cvs -q unedit " + getTarget(File),
628 FileName(owner_->filePath()));
632 int CVS::update(OperationMode opmode, FileName const & tmpf)
634 return doVCCommandWithOutput("cvs -q update "
636 FileName(owner_->filePath()), tmpf, false);
640 string CVS::scanLogFile(FileName const & f, string & status)
642 ifstream ifs(f.toFilesystemEncoding().c_str());
647 LYXERR(Debug::LYXVC, line << "\n");
649 status += line + "; ";
650 if (prefixIs(line, "C ")) {
660 string CVS::checkIn(string const & msg)
662 CvsStatus status = getStatus();
665 if (vcstatus != NOLOCKING)
667 return "CVS: Proceeded";
668 case LocallyModified:
670 int rc = doVCCommand("cvs -q commit -m \"" + msg + "\" "
672 FileName(owner_->filePath()));
673 return rc ? string() : "CVS: Proceeded";
677 frontend::Alert::error(_("Revision control error."),
678 _("The repository version is newer then the current check out.\n"
679 "You have to update from repository first or revert your changes.")) ;
682 frontend::Alert::error(_("Revision control error."),
683 bformat(_("Bad status when checking in changes.\n"
692 bool CVS::isLocked() const
694 FileName fn(owner_->absFileName());
696 return !fn.isReadOnly();
700 bool CVS::checkInEnabled()
702 if (vcstatus != NOLOCKING)
709 bool CVS::isCheckInWithConfirmation()
711 CvsStatus status = getStatus();
712 return status == LocallyModified || status == LocallyAdded;
716 string CVS::checkOut()
718 if (vcstatus != NOLOCKING && edit())
720 FileName tmpf = FileName::tempName("lyxvcout");
722 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
726 int rc = update(File, tmpf);
728 string const res = scanLogFile(tmpf, log);
730 frontend::Alert::error(_("Revision control error."),
731 bformat(_("Error when updating from repository.\n"
732 "You have to manually resolve the conflicts NOW!\n'%1$s'.\n\n"
733 "After pressing OK, LyX will try to reopen the resolved document."),
734 from_local8bit(res)));
739 return rc ? string() : log.empty() ? "CVS: Proceeded" : "CVS: " + log;
743 bool CVS::checkOutEnabled()
745 if (vcstatus != NOLOCKING)
752 string CVS::repoUpdate()
754 FileName tmpf = FileName::tempName("lyxvcout");
756 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
760 getDiff(Directory, tmpf);
761 docstring res = tmpf.fileContents("UTF-8");
763 LYXERR(Debug::LYXVC, "Diff detected:\n" << res);
764 docstring const file = from_utf8(owner_->filePath());
765 docstring text = bformat(_("There were detected changes "
766 "in the working directory:\n%1$s\n\n"
767 "In case of file conflict you have to resolve them "
768 "manually or revert to repository version later."), file);
769 int ret = frontend::Alert::prompt(_("Changes detected"),
770 text, 0, 1, _("&Continue"), _("&Abort"), _("View &Log ..."));
772 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + tmpf.absFileName()));
773 ret = frontend::Alert::prompt(_("Changes detected"),
774 text, 0, 1, _("&Continue"), _("&Abort"));
775 hideDialogs("file", 0);
783 int rc = update(Directory, tmpf);
784 res += "Update log:\n" + tmpf.fileContents("UTF-8");
785 LYXERR(Debug::LYXVC, res);
788 string sres = scanLogFile(tmpf, log);
790 docstring const file = owner_->fileName().displayName(20);
791 frontend::Alert::error(_("Revision control error."),
792 bformat(_("Error when updating document %1$s from repository.\n"
793 "You have to manually resolve the conflicts NOW!\n'%2$s'.\n\n"
794 "After pressing OK, LyX will try to reopen the resolved document."),
795 file, from_local8bit(sres)));
801 return rc ? string() : log.empty() ? "CVS: Proceeded" : "CVS: " + log;
805 bool CVS::repoUpdateEnabled()
811 string CVS::lockingToggle()
813 lyxerr << "Sorry, not implemented." << endl;
818 bool CVS::lockingToggleEnabled()
824 bool CVS::isRevertWithConfirmation()
826 CvsStatus status = getStatus();
827 return !owner_->isClean() || status == LocallyModified || status == NeedsMerge;
833 // Reverts to the version in CVS repository and
834 // gets the updated version from the repository.
835 CvsStatus status = getStatus();
838 if (vcstatus != NOLOCKING)
843 case LocallyModified: {
844 FileName f(owner_->absFileName());
846 update(File, FileName());
851 docstring const file = owner_->fileName().displayName(20);
852 frontend::Alert::error(_("Revision control error."),
853 bformat(_("The document %1$s is not in repository.\n"
854 "You have to check in the first revision before you can revert."),
859 docstring const file = owner_->fileName().displayName(20);
860 frontend::Alert::error(_("Revision control error."),
861 bformat(_("Cannot revert document %1$s to repository version.\n"
862 "The status '%2$s' is unexpected."),
863 file, toString(status)));
872 // merge the current with the previous version
873 // in a reverse patch kind of way, so that the
874 // result is to revert the last changes.
875 lyxerr << "Sorry, not implemented." << endl;
879 bool CVS::undoLastEnabled()
885 void CVS::getLog(FileName const & tmpf)
887 doVCCommandWithOutput("cvs log " + getTarget(File),
888 FileName(owner_->filePath()),
893 bool CVS::toggleReadOnlyEnabled()
899 string CVS::revisionInfo(LyXVC::RevisionInfo const info)
901 if (!version_.empty()) {
907 return rev_author_cache_;
909 return rev_date_cache_;
911 return rev_time_cache_;
919 bool CVS::prepareFileRevision(string const &, string &)
925 bool CVS::prepareFileRevisionEnabled()
931 /////////////////////////////////////////////////////////////////////
935 /////////////////////////////////////////////////////////////////////
937 SVN::SVN(FileName const & m, FileName const & f)
947 FileName const SVN::findFile(FileName const & file)
949 // First we look for the .svn/entries in the same dir
950 // where we have file.
951 FileName const entries(onlyPath(file.absFileName()) + "/.svn/entries");
952 string const tmpf = onlyFileName(file.absFileName());
953 LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under svn in `" << entries
954 << "' for `" << tmpf << '\'');
955 if (entries.isReadableFile()) {
956 // Ok we are at least in a SVN dir. Parse the .svn/entries
957 // and see if we can find this file. We do a fast and
959 ifstream ifs(entries.toFilesystemEncoding().c_str());
960 string line, oldline;
961 while (getline(ifs, line)) {
962 if (line == "dir" || line == "file")
963 LYXERR(Debug::LYXVC, "\tEntries: " << oldline);
964 if (oldline == tmpf && line == "file")
973 void SVN::scanMaster()
975 // vcstatus code is somewhat superflous, until we want
976 // to implement read-only toggle for svn.
977 vcstatus = NOLOCKING;
978 if (checkLockMode()) {
988 bool SVN::checkLockMode()
990 FileName tmpf = FileName::tempName("lyxvcout");
992 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
993 return N_("Error: Could not generate logfile.");
996 LYXERR(Debug::LYXVC, "Detecting locking mode...");
997 if (doVCCommandCall("svn proplist " + quoteName(file_.onlyFileName())
998 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1002 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1008 LYXERR(Debug::LYXVC, line);
1009 if (contains(line, "svn:needs-lock"))
1012 LYXERR(Debug::LYXVC, "Locking enabled: " << ret);
1020 bool SVN::isLocked() const
1023 return !file_.isReadOnly();
1027 void SVN::registrer(string const & /*msg*/)
1029 doVCCommand("svn add -q " + quoteName(onlyFileName(owner_->absFileName())),
1030 FileName(owner_->filePath()));
1034 string SVN::checkIn(string const & msg)
1036 FileName tmpf = FileName::tempName("lyxvcout");
1038 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1039 return N_("Error: Could not generate logfile.");
1042 doVCCommand("svn commit -m \"" + msg + "\" "
1043 + quoteName(onlyFileName(owner_->absFileName()))
1044 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1045 FileName(owner_->filePath()));
1048 string res = scanLogFile(tmpf, log);
1050 frontend::Alert::error(_("Revision control error."),
1051 _("Error when committing to repository.\n"
1052 "You have to manually resolve the problem.\n"
1053 "LyX will reopen the document after you press OK."));
1055 fileLock(false, tmpf, log);
1058 return log.empty() ? string() : "SVN: " + log;
1062 bool SVN::checkInEnabled()
1071 bool SVN::isCheckInWithConfirmation()
1078 // FIXME Correctly return code should be checked instead of this.
1079 // This would need another solution than just plain startscript.
1080 // Hint from Andre': QProcess::readAllStandardError()...
1081 string SVN::scanLogFile(FileName const & f, string & status)
1083 ifstream ifs(f.toFilesystemEncoding().c_str());
1088 LYXERR(Debug::LYXVC, line << "\n");
1090 status += line + "; ";
1091 if (prefixIs(line, "C ") || prefixIs(line, "CU ")
1092 || contains(line, "Commit failed")) {
1096 if (contains(line, "svn:needs-lock")) {
1106 void SVN::fileLock(bool lock, FileName const & tmpf, string &status)
1108 if (!locked_mode_ || (isLocked() == lock))
1111 string const arg = lock ? "lock " : "unlock ";
1112 doVCCommand("svn "+ arg + quoteName(onlyFileName(owner_->absFileName()))
1113 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1114 FileName(owner_->filePath()));
1116 // Lock error messages go unfortunately on stderr and are unreachible this way.
1117 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1121 if (!line.empty()) status += line + "; ";
1125 if (!isLocked() && lock)
1126 frontend::Alert::error(_("Revision control error."),
1127 _("Error while acquiring write lock.\n"
1128 "Another user is most probably editing\n"
1129 "the current document now!\n"
1130 "Also check the access to the repository."));
1131 if (isLocked() && !lock)
1132 frontend::Alert::error(_("Revision control error."),
1133 _("Error while releasing write lock.\n"
1134 "Check the access to the repository."));
1138 string SVN::checkOut()
1140 FileName tmpf = FileName::tempName("lyxvcout");
1142 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1143 return N_("Error: Could not generate logfile.");
1146 doVCCommand("svn update --non-interactive " + quoteName(onlyFileName(owner_->absFileName()))
1147 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1148 FileName(owner_->filePath()));
1151 string const res = scanLogFile(tmpf, log);
1153 frontend::Alert::error(_("Revision control error."),
1154 bformat(_("Error when updating from repository.\n"
1155 "You have to manually resolve the conflicts NOW!\n'%1$s'.\n\n"
1156 "After pressing OK, LyX will try to reopen the resolved document."),
1157 from_local8bit(res)));
1159 fileLock(true, tmpf, log);
1162 return log.empty() ? string() : "SVN: " + log;
1166 bool SVN::checkOutEnabled()
1175 string SVN::repoUpdate()
1177 FileName tmpf = FileName::tempName("lyxvcout");
1179 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1180 return N_("Error: Could not generate logfile.");
1183 doVCCommand("svn diff " + quoteName(owner_->filePath())
1184 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1185 FileName(owner_->filePath()));
1186 docstring res = tmpf.fileContents("UTF-8");
1188 LYXERR(Debug::LYXVC, "Diff detected:\n" << res);
1189 docstring const file = from_utf8(owner_->filePath());
1190 docstring text = bformat(_("There were detected changes "
1191 "in the working directory:\n%1$s\n\n"
1192 "In case of file conflict version of the local directory files "
1193 "will be preferred."
1194 "\n\nContinue?"), file);
1195 int ret = frontend::Alert::prompt(_("Changes detected"),
1196 text, 0, 1, _("&Yes"), _("&No"), _("View &Log ..."));
1198 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + tmpf.absFileName()));
1199 ret = frontend::Alert::prompt(_("Changes detected"),
1200 text, 0, 1, _("&Yes"), _("&No"));
1201 hideDialogs("file", 0);
1209 // Reverting looks too harsh, see bug #6255.
1210 // doVCCommand("svn revert -R " + quoteName(owner_->filePath())
1211 // + " > " + quoteName(tmpf.toFilesystemEncoding()),
1212 // FileName(owner_->filePath()));
1213 // res = "Revert log:\n" + tmpf.fileContents("UTF-8");
1214 doVCCommand("svn update --accept mine-full " + quoteName(owner_->filePath())
1215 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1216 FileName(owner_->filePath()));
1217 res += "Update log:\n" + tmpf.fileContents("UTF-8");
1219 LYXERR(Debug::LYXVC, res);
1221 return to_utf8(res);
1225 bool SVN::repoUpdateEnabled()
1231 string SVN::lockingToggle()
1233 FileName tmpf = FileName::tempName("lyxvcout");
1235 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1236 return N_("Error: Could not generate logfile.");
1239 int ret = doVCCommand("svn proplist " + quoteName(onlyFileName(owner_->absFileName()))
1240 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1241 FileName(owner_->filePath()));
1246 string res = scanLogFile(tmpf, log);
1247 bool locking = contains(res, "svn:needs-lock");
1249 ret = doVCCommand("svn propset svn:needs-lock ON "
1250 + quoteName(onlyFileName(owner_->absFileName()))
1251 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1252 FileName(owner_->filePath()));
1254 ret = doVCCommand("svn propdel svn:needs-lock "
1255 + quoteName(onlyFileName(owner_->absFileName()))
1256 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1257 FileName(owner_->filePath()));
1262 frontend::Alert::warning(_("VCN File Locking"),
1263 (locking ? _("Locking property unset.") : _("Locking property set.")) + "\n"
1264 + _("Do not forget to commit the locking property into the repository."),
1267 return string("SVN: ") + N_("Locking property set.");
1271 bool SVN::lockingToggleEnabled()
1279 // Reverts to the version in SVN repository and
1280 // gets the updated version from the repository.
1281 string const fil = quoteName(onlyFileName(owner_->absFileName()));
1283 doVCCommand("svn revert -q " + fil,
1284 FileName(owner_->filePath()));
1285 owner_->markClean();
1289 bool SVN::isRevertWithConfirmation()
1291 //FIXME owner && diff
1296 void SVN::undoLast()
1298 // merge the current with the previous version
1299 // in a reverse patch kind of way, so that the
1300 // result is to revert the last changes.
1301 lyxerr << "Sorry, not implemented." << endl;
1305 bool SVN::undoLastEnabled()
1311 string SVN::revisionInfo(LyXVC::RevisionInfo const info)
1313 if (info == LyXVC::Tree) {
1314 if (rev_tree_cache_.empty())
1315 if (!getTreeRevisionInfo())
1316 rev_tree_cache_ = "?";
1317 if (rev_tree_cache_ == "?")
1320 return rev_tree_cache_;
1323 // fill the rest of the attributes for a single file
1324 if (rev_file_cache_.empty())
1325 if (!getFileRevisionInfo())
1326 rev_file_cache_ = "?";
1330 if (rev_file_cache_ == "?")
1332 return rev_file_cache_;
1334 return rev_author_cache_;
1336 return rev_date_cache_;
1338 return rev_time_cache_;
1347 bool SVN::getFileRevisionInfo()
1349 FileName tmpf = FileName::tempName("lyxvcout");
1351 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1352 return N_("Error: Could not generate logfile.");
1355 doVCCommand("svn info --xml " + quoteName(onlyFileName(owner_->absFileName()))
1356 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1357 FileName(owner_->filePath()));
1362 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1370 LYXERR(Debug::LYXVC, line);
1371 if (prefixIs(line, "<commit"))
1373 if (c && prefixIs(line, " revision=\"") && suffixIs(line, "\">")) {
1374 string l1 = subst(line, "revision=\"", "");
1375 string l2 = trim(subst(l1, "\">", ""));
1377 rev_file_cache_ = rev = l2;
1379 if (c && prefixIs(line, "<author>") && suffixIs(line, "</author>")) {
1380 string l1 = subst(line, "<author>", "");
1381 string l2 = subst(l1, "</author>", "");
1382 rev_author_cache_ = l2;
1384 if (c && prefixIs(line, "<date>") && suffixIs(line, "</date>")) {
1385 string l1 = subst(line, "<date>", "");
1386 string l2 = subst(l1, "</date>", "");
1387 l2 = split(l2, l1, 'T');
1388 rev_date_cache_ = l1;
1389 l2 = split(l2, l1, '.');
1390 rev_time_cache_ = l1;
1396 return !rev.empty();
1400 bool SVN::getTreeRevisionInfo()
1402 FileName tmpf = FileName::tempName("lyxvcout");
1404 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1405 return N_("Error: Could not generate logfile.");
1408 doVCCommand("svnversion -n . > " + quoteName(tmpf.toFilesystemEncoding()),
1409 FileName(owner_->filePath()));
1414 // only first line in case something bad happens.
1415 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1421 rev_tree_cache_ = line;
1422 return !line.empty();
1426 void SVN::getLog(FileName const & tmpf)
1428 doVCCommand("svn log " + quoteName(onlyFileName(owner_->absFileName()))
1429 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1430 FileName(owner_->filePath()));
1434 bool SVN::prepareFileRevision(string const & revis, string & f)
1436 if (!isStrInt(revis))
1439 int rev = convert<int>(revis);
1441 if (!getFileRevisionInfo())
1444 rev = convert<int>(rev_file_cache_);
1445 // go back for minus rev
1447 rev = rev + convert<int>(rev_file_cache_);
1452 string revname = convert<string>(rev);
1453 FileName tmpf = FileName::tempName("lyxvcrev_" + revname + "_");
1455 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1456 return N_("Error: Could not generate logfile.");
1459 doVCCommand("svn cat -r " + revname + " "
1460 + quoteName(onlyFileName(owner_->absFileName()))
1461 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1462 FileName(owner_->filePath()));
1463 if (tmpf.isFileEmpty())
1466 f = tmpf.absFileName();
1471 bool SVN::prepareFileRevisionEnabled()
1478 bool SVN::toggleReadOnlyEnabled()