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 lyxerr << "Sorry, not implemented." << endl;
240 bool RCS::lockingToggleEnabled()
248 doVCCommand("co -f -u" + version_ + " "
249 + quoteName(onlyFileName(owner_->absFileName())),
250 FileName(owner_->filePath()));
251 // We ignore changes and just reload!
256 bool RCS::isRevertWithConfirmation()
258 //FIXME owner && diff ?
265 LYXERR(Debug::LYXVC, "LyXVC: undoLast");
266 doVCCommand("rcs -o" + version_ + " "
267 + quoteName(onlyFileName(owner_->absFileName())),
268 FileName(owner_->filePath()));
272 bool RCS::undoLastEnabled()
278 void RCS::getLog(FileName const & tmpf)
280 doVCCommand("rlog " + quoteName(onlyFileName(owner_->absFileName()))
281 + " > " + quoteName(tmpf.toFilesystemEncoding()),
282 FileName(owner_->filePath()));
286 bool RCS::toggleReadOnlyEnabled()
288 // This got broken somewhere along lfuns dispatch reorganization.
289 // reloadBuffer would be needed after this, but thats problematic
290 // since we are inside Buffer::dispatch.
295 string RCS::revisionInfo(LyXVC::RevisionInfo const info)
297 if (info == LyXVC::File)
303 bool RCS::prepareFileRevision(string const &revis, string & f)
308 int back = convert<int>(rev);
309 // if positive use as the last number in the whole revision string
312 rsplit(version_, base , '.' );
313 rev = base + "." + rev;
317 // we care about the last number from revision string
318 // in case of backward indexing
321 cur = rsplit(version_, base , '.' );
324 int want = convert<int>(cur) + back;
328 rev = base + "." + convert<string>(want);
332 FileName tmpf = FileName::tempName("lyxvcrev_" + rev + "_");
334 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
335 return N_("Error: Could not generate logfile.");
338 doVCCommand("co -p" + rev + " "
339 + quoteName(onlyFileName(owner_->absFileName()))
340 + " > " + quoteName(tmpf.toFilesystemEncoding()),
341 FileName(owner_->filePath()));
342 if (tmpf.isFileEmpty())
345 f = tmpf.absFileName();
350 bool RCS::prepareFileRevisionEnabled()
356 /////////////////////////////////////////////////////////////////////
360 /////////////////////////////////////////////////////////////////////
362 CVS::CVS(FileName const & m, FileName const & f)
370 FileName const CVS::findFile(FileName const & file)
372 // First we look for the CVS/Entries in the same dir
373 // where we have file.
374 FileName const entries(onlyPath(file.absFileName()) + "/CVS/Entries");
375 string const tmpf = '/' + onlyFileName(file.absFileName()) + '/';
376 LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under cvs in `" << entries
377 << "' for `" << tmpf << '\'');
378 if (entries.isReadableFile()) {
379 // Ok we are at least in a CVS dir. Parse the CVS/Entries
380 // and see if we can find this file. We do a fast and
382 ifstream ifs(entries.toFilesystemEncoding().c_str());
384 while (getline(ifs, line)) {
385 LYXERR(Debug::LYXVC, "\tEntries: " << line);
386 if (contains(line, tmpf))
394 void CVS::scanMaster()
396 LYXERR(Debug::LYXVC, "LyXVC::CVS: scanMaster. \n Checking: " << master_);
397 // Ok now we do the real scan...
398 ifstream ifs(master_.toFilesystemEncoding().c_str());
399 string name = onlyFileName(file_.absFileName());
400 string tmpf = '/' + name + '/';
401 LYXERR(Debug::LYXVC, "\tlooking for `" << tmpf << '\'');
403 static regex const reg("/(.*)/(.*)/(.*)/(.*)/(.*)");
404 while (getline(ifs, line)) {
405 LYXERR(Debug::LYXVC, "\t line: " << line);
406 if (contains(line, tmpf)) {
407 // Ok extract the fields.
410 regex_match(line, sm, reg);
412 //sm[0]; // whole matched string
414 version_ = sm.str(2);
415 string const file_date = sm.str(3);
418 //sm[5]; // tag or tagdate
419 if (file_.isReadableFile()) {
420 time_t mod = file_.lastModified();
421 string mod_date = rtrim(asctime(gmtime(&mod)), "\n");
422 LYXERR(Debug::LYXVC, "Date in Entries: `" << file_date
423 << "'\nModification date of file: `" << mod_date << '\'');
424 if (file_.isReadOnly()) {
425 // readonly checkout is unlocked
428 FileName bdir(addPath(master_.onlyPath().absFileName(),"Base"));
429 FileName base(addName(bdir.absFileName(),name));
430 // if base version is existent "cvs edit" was used to lock
431 vcstatus = base.isReadableFile() ? LOCKED : NOLOCKING;
434 vcstatus = NOLOCKING;
442 string const CVS::getTarget(OperationMode opmode) const
446 // in client server mode CVS does not like full path operand for directory operation
447 // since LyX switches to the repo dir "." is good enough as target
450 return quoteName(onlyFileName(owner_->absFileName()));
456 docstring CVS::toString(CvsStatus status) const
460 return _("Up-to-date");
461 case LocallyModified:
462 return _("Locally Modified");
464 return _("Locally Added");
466 return _("Needs Merge");
468 return _("Needs Checkout");
470 return _("No CVS file");
472 return _("Cannot retrieve CVS status");
478 CVS::CvsStatus CVS::getStatus()
480 FileName tmpf = FileName::tempName("lyxvcout");
482 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
486 if (doVCCommand("cvs status " + getTarget(File)
487 + " > " + quoteName(tmpf.toFilesystemEncoding()),
488 FileName(owner_->filePath()))) {
493 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
494 CvsStatus status = NoCvsFile;
499 LYXERR(Debug::LYXVC, line << "\n");
500 if (prefixIs(line, "File:")) {
501 if (contains(line, "Up-to-date"))
503 else if (contains(line, "Locally Modified"))
504 status = LocallyModified;
505 else if (contains(line, "Locally Added"))
506 status = LocallyAdded;
507 else if (contains(line, "Needs Merge"))
509 else if (contains(line, "Needs Checkout"))
510 status = NeedsCheckout;
518 void CVS::registrer(string const & msg)
520 doVCCommand("cvs -q add -m \"" + msg + "\" "
522 FileName(owner_->filePath()));
526 void CVS::getDiff(OperationMode opmode, FileName const & tmpf)
528 doVCCommand("cvs diff " + getTarget(opmode)
529 + " > " + quoteName(tmpf.toFilesystemEncoding()),
530 FileName(owner_->filePath()), false);
537 return doVCCommand("cvs -q edit " + getTarget(File),
538 FileName(owner_->filePath()));
545 return doVCCommand("cvs -q unedit " + getTarget(File),
546 FileName(owner_->filePath()));
550 int CVS::update(OperationMode opmode, FileName const & tmpf)
552 string const redirection = tmpf.empty() ? ""
553 : " > " + quoteName(tmpf.toFilesystemEncoding());
555 return doVCCommand("cvs -q update "
556 + getTarget(opmode) + redirection,
557 FileName(owner_->filePath()));
561 string CVS::scanLogFile(FileName const & f, string & status)
563 ifstream ifs(f.toFilesystemEncoding().c_str());
568 LYXERR(Debug::LYXVC, line << "\n");
570 status += line + "; ";
571 if (prefixIs(line, "C ")) {
581 string CVS::checkIn(string const & msg)
583 CvsStatus status = getStatus();
586 if (vcstatus != NOLOCKING)
588 return "CVS: Proceeded";
589 case LocallyModified:
591 int rc = doVCCommand("cvs -q commit -m \"" + msg + "\" "
593 FileName(owner_->filePath()));
594 return rc ? string() : "CVS: Proceeded";
598 frontend::Alert::error(_("Revision control error."),
599 _("The repository version is newer then the current check out.\n"
600 "You have to update from repository first or revert your changes.")) ;
603 frontend::Alert::error(_("Revision control error."),
604 bformat(_("Bad status when checking in changes.\n"
613 bool CVS::isLocked() const
615 FileName fn(owner_->absFileName());
617 return !fn.isReadOnly();
621 bool CVS::checkInEnabled()
623 if (vcstatus != NOLOCKING)
630 bool CVS::isCheckInWithConfirmation()
632 CvsStatus status = getStatus();
633 return status == LocallyModified || status == LocallyAdded;
637 string CVS::checkOut()
639 if (vcstatus != NOLOCKING && edit())
641 FileName tmpf = FileName::tempName("lyxvcout");
643 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
647 int rc = update(File, tmpf);
649 string const res = scanLogFile(tmpf, log);
651 frontend::Alert::error(_("Revision control error."),
652 bformat(_("Error when updating from repository.\n"
653 "You have to manually resolve the conflicts NOW!\n'%1$s'.\n\n"
654 "After pressing OK, LyX will try to reopen the resolved document."),
655 from_local8bit(res)));
658 return rc ? string() : log.empty() ? "CVS: Proceeded" : "CVS: " + log;
662 bool CVS::checkOutEnabled()
664 if (vcstatus != NOLOCKING)
671 string CVS::repoUpdate()
673 FileName tmpf = FileName::tempName("lyxvcout");
675 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
679 getDiff(Directory, tmpf);
680 docstring res = tmpf.fileContents("UTF-8");
682 LYXERR(Debug::LYXVC, "Diff detected:\n" << res);
683 docstring const file = from_utf8(owner_->filePath());
684 docstring text = bformat(_("There were detected changes "
685 "in the working directory:\n%1$s\n\n"
686 "In case of file conflict you have to resolve them "
687 "manually or revert to repository version later."), file);
688 int ret = frontend::Alert::prompt(_("Changes detected"),
689 text, 0, 1, _("&Continue"), _("&Abort"), _("View &Log ..."));
691 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + tmpf.absFileName()));
692 ret = frontend::Alert::prompt(_("Changes detected"),
693 text, 0, 1, _("&Continue"), _("&Abort"));
694 hideDialogs("file", 0);
702 int rc = update(Directory, tmpf);
703 res += "Update log:\n" + tmpf.fileContents("UTF-8");
706 LYXERR(Debug::LYXVC, res);
707 return rc ? string() : "CVS: Proceeded" ;
711 bool CVS::repoUpdateEnabled()
717 string CVS::lockingToggle()
719 lyxerr << "Sorry, not implemented." << endl;
724 bool CVS::lockingToggleEnabled()
730 bool CVS::isRevertWithConfirmation()
732 CvsStatus status = getStatus();
733 return !owner_->isClean() || status == LocallyModified || status == NeedsMerge;
739 // Reverts to the version in CVS repository and
740 // gets the updated version from the repository.
741 CvsStatus status = getStatus();
744 if (vcstatus != NOLOCKING)
749 case LocallyModified: {
750 FileName f(owner_->absFileName());
752 update(File, FileName());
757 docstring const file = owner_->fileName().displayName(20);
758 frontend::Alert::error(_("Revision control error."),
759 bformat(_("The document %1$s is not in repository.\n"
760 "You have to check in the first revision before you can revert."),
765 docstring const file = owner_->fileName().displayName(20);
766 frontend::Alert::error(_("Revision control error."),
767 bformat(_("Cannot revert document %1$s to repository version.\n"
768 "The status '%2$s' is unexpected."),
769 file, toString(status)));
778 // merge the current with the previous version
779 // in a reverse patch kind of way, so that the
780 // result is to revert the last changes.
781 lyxerr << "Sorry, not implemented." << endl;
785 bool CVS::undoLastEnabled()
791 void CVS::getLog(FileName const & tmpf)
793 doVCCommand("cvs log " + getTarget(File)
794 + " > " + quoteName(tmpf.toFilesystemEncoding()),
795 FileName(owner_->filePath()));
799 bool CVS::toggleReadOnlyEnabled()
805 string CVS::revisionInfo(LyXVC::RevisionInfo const info)
807 if (info == LyXVC::File)
813 bool CVS::prepareFileRevision(string const &, string &)
819 bool CVS::prepareFileRevisionEnabled()
825 /////////////////////////////////////////////////////////////////////
829 /////////////////////////////////////////////////////////////////////
831 SVN::SVN(FileName const & m, FileName const & f)
841 FileName const SVN::findFile(FileName const & file)
843 // First we look for the .svn/entries in the same dir
844 // where we have file.
845 FileName const entries(onlyPath(file.absFileName()) + "/.svn/entries");
846 string const tmpf = onlyFileName(file.absFileName());
847 LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under svn in `" << entries
848 << "' for `" << tmpf << '\'');
849 if (entries.isReadableFile()) {
850 // Ok we are at least in a SVN dir. Parse the .svn/entries
851 // and see if we can find this file. We do a fast and
853 ifstream ifs(entries.toFilesystemEncoding().c_str());
854 string line, oldline;
855 while (getline(ifs, line)) {
856 if (line == "dir" || line == "file")
857 LYXERR(Debug::LYXVC, "\tEntries: " << oldline);
858 if (oldline == tmpf && line == "file")
867 void SVN::scanMaster()
869 // vcstatus code is somewhat superflous, until we want
870 // to implement read-only toggle for svn.
871 vcstatus = NOLOCKING;
872 if (checkLockMode()) {
882 bool SVN::checkLockMode()
884 FileName tmpf = FileName::tempName("lyxvcout");
886 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
887 return N_("Error: Could not generate logfile.");
890 LYXERR(Debug::LYXVC, "Detecting locking mode...");
891 if (doVCCommandCall("svn proplist " + quoteName(file_.onlyFileName())
892 + " > " + quoteName(tmpf.toFilesystemEncoding()),
896 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
902 LYXERR(Debug::LYXVC, line);
903 if (contains(line, "svn:needs-lock"))
906 LYXERR(Debug::LYXVC, "Locking enabled: " << ret);
914 bool SVN::isLocked() const
917 return !file_.isReadOnly();
921 void SVN::registrer(string const & /*msg*/)
923 doVCCommand("svn add -q " + quoteName(onlyFileName(owner_->absFileName())),
924 FileName(owner_->filePath()));
928 string SVN::checkIn(string const & msg)
930 FileName tmpf = FileName::tempName("lyxvcout");
932 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
933 return N_("Error: Could not generate logfile.");
936 doVCCommand("svn commit -m \"" + msg + "\" "
937 + quoteName(onlyFileName(owner_->absFileName()))
938 + " > " + quoteName(tmpf.toFilesystemEncoding()),
939 FileName(owner_->filePath()));
942 string res = scanLogFile(tmpf, log);
944 frontend::Alert::error(_("Revision control error."),
945 _("Error when committing to repository.\n"
946 "You have to manually resolve the problem.\n"
947 "LyX will reopen the document after you press OK."));
949 fileLock(false, tmpf, log);
952 return log.empty() ? string() : "SVN: " + log;
956 bool SVN::checkInEnabled()
965 bool SVN::isCheckInWithConfirmation()
972 // FIXME Correctly return code should be checked instead of this.
973 // This would need another solution than just plain startscript.
974 // Hint from Andre': QProcess::readAllStandardError()...
975 string SVN::scanLogFile(FileName const & f, string & status)
977 ifstream ifs(f.toFilesystemEncoding().c_str());
982 LYXERR(Debug::LYXVC, line << "\n");
984 status += line + "; ";
985 if (prefixIs(line, "C ") || prefixIs(line, "CU ")
986 || contains(line, "Commit failed")) {
990 if (contains(line, "svn:needs-lock")) {
1000 void SVN::fileLock(bool lock, FileName const & tmpf, string &status)
1002 if (!locked_mode_ || (isLocked() == lock))
1005 string const arg = lock ? "lock " : "unlock ";
1006 doVCCommand("svn "+ arg + quoteName(onlyFileName(owner_->absFileName()))
1007 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1008 FileName(owner_->filePath()));
1010 // Lock error messages go unfortunately on stderr and are unreachible this way.
1011 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1015 if (!line.empty()) status += line + "; ";
1019 if (!isLocked() && lock)
1020 frontend::Alert::error(_("Revision control error."),
1021 _("Error while acquiring write lock.\n"
1022 "Another user is most probably editing\n"
1023 "the current document now!\n"
1024 "Also check the access to the repository."));
1025 if (isLocked() && !lock)
1026 frontend::Alert::error(_("Revision control error."),
1027 _("Error while releasing write lock.\n"
1028 "Check the access to the repository."));
1032 string SVN::checkOut()
1034 FileName tmpf = FileName::tempName("lyxvcout");
1036 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1037 return N_("Error: Could not generate logfile.");
1040 doVCCommand("svn update --non-interactive " + quoteName(onlyFileName(owner_->absFileName()))
1041 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1042 FileName(owner_->filePath()));
1045 string const res = scanLogFile(tmpf, log);
1047 frontend::Alert::error(_("Revision control error."),
1048 bformat(_("Error when updating from repository.\n"
1049 "You have to manually resolve the conflicts NOW!\n'%1$s'.\n\n"
1050 "After pressing OK, LyX will try to reopen the resolved document."),
1051 from_local8bit(res)));
1053 fileLock(true, tmpf, log);
1056 return log.empty() ? string() : "SVN: " + log;
1060 bool SVN::checkOutEnabled()
1069 string SVN::repoUpdate()
1071 FileName tmpf = FileName::tempName("lyxvcout");
1073 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1074 return N_("Error: Could not generate logfile.");
1077 doVCCommand("svn diff " + quoteName(owner_->filePath())
1078 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1079 FileName(owner_->filePath()));
1080 docstring res = tmpf.fileContents("UTF-8");
1082 LYXERR(Debug::LYXVC, "Diff detected:\n" << res);
1083 docstring const file = from_utf8(owner_->filePath());
1084 docstring text = bformat(_("There were detected changes "
1085 "in the working directory:\n%1$s\n\n"
1086 "In case of file conflict version of the local directory files "
1087 "will be preferred."
1088 "\n\nContinue?"), file);
1089 int ret = frontend::Alert::prompt(_("Changes detected"),
1090 text, 0, 1, _("&Yes"), _("&No"), _("View &Log ..."));
1092 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + tmpf.absFileName()));
1093 ret = frontend::Alert::prompt(_("Changes detected"),
1094 text, 0, 1, _("&Yes"), _("&No"));
1095 hideDialogs("file", 0);
1103 // Reverting looks too harsh, see bug #6255.
1104 // doVCCommand("svn revert -R " + quoteName(owner_->filePath())
1105 // + " > " + quoteName(tmpf.toFilesystemEncoding()),
1106 // FileName(owner_->filePath()));
1107 // res = "Revert log:\n" + tmpf.fileContents("UTF-8");
1108 doVCCommand("svn update --accept mine-full " + quoteName(owner_->filePath())
1109 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1110 FileName(owner_->filePath()));
1111 res += "Update log:\n" + tmpf.fileContents("UTF-8");
1113 LYXERR(Debug::LYXVC, res);
1115 return to_utf8(res);
1119 bool SVN::repoUpdateEnabled()
1125 string SVN::lockingToggle()
1127 FileName tmpf = FileName::tempName("lyxvcout");
1129 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1130 return N_("Error: Could not generate logfile.");
1133 int ret = doVCCommand("svn proplist " + quoteName(onlyFileName(owner_->absFileName()))
1134 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1135 FileName(owner_->filePath()));
1140 string res = scanLogFile(tmpf, log);
1141 bool locking = contains(res, "svn:needs-lock");
1143 ret = doVCCommand("svn propset svn:needs-lock ON "
1144 + quoteName(onlyFileName(owner_->absFileName()))
1145 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1146 FileName(owner_->filePath()));
1148 ret = doVCCommand("svn propdel svn:needs-lock "
1149 + quoteName(onlyFileName(owner_->absFileName()))
1150 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1151 FileName(owner_->filePath()));
1156 frontend::Alert::warning(_("VCN File Locking"),
1157 (locking ? _("Locking property unset.") : _("Locking property set.")) + "\n"
1158 + _("Do not forget to commit the locking property into the repository."),
1161 return string("SVN: ") + N_("Locking property set.");
1165 bool SVN::lockingToggleEnabled()
1173 // Reverts to the version in SVN repository and
1174 // gets the updated version from the repository.
1175 string const fil = quoteName(onlyFileName(owner_->absFileName()));
1177 doVCCommand("svn revert -q " + fil,
1178 FileName(owner_->filePath()));
1179 owner_->markClean();
1183 bool SVN::isRevertWithConfirmation()
1185 //FIXME owner && diff
1190 void SVN::undoLast()
1192 // merge the current with the previous version
1193 // in a reverse patch kind of way, so that the
1194 // result is to revert the last changes.
1195 lyxerr << "Sorry, not implemented." << endl;
1199 bool SVN::undoLastEnabled()
1205 string SVN::revisionInfo(LyXVC::RevisionInfo const info)
1207 if (info == LyXVC::Tree) {
1208 if (rev_tree_cache_.empty())
1209 if (!getTreeRevisionInfo())
1210 rev_tree_cache_ = "?";
1211 if (rev_tree_cache_ == "?")
1214 return rev_tree_cache_;
1217 // fill the rest of the attributes for a single file
1218 if (rev_file_cache_.empty())
1219 if (!getFileRevisionInfo())
1220 rev_file_cache_ = "?";
1224 if (rev_file_cache_ == "?")
1226 return rev_file_cache_;
1228 return rev_author_cache_;
1230 return rev_date_cache_;
1232 return rev_time_cache_;
1241 bool SVN::getFileRevisionInfo()
1243 FileName tmpf = FileName::tempName("lyxvcout");
1245 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1246 return N_("Error: Could not generate logfile.");
1249 doVCCommand("svn info --xml " + quoteName(onlyFileName(owner_->absFileName()))
1250 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1251 FileName(owner_->filePath()));
1256 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1264 LYXERR(Debug::LYXVC, line);
1265 if (prefixIs(line, "<commit"))
1267 if (c && prefixIs(line, " revision=\"") && suffixIs(line, "\">")) {
1268 string l1 = subst(line, "revision=\"", "");
1269 string l2 = trim(subst(l1, "\">", ""));
1271 rev_file_cache_ = rev = l2;
1273 if (c && prefixIs(line, "<author>") && suffixIs(line, "</author>")) {
1274 string l1 = subst(line, "<author>", "");
1275 string l2 = subst(l1, "</author>", "");
1276 rev_author_cache_ = l2;
1278 if (c && prefixIs(line, "<date>") && suffixIs(line, "</date>")) {
1279 string l1 = subst(line, "<date>", "");
1280 string l2 = subst(l1, "</date>", "");
1281 l2 = split(l2, l1, 'T');
1282 rev_date_cache_ = l1;
1283 l2 = split(l2, l1, '.');
1284 rev_time_cache_ = l1;
1290 return !rev.empty();
1294 bool SVN::getTreeRevisionInfo()
1296 FileName tmpf = FileName::tempName("lyxvcout");
1298 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1299 return N_("Error: Could not generate logfile.");
1302 doVCCommand("svnversion -n . > " + quoteName(tmpf.toFilesystemEncoding()),
1303 FileName(owner_->filePath()));
1308 // only first line in case something bad happens.
1309 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1315 rev_tree_cache_ = line;
1316 return !line.empty();
1320 void SVN::getLog(FileName const & tmpf)
1322 doVCCommand("svn log " + quoteName(onlyFileName(owner_->absFileName()))
1323 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1324 FileName(owner_->filePath()));
1328 bool SVN::prepareFileRevision(string const & revis, string & f)
1330 if (!isStrInt(revis))
1333 int rev = convert<int>(revis);
1335 if (!getFileRevisionInfo())
1338 rev = convert<int>(rev_file_cache_);
1339 // go back for minus rev
1341 rev = rev + convert<int>(rev_file_cache_);
1346 string revname = convert<string>(rev);
1347 FileName tmpf = FileName::tempName("lyxvcrev_" + revname + "_");
1349 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1350 return N_("Error: Could not generate logfile.");
1353 doVCCommand("svn cat -r " + revname + " "
1354 + quoteName(onlyFileName(owner_->absFileName()))
1355 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1356 FileName(owner_->filePath()));
1357 if (tmpf.isFileEmpty())
1360 f = tmpf.absFileName();
1365 bool SVN::prepareFileRevisionEnabled()
1372 bool SVN::toggleReadOnlyEnabled()