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 string RCS::checkOut()
202 int ret = doVCCommand("co -q -l " + quoteName(onlyFileName(owner_->absFileName())),
203 FileName(owner_->filePath()));
204 return ret ? string() : "RCS: Proceeded";
208 bool RCS::checkOutEnabled()
210 return owner_ && owner_->isReadonly();
214 string RCS::repoUpdate()
216 lyxerr << "Sorry, not implemented." << endl;
221 bool RCS::repoUpdateEnabled()
227 string RCS::lockingToggle()
229 lyxerr << "Sorry, not implemented." << endl;
234 bool RCS::lockingToggleEnabled()
242 doVCCommand("co -f -u" + version_ + " "
243 + quoteName(onlyFileName(owner_->absFileName())),
244 FileName(owner_->filePath()));
245 // We ignore changes and just reload!
252 LYXERR(Debug::LYXVC, "LyXVC: undoLast");
253 doVCCommand("rcs -o" + version_ + " "
254 + quoteName(onlyFileName(owner_->absFileName())),
255 FileName(owner_->filePath()));
259 bool RCS::undoLastEnabled()
265 void RCS::getLog(FileName const & tmpf)
267 doVCCommand("rlog " + quoteName(onlyFileName(owner_->absFileName()))
268 + " > " + quoteName(tmpf.toFilesystemEncoding()),
269 FileName(owner_->filePath()));
273 bool RCS::toggleReadOnlyEnabled()
275 // This got broken somewhere along lfuns dispatch reorganization.
276 // reloadBuffer would be needed after this, but thats problematic
277 // since we are inside Buffer::dispatch.
282 string RCS::revisionInfo(LyXVC::RevisionInfo const info)
284 if (info == LyXVC::File)
290 bool RCS::prepareFileRevision(string const &revis, string & f)
295 int back = convert<int>(rev);
296 // if positive use as the last number in the whole revision string
299 rsplit(version_, base , '.' );
300 rev = base + "." + rev;
304 // we care about the last number from revision string
305 // in case of backward indexing
308 cur = rsplit(version_, base , '.' );
311 int want = convert<int>(cur) + back;
315 rev = base + "." + convert<string>(want);
319 FileName tmpf = FileName::tempName("lyxvcrev_" + rev + "_");
321 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
322 return N_("Error: Could not generate logfile.");
325 doVCCommand("co -p" + rev + " "
326 + quoteName(onlyFileName(owner_->absFileName()))
327 + " > " + quoteName(tmpf.toFilesystemEncoding()),
328 FileName(owner_->filePath()));
329 if (tmpf.isFileEmpty())
332 f = tmpf.absFileName();
337 bool RCS::prepareFileRevisionEnabled()
343 /////////////////////////////////////////////////////////////////////
347 /////////////////////////////////////////////////////////////////////
349 CVS::CVS(FileName const & m, FileName const & f)
357 FileName const CVS::findFile(FileName const & file)
359 // First we look for the CVS/Entries in the same dir
360 // where we have file.
361 FileName const entries(onlyPath(file.absFileName()) + "/CVS/Entries");
362 string const tmpf = '/' + onlyFileName(file.absFileName()) + '/';
363 LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under cvs in `" << entries
364 << "' for `" << tmpf << '\'');
365 if (entries.isReadableFile()) {
366 // Ok we are at least in a CVS dir. Parse the CVS/Entries
367 // and see if we can find this file. We do a fast and
369 ifstream ifs(entries.toFilesystemEncoding().c_str());
371 while (getline(ifs, line)) {
372 LYXERR(Debug::LYXVC, "\tEntries: " << line);
373 if (contains(line, tmpf))
381 void CVS::scanMaster()
383 LYXERR(Debug::LYXVC, "LyXVC::CVS: scanMaster. \n Checking: " << master_);
384 // Ok now we do the real scan...
385 ifstream ifs(master_.toFilesystemEncoding().c_str());
386 string name = onlyFileName(file_.absFileName());
387 string tmpf = '/' + name + '/';
388 LYXERR(Debug::LYXVC, "\tlooking for `" << tmpf << '\'');
390 static regex const reg("/(.*)/(.*)/(.*)/(.*)/(.*)");
391 while (getline(ifs, line)) {
392 LYXERR(Debug::LYXVC, "\t line: " << line);
393 if (contains(line, tmpf)) {
394 // Ok extract the fields.
397 regex_match(line, sm, reg);
399 //sm[0]; // whole matched string
401 version_ = sm.str(2);
402 string const file_date = sm.str(3);
405 //sm[5]; // tag or tagdate
406 if (file_.isReadableFile()) {
407 time_t mod = file_.lastModified();
408 string mod_date = rtrim(asctime(gmtime(&mod)), "\n");
409 LYXERR(Debug::LYXVC, "Date in Entries: `" << file_date
410 << "'\nModification date of file: `" << mod_date << '\'');
411 if (file_.isReadOnly()) {
412 // readonly checkout is unlocked
415 FileName bdir(addPath(master_.onlyPath().absFileName(),"Base"));
416 FileName base(addName(bdir.absFileName(),name));
417 // if base version is existent "cvs edit" was used to lock
418 vcstatus = base.isReadableFile() ? LOCKED : NOLOCKING;
421 vcstatus = NOLOCKING;
429 string const CVS::getTarget(OperationMode opmode) const
433 return quoteName(owner_->filePath());
435 return quoteName(onlyFileName(owner_->absFileName()));
441 docstring CVS::toString(CvsStatus status) const
445 return _("Up-to-date");
446 case LocallyModified:
447 return _("Locally Modified");
449 return _("Locally Added");
451 return _("Needs Merge");
453 return _("Needs Checkout");
455 return _("No CVS file");
457 return _("Cannot retrieve CVS status");
463 CVS::CvsStatus CVS::getStatus()
465 FileName tmpf = FileName::tempName("lyxvcout");
467 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
471 if (doVCCommand("cvs status " + getTarget(File)
472 + " > " + quoteName(tmpf.toFilesystemEncoding()),
473 FileName(owner_->filePath()))) {
478 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
479 CvsStatus status = NoCvsFile;
484 LYXERR(Debug::LYXVC, line << "\n");
485 if (prefixIs(line, "File:")) {
486 if (contains(line, "Up-to-date"))
488 else if (contains(line, "Locally Modified"))
489 status = LocallyModified;
490 else if (contains(line, "Locally Added"))
491 status = LocallyAdded;
492 else if (contains(line, "Needs Merge"))
494 else if (contains(line, "Needs Checkout"))
495 status = NeedsCheckout;
503 void CVS::registrer(string const & msg)
505 doVCCommand("cvs -q add -m \"" + msg + "\" "
507 FileName(owner_->filePath()));
511 void CVS::getDiff(OperationMode opmode, FileName const & tmpf)
513 doVCCommand("cvs diff " + getTarget(opmode)
514 + " > " + quoteName(tmpf.toFilesystemEncoding()),
515 FileName(owner_->filePath()), false);
522 return doVCCommand("cvs -q edit " + getTarget(File),
523 FileName(owner_->filePath()));
530 return doVCCommand("cvs -q unedit " + getTarget(File),
531 FileName(owner_->filePath()));
535 int CVS::update(OperationMode opmode, FileName const & tmpf)
537 string const redirection = tmpf.empty() ? ""
538 : " > " + quoteName(tmpf.toFilesystemEncoding());
540 return doVCCommand("cvs -q update "
541 + getTarget(opmode) + redirection,
542 FileName(owner_->filePath()));
546 string CVS::scanLogFile(FileName const & f, string & status)
548 ifstream ifs(f.toFilesystemEncoding().c_str());
553 LYXERR(Debug::LYXVC, line << "\n");
555 status += line + "; ";
556 if (prefixIs(line, "C ")) {
566 string CVS::checkIn(string const & msg)
568 CvsStatus status = getStatus();
571 if (vcstatus != NOLOCKING)
573 return "CVS: Proceeded";
574 case LocallyModified:
576 int rc = doVCCommand("cvs -q commit -m \"" + msg + "\" "
578 FileName(owner_->filePath()));
579 return rc ? string() : "CVS: Proceeded";
583 frontend::Alert::error(_("Revision control error."),
584 _("The repository version is newer then the current check out.\n"
585 "You have to update from repository first or revert your changes.")) ;
588 frontend::Alert::error(_("Revision control error."),
589 bformat(_("Bad status when checking in changes.\n"
598 bool CVS::isLocked() const
600 FileName fn(owner_->absFileName());
602 return !fn.isReadOnly();
606 bool CVS::checkInEnabled()
608 if (vcstatus != NOLOCKING)
615 string CVS::checkOut()
617 if (vcstatus != NOLOCKING && edit())
619 FileName tmpf = FileName::tempName("lyxvcout");
621 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
625 int rc = update(File, tmpf);
627 string const res = scanLogFile(tmpf, log);
629 frontend::Alert::error(_("Revision control error."),
630 bformat(_("Error when updating from repository.\n"
631 "You have to manually resolve the conflicts NOW!\n'%1$s'.\n\n"
632 "After pressing OK, LyX will try to reopen the resolved document."),
633 from_local8bit(res)));
636 return rc ? string() : log.empty() ? "CVS: Proceeded" : "CVS: " + log;
640 bool CVS::checkOutEnabled()
642 if (vcstatus != NOLOCKING)
649 string CVS::repoUpdate()
651 FileName tmpf = FileName::tempName("lyxvcout");
653 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
657 getDiff(Directory, tmpf);
658 docstring res = tmpf.fileContents("UTF-8");
660 LYXERR(Debug::LYXVC, "Diff detected:\n" << res);
661 docstring const file = from_utf8(owner_->filePath());
662 docstring text = bformat(_("There were detected changes "
663 "in the working directory:\n%1$s\n\n"
664 "In case of file conflict you have to resolve them "
665 "manually or revert to repository version later."), file);
666 int ret = frontend::Alert::prompt(_("Changes detected"),
667 text, 0, 1, _("&Continue"), _("&Abort"), _("View &Log ..."));
669 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + tmpf.absFileName()));
670 ret = frontend::Alert::prompt(_("Changes detected"),
671 text, 0, 1, _("&Continue"), _("&Abort"));
672 hideDialogs("file", 0);
680 int rc = update(Directory, tmpf);
681 res += "Update log:\n" + tmpf.fileContents("UTF-8");
684 LYXERR(Debug::LYXVC, res);
685 return rc ? string() : "CVS: Proceeded" ;
689 bool CVS::repoUpdateEnabled()
695 string CVS::lockingToggle()
697 lyxerr << "Sorry, not implemented." << endl;
702 bool CVS::lockingToggleEnabled()
710 // Reverts to the version in CVS repository and
711 // gets the updated version from the repository.
712 CvsStatus status = getStatus();
715 if (vcstatus != NOLOCKING)
720 case LocallyModified: {
721 FileName f(owner_->absFileName());
723 update(File, FileName());
728 frontend::Alert::error(_("Revision control error."),
729 _("The current file is not in repository.\n"
730 "You have to check in the first revision before you can revert.")) ;
733 frontend::Alert::error(_("Revision control error."),
734 bformat(_("Bad status when checking in changes.\n"
744 // merge the current with the previous version
745 // in a reverse patch kind of way, so that the
746 // result is to revert the last changes.
747 lyxerr << "Sorry, not implemented." << endl;
751 bool CVS::undoLastEnabled()
757 void CVS::getLog(FileName const & tmpf)
759 doVCCommand("cvs log " + getTarget(File)
760 + " > " + quoteName(tmpf.toFilesystemEncoding()),
761 FileName(owner_->filePath()));
765 bool CVS::toggleReadOnlyEnabled()
771 string CVS::revisionInfo(LyXVC::RevisionInfo const info)
773 if (info == LyXVC::File)
779 bool CVS::prepareFileRevision(string const &, string &)
785 bool CVS::prepareFileRevisionEnabled()
791 /////////////////////////////////////////////////////////////////////
795 /////////////////////////////////////////////////////////////////////
797 SVN::SVN(FileName const & m, FileName const & f)
807 FileName const SVN::findFile(FileName const & file)
809 // First we look for the .svn/entries in the same dir
810 // where we have file.
811 FileName const entries(onlyPath(file.absFileName()) + "/.svn/entries");
812 string const tmpf = onlyFileName(file.absFileName());
813 LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under svn in `" << entries
814 << "' for `" << tmpf << '\'');
815 if (entries.isReadableFile()) {
816 // Ok we are at least in a SVN dir. Parse the .svn/entries
817 // and see if we can find this file. We do a fast and
819 ifstream ifs(entries.toFilesystemEncoding().c_str());
820 string line, oldline;
821 while (getline(ifs, line)) {
822 if (line == "dir" || line == "file")
823 LYXERR(Debug::LYXVC, "\tEntries: " << oldline);
824 if (oldline == tmpf && line == "file")
833 void SVN::scanMaster()
835 // vcstatus code is somewhat superflous, until we want
836 // to implement read-only toggle for svn.
837 vcstatus = NOLOCKING;
838 if (checkLockMode()) {
848 bool SVN::checkLockMode()
850 FileName tmpf = FileName::tempName("lyxvcout");
852 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
853 return N_("Error: Could not generate logfile.");
856 LYXERR(Debug::LYXVC, "Detecting locking mode...");
857 if (doVCCommandCall("svn proplist " + quoteName(file_.onlyFileName())
858 + " > " + quoteName(tmpf.toFilesystemEncoding()),
862 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
868 LYXERR(Debug::LYXVC, line);
869 if (contains(line, "svn:needs-lock"))
872 LYXERR(Debug::LYXVC, "Locking enabled: " << ret);
880 bool SVN::isLocked() const
883 return !file_.isReadOnly();
887 void SVN::registrer(string const & /*msg*/)
889 doVCCommand("svn add -q " + quoteName(onlyFileName(owner_->absFileName())),
890 FileName(owner_->filePath()));
894 string SVN::checkIn(string const & msg)
896 FileName tmpf = FileName::tempName("lyxvcout");
898 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
899 return N_("Error: Could not generate logfile.");
902 doVCCommand("svn commit -m \"" + msg + "\" "
903 + quoteName(onlyFileName(owner_->absFileName()))
904 + " > " + quoteName(tmpf.toFilesystemEncoding()),
905 FileName(owner_->filePath()));
908 string res = scanLogFile(tmpf, log);
910 frontend::Alert::error(_("Revision control error."),
911 _("Error when committing to repository.\n"
912 "You have to manually resolve the problem.\n"
913 "LyX will reopen the document after you press OK."));
915 fileLock(false, tmpf, log);
918 return log.empty() ? string() : "SVN: " + log;
922 bool SVN::checkInEnabled()
931 // FIXME Correctly return code should be checked instead of this.
932 // This would need another solution than just plain startscript.
933 // Hint from Andre': QProcess::readAllStandardError()...
934 string SVN::scanLogFile(FileName const & f, string & status)
936 ifstream ifs(f.toFilesystemEncoding().c_str());
941 LYXERR(Debug::LYXVC, line << "\n");
943 status += line + "; ";
944 if (prefixIs(line, "C ") || prefixIs(line, "CU ")
945 || contains(line, "Commit failed")) {
949 if (contains(line, "svn:needs-lock")) {
959 void SVN::fileLock(bool lock, FileName const & tmpf, string &status)
961 if (!locked_mode_ || (isLocked() == lock))
964 string const arg = lock ? "lock " : "unlock ";
965 doVCCommand("svn "+ arg + quoteName(onlyFileName(owner_->absFileName()))
966 + " > " + quoteName(tmpf.toFilesystemEncoding()),
967 FileName(owner_->filePath()));
969 // Lock error messages go unfortunately on stderr and are unreachible this way.
970 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
974 if (!line.empty()) status += line + "; ";
978 if (!isLocked() && lock)
979 frontend::Alert::error(_("Revision control error."),
980 _("Error while acquiring write lock.\n"
981 "Another user is most probably editing\n"
982 "the current document now!\n"
983 "Also check the access to the repository."));
984 if (isLocked() && !lock)
985 frontend::Alert::error(_("Revision control error."),
986 _("Error while releasing write lock.\n"
987 "Check the access to the repository."));
991 string SVN::checkOut()
993 FileName tmpf = FileName::tempName("lyxvcout");
995 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
996 return N_("Error: Could not generate logfile.");
999 doVCCommand("svn update --non-interactive " + quoteName(onlyFileName(owner_->absFileName()))
1000 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1001 FileName(owner_->filePath()));
1004 string const res = scanLogFile(tmpf, log);
1006 frontend::Alert::error(_("Revision control error."),
1007 bformat(_("Error when updating from repository.\n"
1008 "You have to manually resolve the conflicts NOW!\n'%1$s'.\n\n"
1009 "After pressing OK, LyX will try to reopen the resolved document."),
1010 from_local8bit(res)));
1012 fileLock(true, tmpf, log);
1015 return log.empty() ? string() : "SVN: " + log;
1019 bool SVN::checkOutEnabled()
1028 string SVN::repoUpdate()
1030 FileName tmpf = FileName::tempName("lyxvcout");
1032 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1033 return N_("Error: Could not generate logfile.");
1036 doVCCommand("svn diff " + quoteName(owner_->filePath())
1037 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1038 FileName(owner_->filePath()));
1039 docstring res = tmpf.fileContents("UTF-8");
1041 LYXERR(Debug::LYXVC, "Diff detected:\n" << res);
1042 docstring const file = from_utf8(owner_->filePath());
1043 docstring text = bformat(_("There were detected changes "
1044 "in the working directory:\n%1$s\n\n"
1045 "In case of file conflict version of the local directory files "
1046 "will be preferred."
1047 "\n\nContinue?"), file);
1048 int ret = frontend::Alert::prompt(_("Changes detected"),
1049 text, 0, 1, _("&Yes"), _("&No"), _("View &Log ..."));
1051 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + tmpf.absFileName()));
1052 ret = frontend::Alert::prompt(_("Changes detected"),
1053 text, 0, 1, _("&Yes"), _("&No"));
1054 hideDialogs("file", 0);
1062 // Reverting looks too harsh, see bug #6255.
1063 // doVCCommand("svn revert -R " + quoteName(owner_->filePath())
1064 // + " > " + quoteName(tmpf.toFilesystemEncoding()),
1065 // FileName(owner_->filePath()));
1066 // res = "Revert log:\n" + tmpf.fileContents("UTF-8");
1067 doVCCommand("svn update --accept mine-full " + quoteName(owner_->filePath())
1068 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1069 FileName(owner_->filePath()));
1070 res += "Update log:\n" + tmpf.fileContents("UTF-8");
1072 LYXERR(Debug::LYXVC, res);
1074 return to_utf8(res);
1078 bool SVN::repoUpdateEnabled()
1084 string SVN::lockingToggle()
1086 FileName tmpf = FileName::tempName("lyxvcout");
1088 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1089 return N_("Error: Could not generate logfile.");
1092 int ret = doVCCommand("svn proplist " + quoteName(onlyFileName(owner_->absFileName()))
1093 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1094 FileName(owner_->filePath()));
1099 string res = scanLogFile(tmpf, log);
1100 bool locking = contains(res, "svn:needs-lock");
1102 ret = doVCCommand("svn propset svn:needs-lock ON "
1103 + quoteName(onlyFileName(owner_->absFileName()))
1104 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1105 FileName(owner_->filePath()));
1107 ret = doVCCommand("svn propdel svn:needs-lock "
1108 + quoteName(onlyFileName(owner_->absFileName()))
1109 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1110 FileName(owner_->filePath()));
1115 frontend::Alert::warning(_("VCN File Locking"),
1116 (locking ? _("Locking property unset.") : _("Locking property set.")) + "\n"
1117 + _("Do not forget to commit the locking property into the repository."),
1120 return string("SVN: ") + N_("Locking property set.");
1124 bool SVN::lockingToggleEnabled()
1132 // Reverts to the version in CVS repository and
1133 // gets the updated version from the repository.
1134 string const fil = quoteName(onlyFileName(owner_->absFileName()));
1136 doVCCommand("svn revert -q " + fil,
1137 FileName(owner_->filePath()));
1138 owner_->markClean();
1142 void SVN::undoLast()
1144 // merge the current with the previous version
1145 // in a reverse patch kind of way, so that the
1146 // result is to revert the last changes.
1147 lyxerr << "Sorry, not implemented." << endl;
1151 bool SVN::undoLastEnabled()
1157 string SVN::revisionInfo(LyXVC::RevisionInfo const info)
1159 if (info == LyXVC::Tree) {
1160 if (rev_tree_cache_.empty())
1161 if (!getTreeRevisionInfo())
1162 rev_tree_cache_ = "?";
1163 if (rev_tree_cache_ == "?")
1166 return rev_tree_cache_;
1169 // fill the rest of the attributes for a single file
1170 if (rev_file_cache_.empty())
1171 if (!getFileRevisionInfo())
1172 rev_file_cache_ = "?";
1176 if (rev_file_cache_ == "?")
1178 return rev_file_cache_;
1180 return rev_author_cache_;
1182 return rev_date_cache_;
1184 return rev_time_cache_;
1193 bool SVN::getFileRevisionInfo()
1195 FileName tmpf = FileName::tempName("lyxvcout");
1197 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1198 return N_("Error: Could not generate logfile.");
1201 doVCCommand("svn info --xml " + quoteName(onlyFileName(owner_->absFileName()))
1202 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1203 FileName(owner_->filePath()));
1208 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1216 LYXERR(Debug::LYXVC, line);
1217 if (prefixIs(line, "<commit"))
1219 if (c && prefixIs(line, " revision=\"") && suffixIs(line, "\">")) {
1220 string l1 = subst(line, "revision=\"", "");
1221 string l2 = trim(subst(l1, "\">", ""));
1223 rev_file_cache_ = rev = l2;
1225 if (c && prefixIs(line, "<author>") && suffixIs(line, "</author>")) {
1226 string l1 = subst(line, "<author>", "");
1227 string l2 = subst(l1, "</author>", "");
1228 rev_author_cache_ = l2;
1230 if (c && prefixIs(line, "<date>") && suffixIs(line, "</date>")) {
1231 string l1 = subst(line, "<date>", "");
1232 string l2 = subst(l1, "</date>", "");
1233 l2 = split(l2, l1, 'T');
1234 rev_date_cache_ = l1;
1235 l2 = split(l2, l1, '.');
1236 rev_time_cache_ = l1;
1242 return !rev.empty();
1246 bool SVN::getTreeRevisionInfo()
1248 FileName tmpf = FileName::tempName("lyxvcout");
1250 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1251 return N_("Error: Could not generate logfile.");
1254 doVCCommand("svnversion -n . > " + quoteName(tmpf.toFilesystemEncoding()),
1255 FileName(owner_->filePath()));
1260 // only first line in case something bad happens.
1261 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1267 rev_tree_cache_ = line;
1268 return !line.empty();
1272 void SVN::getLog(FileName const & tmpf)
1274 doVCCommand("svn log " + quoteName(onlyFileName(owner_->absFileName()))
1275 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1276 FileName(owner_->filePath()));
1280 bool SVN::prepareFileRevision(string const & revis, string & f)
1282 if (!isStrInt(revis))
1285 int rev = convert<int>(revis);
1287 if (!getFileRevisionInfo())
1290 rev = convert<int>(rev_file_cache_);
1291 // go back for minus rev
1293 rev = rev + convert<int>(rev_file_cache_);
1298 string revname = convert<string>(rev);
1299 FileName tmpf = FileName::tempName("lyxvcrev_" + revname + "_");
1301 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1302 return N_("Error: Could not generate logfile.");
1305 doVCCommand("svn cat -r " + revname + " "
1306 + quoteName(onlyFileName(owner_->absFileName()))
1307 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1308 FileName(owner_->filePath()));
1309 if (tmpf.isFileEmpty())
1312 f = tmpf.absFileName();
1317 bool SVN::prepareFileRevisionEnabled()
1324 bool SVN::toggleReadOnlyEnabled()