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();
198 bool RCS::isCheckInWithConfirmation()
205 string RCS::checkOut()
208 int ret = doVCCommand("co -q -l " + quoteName(onlyFileName(owner_->absFileName())),
209 FileName(owner_->filePath()));
210 return ret ? string() : "RCS: Proceeded";
214 bool RCS::checkOutEnabled()
216 return owner_ && owner_->isReadonly();
220 string RCS::repoUpdate()
222 lyxerr << "Sorry, not implemented." << endl;
227 bool RCS::repoUpdateEnabled()
233 string RCS::lockingToggle()
235 //FIXME this might be actually possible, study rcs -U, rcs -L.
236 //State should be easy to get inside scanMaster.
237 //It would fix #4370 and make rcs/svn usage even more closer.
238 lyxerr << "Sorry, not implemented." << endl;
243 bool RCS::lockingToggleEnabled()
251 doVCCommand("co -f -u" + version_ + " "
252 + quoteName(onlyFileName(owner_->absFileName())),
253 FileName(owner_->filePath()));
254 // We ignore changes and just reload!
259 bool RCS::isRevertWithConfirmation()
261 //FIXME owner && diff ?
268 LYXERR(Debug::LYXVC, "LyXVC: undoLast");
269 doVCCommand("rcs -o" + version_ + " "
270 + quoteName(onlyFileName(owner_->absFileName())),
271 FileName(owner_->filePath()));
275 bool RCS::undoLastEnabled()
281 void RCS::getLog(FileName const & tmpf)
283 doVCCommand("rlog " + quoteName(onlyFileName(owner_->absFileName()))
284 + " > " + quoteName(tmpf.toFilesystemEncoding()),
285 FileName(owner_->filePath()));
289 bool RCS::toggleReadOnlyEnabled()
291 // This got broken somewhere along lfuns dispatch reorganization.
292 // reloadBuffer would be needed after this, but thats problematic
293 // since we are inside Buffer::dispatch.
298 string RCS::revisionInfo(LyXVC::RevisionInfo const info)
300 if (info == LyXVC::File)
306 bool RCS::prepareFileRevision(string const &revis, string & f)
311 int back = convert<int>(rev);
312 // if positive use as the last number in the whole revision string
315 rsplit(version_, base , '.' );
316 rev = base + "." + rev;
320 // we care about the last number from revision string
321 // in case of backward indexing
324 cur = rsplit(version_, base , '.' );
327 int want = convert<int>(cur) + back;
331 rev = base + "." + convert<string>(want);
335 FileName tmpf = FileName::tempName("lyxvcrev_" + rev + "_");
337 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
338 return N_("Error: Could not generate logfile.");
341 doVCCommand("co -p" + rev + " "
342 + quoteName(onlyFileName(owner_->absFileName()))
343 + " > " + quoteName(tmpf.toFilesystemEncoding()),
344 FileName(owner_->filePath()));
345 if (tmpf.isFileEmpty())
348 f = tmpf.absFileName();
353 bool RCS::prepareFileRevisionEnabled()
359 /////////////////////////////////////////////////////////////////////
363 /////////////////////////////////////////////////////////////////////
365 CVS::CVS(FileName const & m, FileName const & f)
373 FileName const CVS::findFile(FileName const & file)
375 // First we look for the CVS/Entries in the same dir
376 // where we have file.
377 FileName const entries(onlyPath(file.absFileName()) + "/CVS/Entries");
378 string const tmpf = '/' + onlyFileName(file.absFileName()) + '/';
379 LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under cvs in `" << entries
380 << "' for `" << tmpf << '\'');
381 if (entries.isReadableFile()) {
382 // Ok we are at least in a CVS dir. Parse the CVS/Entries
383 // and see if we can find this file. We do a fast and
385 ifstream ifs(entries.toFilesystemEncoding().c_str());
387 while (getline(ifs, line)) {
388 LYXERR(Debug::LYXVC, "\tEntries: " << line);
389 if (contains(line, tmpf))
397 void CVS::scanMaster()
399 LYXERR(Debug::LYXVC, "LyXVC::CVS: scanMaster. \n Checking: " << master_);
400 // Ok now we do the real scan...
401 ifstream ifs(master_.toFilesystemEncoding().c_str());
402 string name = onlyFileName(file_.absFileName());
403 string tmpf = '/' + name + '/';
404 LYXERR(Debug::LYXVC, "\tlooking for `" << tmpf << '\'');
406 static regex const reg("/(.*)/(.*)/(.*)/(.*)/(.*)");
407 while (getline(ifs, line)) {
408 LYXERR(Debug::LYXVC, "\t line: " << line);
409 if (contains(line, tmpf)) {
410 // Ok extract the fields.
413 regex_match(line, sm, reg);
415 //sm[0]; // whole matched string
417 version_ = sm.str(2);
418 string const file_date = sm.str(3);
421 //sm[5]; // tag or tagdate
422 if (file_.isReadableFile()) {
423 time_t mod = file_.lastModified();
424 string mod_date = rtrim(asctime(gmtime(&mod)), "\n");
425 LYXERR(Debug::LYXVC, "Date in Entries: `" << file_date
426 << "'\nModification date of file: `" << mod_date << '\'');
427 if (file_.isReadOnly()) {
428 // readonly checkout is unlocked
431 FileName bdir(addPath(master_.onlyPath().absFileName(),"Base"));
432 FileName base(addName(bdir.absFileName(),name));
433 // if base version is existent "cvs edit" was used to lock
434 vcstatus = base.isReadableFile() ? LOCKED : NOLOCKING;
437 vcstatus = NOLOCKING;
445 string const CVS::getTarget(OperationMode opmode) const
449 // in client server mode CVS does not like full path operand for directory operation
450 // since LyX switches to the repo dir "." is good enough as target
453 return quoteName(onlyFileName(owner_->absFileName()));
459 docstring CVS::toString(CvsStatus status) const
463 return _("Up-to-date");
464 case LocallyModified:
465 return _("Locally Modified");
467 return _("Locally Added");
469 return _("Needs Merge");
471 return _("Needs Checkout");
473 return _("No CVS file");
475 return _("Cannot retrieve CVS status");
481 CVS::CvsStatus CVS::getStatus()
483 FileName tmpf = FileName::tempName("lyxvcout");
485 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
489 if (doVCCommand("cvs status " + getTarget(File)
490 + " > " + quoteName(tmpf.toFilesystemEncoding()),
491 FileName(owner_->filePath()))) {
496 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
497 CvsStatus status = NoCvsFile;
502 LYXERR(Debug::LYXVC, line << "\n");
503 if (prefixIs(line, "File:")) {
504 if (contains(line, "Up-to-date"))
506 else if (contains(line, "Locally Modified"))
507 status = LocallyModified;
508 else if (contains(line, "Locally Added"))
509 status = LocallyAdded;
510 else if (contains(line, "Needs Merge"))
512 else if (contains(line, "Needs Checkout"))
513 status = NeedsCheckout;
521 void CVS::registrer(string const & msg)
523 doVCCommand("cvs -q add -m \"" + msg + "\" "
525 FileName(owner_->filePath()));
529 void CVS::getDiff(OperationMode opmode, FileName const & tmpf)
531 doVCCommand("cvs diff " + getTarget(opmode)
532 + " > " + quoteName(tmpf.toFilesystemEncoding()),
533 FileName(owner_->filePath()), false);
540 return doVCCommand("cvs -q edit " + getTarget(File),
541 FileName(owner_->filePath()));
548 return doVCCommand("cvs -q unedit " + getTarget(File),
549 FileName(owner_->filePath()));
553 int CVS::update(OperationMode opmode, FileName const & tmpf)
555 string const redirection = tmpf.empty() ? ""
556 : " > " + quoteName(tmpf.toFilesystemEncoding());
558 return doVCCommand("cvs -q update "
559 + getTarget(opmode) + redirection,
560 FileName(owner_->filePath()));
564 string CVS::scanLogFile(FileName const & f, string & status)
566 ifstream ifs(f.toFilesystemEncoding().c_str());
571 LYXERR(Debug::LYXVC, line << "\n");
573 status += line + "; ";
574 if (prefixIs(line, "C ")) {
584 string CVS::checkIn(string const & msg)
586 CvsStatus status = getStatus();
589 if (vcstatus != NOLOCKING)
591 return "CVS: Proceeded";
592 case LocallyModified:
594 int rc = doVCCommand("cvs -q commit -m \"" + msg + "\" "
596 FileName(owner_->filePath()));
597 return rc ? string() : "CVS: Proceeded";
601 frontend::Alert::error(_("Revision control error."),
602 _("The repository version is newer then the current check out.\n"
603 "You have to update from repository first or revert your changes.")) ;
606 frontend::Alert::error(_("Revision control error."),
607 bformat(_("Bad status when checking in changes.\n"
616 bool CVS::isLocked() const
618 FileName fn(owner_->absFileName());
620 return !fn.isReadOnly();
624 bool CVS::checkInEnabled()
626 if (vcstatus != NOLOCKING)
633 bool CVS::isCheckInWithConfirmation()
635 CvsStatus status = getStatus();
636 return status == LocallyModified || status == LocallyAdded;
640 string CVS::checkOut()
642 if (vcstatus != NOLOCKING && edit())
644 FileName tmpf = FileName::tempName("lyxvcout");
646 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
650 int rc = update(File, tmpf);
652 string const res = scanLogFile(tmpf, log);
654 frontend::Alert::error(_("Revision control error."),
655 bformat(_("Error when updating from repository.\n"
656 "You have to manually resolve the conflicts NOW!\n'%1$s'.\n\n"
657 "After pressing OK, LyX will try to reopen the resolved document."),
658 from_local8bit(res)));
661 return rc ? string() : log.empty() ? "CVS: Proceeded" : "CVS: " + log;
665 bool CVS::checkOutEnabled()
667 if (vcstatus != NOLOCKING)
674 string CVS::repoUpdate()
676 FileName tmpf = FileName::tempName("lyxvcout");
678 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
682 getDiff(Directory, tmpf);
683 docstring res = tmpf.fileContents("UTF-8");
685 LYXERR(Debug::LYXVC, "Diff detected:\n" << res);
686 docstring const file = from_utf8(owner_->filePath());
687 docstring text = bformat(_("There were detected changes "
688 "in the working directory:\n%1$s\n\n"
689 "In case of file conflict you have to resolve them "
690 "manually or revert to repository version later."), file);
691 int ret = frontend::Alert::prompt(_("Changes detected"),
692 text, 0, 1, _("&Continue"), _("&Abort"), _("View &Log ..."));
694 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + tmpf.absFileName()));
695 ret = frontend::Alert::prompt(_("Changes detected"),
696 text, 0, 1, _("&Continue"), _("&Abort"));
697 hideDialogs("file", 0);
705 int rc = update(Directory, tmpf);
706 res += "Update log:\n" + tmpf.fileContents("UTF-8");
709 LYXERR(Debug::LYXVC, res);
710 return rc ? string() : "CVS: Proceeded" ;
714 bool CVS::repoUpdateEnabled()
720 string CVS::lockingToggle()
722 lyxerr << "Sorry, not implemented." << endl;
727 bool CVS::lockingToggleEnabled()
733 bool CVS::isRevertWithConfirmation()
735 CvsStatus status = getStatus();
736 return !owner_->isClean() || status == LocallyModified || status == NeedsMerge;
742 // Reverts to the version in CVS repository and
743 // gets the updated version from the repository.
744 CvsStatus status = getStatus();
747 if (vcstatus != NOLOCKING)
752 case LocallyModified: {
753 FileName f(owner_->absFileName());
755 update(File, FileName());
760 docstring const file = owner_->fileName().displayName(20);
761 frontend::Alert::error(_("Revision control error."),
762 bformat(_("The document %1$s is not in repository.\n"
763 "You have to check in the first revision before you can revert."),
768 docstring const file = owner_->fileName().displayName(20);
769 frontend::Alert::error(_("Revision control error."),
770 bformat(_("Cannot revert document %1$s to repository version.\n"
771 "The status '%2$s' is unexpected."),
772 file, toString(status)));
781 // merge the current with the previous version
782 // in a reverse patch kind of way, so that the
783 // result is to revert the last changes.
784 lyxerr << "Sorry, not implemented." << endl;
788 bool CVS::undoLastEnabled()
794 void CVS::getLog(FileName const & tmpf)
796 doVCCommand("cvs log " + getTarget(File)
797 + " > " + quoteName(tmpf.toFilesystemEncoding()),
798 FileName(owner_->filePath()));
802 bool CVS::toggleReadOnlyEnabled()
808 string CVS::revisionInfo(LyXVC::RevisionInfo const info)
810 if (info == LyXVC::File)
816 bool CVS::prepareFileRevision(string const &, string &)
822 bool CVS::prepareFileRevisionEnabled()
828 /////////////////////////////////////////////////////////////////////
832 /////////////////////////////////////////////////////////////////////
834 SVN::SVN(FileName const & m, FileName const & f)
844 FileName const SVN::findFile(FileName const & file)
846 // First we look for the .svn/entries in the same dir
847 // where we have file.
848 FileName const entries(onlyPath(file.absFileName()) + "/.svn/entries");
849 string const tmpf = onlyFileName(file.absFileName());
850 LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under svn in `" << entries
851 << "' for `" << tmpf << '\'');
852 if (entries.isReadableFile()) {
853 // Ok we are at least in a SVN dir. Parse the .svn/entries
854 // and see if we can find this file. We do a fast and
856 ifstream ifs(entries.toFilesystemEncoding().c_str());
857 string line, oldline;
858 while (getline(ifs, line)) {
859 if (line == "dir" || line == "file")
860 LYXERR(Debug::LYXVC, "\tEntries: " << oldline);
861 if (oldline == tmpf && line == "file")
870 void SVN::scanMaster()
872 // vcstatus code is somewhat superflous, until we want
873 // to implement read-only toggle for svn.
874 vcstatus = NOLOCKING;
875 if (checkLockMode()) {
885 bool SVN::checkLockMode()
887 FileName tmpf = FileName::tempName("lyxvcout");
889 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
890 return N_("Error: Could not generate logfile.");
893 LYXERR(Debug::LYXVC, "Detecting locking mode...");
894 if (doVCCommandCall("svn proplist " + quoteName(file_.onlyFileName())
895 + " > " + quoteName(tmpf.toFilesystemEncoding()),
899 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
905 LYXERR(Debug::LYXVC, line);
906 if (contains(line, "svn:needs-lock"))
909 LYXERR(Debug::LYXVC, "Locking enabled: " << ret);
917 bool SVN::isLocked() const
920 return !file_.isReadOnly();
924 void SVN::registrer(string const & /*msg*/)
926 doVCCommand("svn add -q " + quoteName(onlyFileName(owner_->absFileName())),
927 FileName(owner_->filePath()));
931 string SVN::checkIn(string const & msg)
933 FileName tmpf = FileName::tempName("lyxvcout");
935 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
936 return N_("Error: Could not generate logfile.");
939 doVCCommand("svn commit -m \"" + msg + "\" "
940 + quoteName(onlyFileName(owner_->absFileName()))
941 + " > " + quoteName(tmpf.toFilesystemEncoding()),
942 FileName(owner_->filePath()));
945 string res = scanLogFile(tmpf, log);
947 frontend::Alert::error(_("Revision control error."),
948 _("Error when committing to repository.\n"
949 "You have to manually resolve the problem.\n"
950 "LyX will reopen the document after you press OK."));
952 fileLock(false, tmpf, log);
955 return log.empty() ? string() : "SVN: " + log;
959 bool SVN::checkInEnabled()
968 bool SVN::isCheckInWithConfirmation()
975 // FIXME Correctly return code should be checked instead of this.
976 // This would need another solution than just plain startscript.
977 // Hint from Andre': QProcess::readAllStandardError()...
978 string SVN::scanLogFile(FileName const & f, string & status)
980 ifstream ifs(f.toFilesystemEncoding().c_str());
985 LYXERR(Debug::LYXVC, line << "\n");
987 status += line + "; ";
988 if (prefixIs(line, "C ") || prefixIs(line, "CU ")
989 || contains(line, "Commit failed")) {
993 if (contains(line, "svn:needs-lock")) {
1003 void SVN::fileLock(bool lock, FileName const & tmpf, string &status)
1005 if (!locked_mode_ || (isLocked() == lock))
1008 string const arg = lock ? "lock " : "unlock ";
1009 doVCCommand("svn "+ arg + quoteName(onlyFileName(owner_->absFileName()))
1010 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1011 FileName(owner_->filePath()));
1013 // Lock error messages go unfortunately on stderr and are unreachible this way.
1014 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1018 if (!line.empty()) status += line + "; ";
1022 if (!isLocked() && lock)
1023 frontend::Alert::error(_("Revision control error."),
1024 _("Error while acquiring write lock.\n"
1025 "Another user is most probably editing\n"
1026 "the current document now!\n"
1027 "Also check the access to the repository."));
1028 if (isLocked() && !lock)
1029 frontend::Alert::error(_("Revision control error."),
1030 _("Error while releasing write lock.\n"
1031 "Check the access to the repository."));
1035 string SVN::checkOut()
1037 FileName tmpf = FileName::tempName("lyxvcout");
1039 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1040 return N_("Error: Could not generate logfile.");
1043 doVCCommand("svn update --non-interactive " + quoteName(onlyFileName(owner_->absFileName()))
1044 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1045 FileName(owner_->filePath()));
1048 string const res = scanLogFile(tmpf, log);
1050 frontend::Alert::error(_("Revision control error."),
1051 bformat(_("Error when updating from repository.\n"
1052 "You have to manually resolve the conflicts NOW!\n'%1$s'.\n\n"
1053 "After pressing OK, LyX will try to reopen the resolved document."),
1054 from_local8bit(res)));
1056 fileLock(true, tmpf, log);
1059 return log.empty() ? string() : "SVN: " + log;
1063 bool SVN::checkOutEnabled()
1072 string SVN::repoUpdate()
1074 FileName tmpf = FileName::tempName("lyxvcout");
1076 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1077 return N_("Error: Could not generate logfile.");
1080 doVCCommand("svn diff " + quoteName(owner_->filePath())
1081 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1082 FileName(owner_->filePath()));
1083 docstring res = tmpf.fileContents("UTF-8");
1085 LYXERR(Debug::LYXVC, "Diff detected:\n" << res);
1086 docstring const file = from_utf8(owner_->filePath());
1087 docstring text = bformat(_("There were detected changes "
1088 "in the working directory:\n%1$s\n\n"
1089 "In case of file conflict version of the local directory files "
1090 "will be preferred."
1091 "\n\nContinue?"), file);
1092 int ret = frontend::Alert::prompt(_("Changes detected"),
1093 text, 0, 1, _("&Yes"), _("&No"), _("View &Log ..."));
1095 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + tmpf.absFileName()));
1096 ret = frontend::Alert::prompt(_("Changes detected"),
1097 text, 0, 1, _("&Yes"), _("&No"));
1098 hideDialogs("file", 0);
1106 // Reverting looks too harsh, see bug #6255.
1107 // doVCCommand("svn revert -R " + quoteName(owner_->filePath())
1108 // + " > " + quoteName(tmpf.toFilesystemEncoding()),
1109 // FileName(owner_->filePath()));
1110 // res = "Revert log:\n" + tmpf.fileContents("UTF-8");
1111 doVCCommand("svn update --accept mine-full " + quoteName(owner_->filePath())
1112 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1113 FileName(owner_->filePath()));
1114 res += "Update log:\n" + tmpf.fileContents("UTF-8");
1116 LYXERR(Debug::LYXVC, res);
1118 return to_utf8(res);
1122 bool SVN::repoUpdateEnabled()
1128 string SVN::lockingToggle()
1130 FileName tmpf = FileName::tempName("lyxvcout");
1132 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1133 return N_("Error: Could not generate logfile.");
1136 int ret = doVCCommand("svn proplist " + quoteName(onlyFileName(owner_->absFileName()))
1137 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1138 FileName(owner_->filePath()));
1143 string res = scanLogFile(tmpf, log);
1144 bool locking = contains(res, "svn:needs-lock");
1146 ret = doVCCommand("svn propset svn:needs-lock ON "
1147 + quoteName(onlyFileName(owner_->absFileName()))
1148 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1149 FileName(owner_->filePath()));
1151 ret = doVCCommand("svn propdel svn:needs-lock "
1152 + quoteName(onlyFileName(owner_->absFileName()))
1153 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1154 FileName(owner_->filePath()));
1159 frontend::Alert::warning(_("VCN File Locking"),
1160 (locking ? _("Locking property unset.") : _("Locking property set.")) + "\n"
1161 + _("Do not forget to commit the locking property into the repository."),
1164 return string("SVN: ") + N_("Locking property set.");
1168 bool SVN::lockingToggleEnabled()
1176 // Reverts to the version in SVN repository and
1177 // gets the updated version from the repository.
1178 string const fil = quoteName(onlyFileName(owner_->absFileName()));
1180 doVCCommand("svn revert -q " + fil,
1181 FileName(owner_->filePath()));
1182 owner_->markClean();
1186 bool SVN::isRevertWithConfirmation()
1188 //FIXME owner && diff
1193 void SVN::undoLast()
1195 // merge the current with the previous version
1196 // in a reverse patch kind of way, so that the
1197 // result is to revert the last changes.
1198 lyxerr << "Sorry, not implemented." << endl;
1202 bool SVN::undoLastEnabled()
1208 string SVN::revisionInfo(LyXVC::RevisionInfo const info)
1210 if (info == LyXVC::Tree) {
1211 if (rev_tree_cache_.empty())
1212 if (!getTreeRevisionInfo())
1213 rev_tree_cache_ = "?";
1214 if (rev_tree_cache_ == "?")
1217 return rev_tree_cache_;
1220 // fill the rest of the attributes for a single file
1221 if (rev_file_cache_.empty())
1222 if (!getFileRevisionInfo())
1223 rev_file_cache_ = "?";
1227 if (rev_file_cache_ == "?")
1229 return rev_file_cache_;
1231 return rev_author_cache_;
1233 return rev_date_cache_;
1235 return rev_time_cache_;
1244 bool SVN::getFileRevisionInfo()
1246 FileName tmpf = FileName::tempName("lyxvcout");
1248 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1249 return N_("Error: Could not generate logfile.");
1252 doVCCommand("svn info --xml " + quoteName(onlyFileName(owner_->absFileName()))
1253 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1254 FileName(owner_->filePath()));
1259 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1267 LYXERR(Debug::LYXVC, line);
1268 if (prefixIs(line, "<commit"))
1270 if (c && prefixIs(line, " revision=\"") && suffixIs(line, "\">")) {
1271 string l1 = subst(line, "revision=\"", "");
1272 string l2 = trim(subst(l1, "\">", ""));
1274 rev_file_cache_ = rev = l2;
1276 if (c && prefixIs(line, "<author>") && suffixIs(line, "</author>")) {
1277 string l1 = subst(line, "<author>", "");
1278 string l2 = subst(l1, "</author>", "");
1279 rev_author_cache_ = l2;
1281 if (c && prefixIs(line, "<date>") && suffixIs(line, "</date>")) {
1282 string l1 = subst(line, "<date>", "");
1283 string l2 = subst(l1, "</date>", "");
1284 l2 = split(l2, l1, 'T');
1285 rev_date_cache_ = l1;
1286 l2 = split(l2, l1, '.');
1287 rev_time_cache_ = l1;
1293 return !rev.empty();
1297 bool SVN::getTreeRevisionInfo()
1299 FileName tmpf = FileName::tempName("lyxvcout");
1301 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1302 return N_("Error: Could not generate logfile.");
1305 doVCCommand("svnversion -n . > " + quoteName(tmpf.toFilesystemEncoding()),
1306 FileName(owner_->filePath()));
1311 // only first line in case something bad happens.
1312 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1318 rev_tree_cache_ = line;
1319 return !line.empty();
1323 void SVN::getLog(FileName const & tmpf)
1325 doVCCommand("svn log " + quoteName(onlyFileName(owner_->absFileName()))
1326 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1327 FileName(owner_->filePath()));
1331 bool SVN::prepareFileRevision(string const & revis, string & f)
1333 if (!isStrInt(revis))
1336 int rev = convert<int>(revis);
1338 if (!getFileRevisionInfo())
1341 rev = convert<int>(rev_file_cache_);
1342 // go back for minus rev
1344 rev = rev + convert<int>(rev_file_cache_);
1349 string revname = convert<string>(rev);
1350 FileName tmpf = FileName::tempName("lyxvcrev_" + revname + "_");
1352 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1353 return N_("Error: Could not generate logfile.");
1356 doVCCommand("svn cat -r " + revname + " "
1357 + quoteName(onlyFileName(owner_->absFileName()))
1358 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1359 FileName(owner_->filePath()));
1360 if (tmpf.isFileEmpty())
1363 f = tmpf.absFileName();
1368 bool SVN::prepareFileRevisionEnabled()
1375 bool SVN::toggleReadOnlyEnabled()