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 return quoteName(owner_->filePath());
448 return quoteName(onlyFileName(owner_->absFileName()));
454 docstring CVS::toString(CvsStatus status) const
458 return _("Up-to-date");
459 case LocallyModified:
460 return _("Locally Modified");
462 return _("Locally Added");
464 return _("Needs Merge");
466 return _("Needs Checkout");
468 return _("No CVS file");
470 return _("Cannot retrieve CVS status");
476 CVS::CvsStatus CVS::getStatus()
478 FileName tmpf = FileName::tempName("lyxvcout");
480 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
484 if (doVCCommand("cvs status " + getTarget(File)
485 + " > " + quoteName(tmpf.toFilesystemEncoding()),
486 FileName(owner_->filePath()))) {
491 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
492 CvsStatus status = NoCvsFile;
497 LYXERR(Debug::LYXVC, line << "\n");
498 if (prefixIs(line, "File:")) {
499 if (contains(line, "Up-to-date"))
501 else if (contains(line, "Locally Modified"))
502 status = LocallyModified;
503 else if (contains(line, "Locally Added"))
504 status = LocallyAdded;
505 else if (contains(line, "Needs Merge"))
507 else if (contains(line, "Needs Checkout"))
508 status = NeedsCheckout;
516 void CVS::registrer(string const & msg)
518 doVCCommand("cvs -q add -m \"" + msg + "\" "
520 FileName(owner_->filePath()));
524 void CVS::getDiff(OperationMode opmode, FileName const & tmpf)
526 doVCCommand("cvs diff " + getTarget(opmode)
527 + " > " + quoteName(tmpf.toFilesystemEncoding()),
528 FileName(owner_->filePath()), false);
535 return doVCCommand("cvs -q edit " + getTarget(File),
536 FileName(owner_->filePath()));
543 return doVCCommand("cvs -q unedit " + getTarget(File),
544 FileName(owner_->filePath()));
548 int CVS::update(OperationMode opmode, FileName const & tmpf)
550 string const redirection = tmpf.empty() ? ""
551 : " > " + quoteName(tmpf.toFilesystemEncoding());
553 return doVCCommand("cvs -q update "
554 + getTarget(opmode) + redirection,
555 FileName(owner_->filePath()));
559 string CVS::scanLogFile(FileName const & f, string & status)
561 ifstream ifs(f.toFilesystemEncoding().c_str());
566 LYXERR(Debug::LYXVC, line << "\n");
568 status += line + "; ";
569 if (prefixIs(line, "C ")) {
579 string CVS::checkIn(string const & msg)
581 CvsStatus status = getStatus();
584 if (vcstatus != NOLOCKING)
586 return "CVS: Proceeded";
587 case LocallyModified:
589 int rc = doVCCommand("cvs -q commit -m \"" + msg + "\" "
591 FileName(owner_->filePath()));
592 return rc ? string() : "CVS: Proceeded";
596 frontend::Alert::error(_("Revision control error."),
597 _("The repository version is newer then the current check out.\n"
598 "You have to update from repository first or revert your changes.")) ;
601 frontend::Alert::error(_("Revision control error."),
602 bformat(_("Bad status when checking in changes.\n"
611 bool CVS::isLocked() const
613 FileName fn(owner_->absFileName());
615 return !fn.isReadOnly();
619 bool CVS::checkInEnabled()
621 if (vcstatus != NOLOCKING)
628 bool CVS::isCheckInWithConfirmation()
630 CvsStatus status = getStatus();
631 return status == LocallyModified || status == LocallyAdded;
635 string CVS::checkOut()
637 if (vcstatus != NOLOCKING && edit())
639 FileName tmpf = FileName::tempName("lyxvcout");
641 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
645 int rc = update(File, tmpf);
647 string const res = scanLogFile(tmpf, log);
649 frontend::Alert::error(_("Revision control error."),
650 bformat(_("Error when updating from repository.\n"
651 "You have to manually resolve the conflicts NOW!\n'%1$s'.\n\n"
652 "After pressing OK, LyX will try to reopen the resolved document."),
653 from_local8bit(res)));
656 return rc ? string() : log.empty() ? "CVS: Proceeded" : "CVS: " + log;
660 bool CVS::checkOutEnabled()
662 if (vcstatus != NOLOCKING)
669 string CVS::repoUpdate()
671 FileName tmpf = FileName::tempName("lyxvcout");
673 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
677 getDiff(Directory, tmpf);
678 docstring res = tmpf.fileContents("UTF-8");
680 LYXERR(Debug::LYXVC, "Diff detected:\n" << res);
681 docstring const file = from_utf8(owner_->filePath());
682 docstring text = bformat(_("There were detected changes "
683 "in the working directory:\n%1$s\n\n"
684 "In case of file conflict you have to resolve them "
685 "manually or revert to repository version later."), file);
686 int ret = frontend::Alert::prompt(_("Changes detected"),
687 text, 0, 1, _("&Continue"), _("&Abort"), _("View &Log ..."));
689 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + tmpf.absFileName()));
690 ret = frontend::Alert::prompt(_("Changes detected"),
691 text, 0, 1, _("&Continue"), _("&Abort"));
692 hideDialogs("file", 0);
700 int rc = update(Directory, tmpf);
701 res += "Update log:\n" + tmpf.fileContents("UTF-8");
704 LYXERR(Debug::LYXVC, res);
705 return rc ? string() : "CVS: Proceeded" ;
709 bool CVS::repoUpdateEnabled()
715 string CVS::lockingToggle()
717 lyxerr << "Sorry, not implemented." << endl;
722 bool CVS::lockingToggleEnabled()
728 bool CVS::isRevertWithConfirmation()
730 CvsStatus status = getStatus();
731 return !owner_->isClean() || status == LocallyModified || status == NeedsMerge;
737 // Reverts to the version in CVS repository and
738 // gets the updated version from the repository.
739 CvsStatus status = getStatus();
742 if (vcstatus != NOLOCKING)
747 case LocallyModified: {
748 FileName f(owner_->absFileName());
750 update(File, FileName());
755 docstring const file = owner_->fileName().displayName(20);
756 frontend::Alert::error(_("Revision control error."),
757 bformat(_("The document %1$s is not in repository.\n"
758 "You have to check in the first revision before you can revert."),
763 docstring const file = owner_->fileName().displayName(20);
764 frontend::Alert::error(_("Revision control error."),
765 bformat(_("Cannot revert document %1$s to repository version.\n"
766 "The status '%2$s' is unexpected."),
767 file, toString(status)));
776 // merge the current with the previous version
777 // in a reverse patch kind of way, so that the
778 // result is to revert the last changes.
779 lyxerr << "Sorry, not implemented." << endl;
783 bool CVS::undoLastEnabled()
789 void CVS::getLog(FileName const & tmpf)
791 doVCCommand("cvs log " + getTarget(File)
792 + " > " + quoteName(tmpf.toFilesystemEncoding()),
793 FileName(owner_->filePath()));
797 bool CVS::toggleReadOnlyEnabled()
803 string CVS::revisionInfo(LyXVC::RevisionInfo const info)
805 if (info == LyXVC::File)
811 bool CVS::prepareFileRevision(string const &, string &)
817 bool CVS::prepareFileRevisionEnabled()
823 /////////////////////////////////////////////////////////////////////
827 /////////////////////////////////////////////////////////////////////
829 SVN::SVN(FileName const & m, FileName const & f)
839 FileName const SVN::findFile(FileName const & file)
841 // First we look for the .svn/entries in the same dir
842 // where we have file.
843 FileName const entries(onlyPath(file.absFileName()) + "/.svn/entries");
844 string const tmpf = onlyFileName(file.absFileName());
845 LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under svn in `" << entries
846 << "' for `" << tmpf << '\'');
847 if (entries.isReadableFile()) {
848 // Ok we are at least in a SVN dir. Parse the .svn/entries
849 // and see if we can find this file. We do a fast and
851 ifstream ifs(entries.toFilesystemEncoding().c_str());
852 string line, oldline;
853 while (getline(ifs, line)) {
854 if (line == "dir" || line == "file")
855 LYXERR(Debug::LYXVC, "\tEntries: " << oldline);
856 if (oldline == tmpf && line == "file")
865 void SVN::scanMaster()
867 // vcstatus code is somewhat superflous, until we want
868 // to implement read-only toggle for svn.
869 vcstatus = NOLOCKING;
870 if (checkLockMode()) {
880 bool SVN::checkLockMode()
882 FileName tmpf = FileName::tempName("lyxvcout");
884 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
885 return N_("Error: Could not generate logfile.");
888 LYXERR(Debug::LYXVC, "Detecting locking mode...");
889 if (doVCCommandCall("svn proplist " + quoteName(file_.onlyFileName())
890 + " > " + quoteName(tmpf.toFilesystemEncoding()),
894 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
900 LYXERR(Debug::LYXVC, line);
901 if (contains(line, "svn:needs-lock"))
904 LYXERR(Debug::LYXVC, "Locking enabled: " << ret);
912 bool SVN::isLocked() const
915 return !file_.isReadOnly();
919 void SVN::registrer(string const & /*msg*/)
921 doVCCommand("svn add -q " + quoteName(onlyFileName(owner_->absFileName())),
922 FileName(owner_->filePath()));
926 string SVN::checkIn(string const & msg)
928 FileName tmpf = FileName::tempName("lyxvcout");
930 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
931 return N_("Error: Could not generate logfile.");
934 doVCCommand("svn commit -m \"" + msg + "\" "
935 + quoteName(onlyFileName(owner_->absFileName()))
936 + " > " + quoteName(tmpf.toFilesystemEncoding()),
937 FileName(owner_->filePath()));
940 string res = scanLogFile(tmpf, log);
942 frontend::Alert::error(_("Revision control error."),
943 _("Error when committing to repository.\n"
944 "You have to manually resolve the problem.\n"
945 "LyX will reopen the document after you press OK."));
947 fileLock(false, tmpf, log);
950 return log.empty() ? string() : "SVN: " + log;
954 bool SVN::checkInEnabled()
963 bool SVN::isCheckInWithConfirmation()
970 // FIXME Correctly return code should be checked instead of this.
971 // This would need another solution than just plain startscript.
972 // Hint from Andre': QProcess::readAllStandardError()...
973 string SVN::scanLogFile(FileName const & f, string & status)
975 ifstream ifs(f.toFilesystemEncoding().c_str());
980 LYXERR(Debug::LYXVC, line << "\n");
982 status += line + "; ";
983 if (prefixIs(line, "C ") || prefixIs(line, "CU ")
984 || contains(line, "Commit failed")) {
988 if (contains(line, "svn:needs-lock")) {
998 void SVN::fileLock(bool lock, FileName const & tmpf, string &status)
1000 if (!locked_mode_ || (isLocked() == lock))
1003 string const arg = lock ? "lock " : "unlock ";
1004 doVCCommand("svn "+ arg + quoteName(onlyFileName(owner_->absFileName()))
1005 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1006 FileName(owner_->filePath()));
1008 // Lock error messages go unfortunately on stderr and are unreachible this way.
1009 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1013 if (!line.empty()) status += line + "; ";
1017 if (!isLocked() && lock)
1018 frontend::Alert::error(_("Revision control error."),
1019 _("Error while acquiring write lock.\n"
1020 "Another user is most probably editing\n"
1021 "the current document now!\n"
1022 "Also check the access to the repository."));
1023 if (isLocked() && !lock)
1024 frontend::Alert::error(_("Revision control error."),
1025 _("Error while releasing write lock.\n"
1026 "Check the access to the repository."));
1030 string SVN::checkOut()
1032 FileName tmpf = FileName::tempName("lyxvcout");
1034 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1035 return N_("Error: Could not generate logfile.");
1038 doVCCommand("svn update --non-interactive " + quoteName(onlyFileName(owner_->absFileName()))
1039 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1040 FileName(owner_->filePath()));
1043 string const res = scanLogFile(tmpf, log);
1045 frontend::Alert::error(_("Revision control error."),
1046 bformat(_("Error when updating from repository.\n"
1047 "You have to manually resolve the conflicts NOW!\n'%1$s'.\n\n"
1048 "After pressing OK, LyX will try to reopen the resolved document."),
1049 from_local8bit(res)));
1051 fileLock(true, tmpf, log);
1054 return log.empty() ? string() : "SVN: " + log;
1058 bool SVN::checkOutEnabled()
1067 string SVN::repoUpdate()
1069 FileName tmpf = FileName::tempName("lyxvcout");
1071 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1072 return N_("Error: Could not generate logfile.");
1075 doVCCommand("svn diff " + quoteName(owner_->filePath())
1076 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1077 FileName(owner_->filePath()));
1078 docstring res = tmpf.fileContents("UTF-8");
1080 LYXERR(Debug::LYXVC, "Diff detected:\n" << res);
1081 docstring const file = from_utf8(owner_->filePath());
1082 docstring text = bformat(_("There were detected changes "
1083 "in the working directory:\n%1$s\n\n"
1084 "In case of file conflict version of the local directory files "
1085 "will be preferred."
1086 "\n\nContinue?"), file);
1087 int ret = frontend::Alert::prompt(_("Changes detected"),
1088 text, 0, 1, _("&Yes"), _("&No"), _("View &Log ..."));
1090 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + tmpf.absFileName()));
1091 ret = frontend::Alert::prompt(_("Changes detected"),
1092 text, 0, 1, _("&Yes"), _("&No"));
1093 hideDialogs("file", 0);
1101 // Reverting looks too harsh, see bug #6255.
1102 // doVCCommand("svn revert -R " + quoteName(owner_->filePath())
1103 // + " > " + quoteName(tmpf.toFilesystemEncoding()),
1104 // FileName(owner_->filePath()));
1105 // res = "Revert log:\n" + tmpf.fileContents("UTF-8");
1106 doVCCommand("svn update --accept mine-full " + quoteName(owner_->filePath())
1107 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1108 FileName(owner_->filePath()));
1109 res += "Update log:\n" + tmpf.fileContents("UTF-8");
1111 LYXERR(Debug::LYXVC, res);
1113 return to_utf8(res);
1117 bool SVN::repoUpdateEnabled()
1123 string SVN::lockingToggle()
1125 FileName tmpf = FileName::tempName("lyxvcout");
1127 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1128 return N_("Error: Could not generate logfile.");
1131 int ret = doVCCommand("svn proplist " + quoteName(onlyFileName(owner_->absFileName()))
1132 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1133 FileName(owner_->filePath()));
1138 string res = scanLogFile(tmpf, log);
1139 bool locking = contains(res, "svn:needs-lock");
1141 ret = doVCCommand("svn propset svn:needs-lock ON "
1142 + quoteName(onlyFileName(owner_->absFileName()))
1143 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1144 FileName(owner_->filePath()));
1146 ret = doVCCommand("svn propdel svn:needs-lock "
1147 + quoteName(onlyFileName(owner_->absFileName()))
1148 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1149 FileName(owner_->filePath()));
1154 frontend::Alert::warning(_("VCN File Locking"),
1155 (locking ? _("Locking property unset.") : _("Locking property set.")) + "\n"
1156 + _("Do not forget to commit the locking property into the repository."),
1159 return string("SVN: ") + N_("Locking property set.");
1163 bool SVN::lockingToggleEnabled()
1171 // Reverts to the version in SVN repository and
1172 // gets the updated version from the repository.
1173 string const fil = quoteName(onlyFileName(owner_->absFileName()));
1175 doVCCommand("svn revert -q " + fil,
1176 FileName(owner_->filePath()));
1177 owner_->markClean();
1181 bool SVN::isRevertWithConfirmation()
1183 //FIXME owner && diff
1188 void SVN::undoLast()
1190 // merge the current with the previous version
1191 // in a reverse patch kind of way, so that the
1192 // result is to revert the last changes.
1193 lyxerr << "Sorry, not implemented." << endl;
1197 bool SVN::undoLastEnabled()
1203 string SVN::revisionInfo(LyXVC::RevisionInfo const info)
1205 if (info == LyXVC::Tree) {
1206 if (rev_tree_cache_.empty())
1207 if (!getTreeRevisionInfo())
1208 rev_tree_cache_ = "?";
1209 if (rev_tree_cache_ == "?")
1212 return rev_tree_cache_;
1215 // fill the rest of the attributes for a single file
1216 if (rev_file_cache_.empty())
1217 if (!getFileRevisionInfo())
1218 rev_file_cache_ = "?";
1222 if (rev_file_cache_ == "?")
1224 return rev_file_cache_;
1226 return rev_author_cache_;
1228 return rev_date_cache_;
1230 return rev_time_cache_;
1239 bool SVN::getFileRevisionInfo()
1241 FileName tmpf = FileName::tempName("lyxvcout");
1243 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1244 return N_("Error: Could not generate logfile.");
1247 doVCCommand("svn info --xml " + quoteName(onlyFileName(owner_->absFileName()))
1248 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1249 FileName(owner_->filePath()));
1254 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1262 LYXERR(Debug::LYXVC, line);
1263 if (prefixIs(line, "<commit"))
1265 if (c && prefixIs(line, " revision=\"") && suffixIs(line, "\">")) {
1266 string l1 = subst(line, "revision=\"", "");
1267 string l2 = trim(subst(l1, "\">", ""));
1269 rev_file_cache_ = rev = l2;
1271 if (c && prefixIs(line, "<author>") && suffixIs(line, "</author>")) {
1272 string l1 = subst(line, "<author>", "");
1273 string l2 = subst(l1, "</author>", "");
1274 rev_author_cache_ = l2;
1276 if (c && prefixIs(line, "<date>") && suffixIs(line, "</date>")) {
1277 string l1 = subst(line, "<date>", "");
1278 string l2 = subst(l1, "</date>", "");
1279 l2 = split(l2, l1, 'T');
1280 rev_date_cache_ = l1;
1281 l2 = split(l2, l1, '.');
1282 rev_time_cache_ = l1;
1288 return !rev.empty();
1292 bool SVN::getTreeRevisionInfo()
1294 FileName tmpf = FileName::tempName("lyxvcout");
1296 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1297 return N_("Error: Could not generate logfile.");
1300 doVCCommand("svnversion -n . > " + quoteName(tmpf.toFilesystemEncoding()),
1301 FileName(owner_->filePath()));
1306 // only first line in case something bad happens.
1307 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1313 rev_tree_cache_ = line;
1314 return !line.empty();
1318 void SVN::getLog(FileName const & tmpf)
1320 doVCCommand("svn log " + quoteName(onlyFileName(owner_->absFileName()))
1321 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1322 FileName(owner_->filePath()));
1326 bool SVN::prepareFileRevision(string const & revis, string & f)
1328 if (!isStrInt(revis))
1331 int rev = convert<int>(revis);
1333 if (!getFileRevisionInfo())
1336 rev = convert<int>(rev_file_cache_);
1337 // go back for minus rev
1339 rev = rev + convert<int>(rev_file_cache_);
1344 string revname = convert<string>(rev);
1345 FileName tmpf = FileName::tempName("lyxvcrev_" + revname + "_");
1347 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1348 return N_("Error: Could not generate logfile.");
1351 doVCCommand("svn cat -r " + revname + " "
1352 + quoteName(onlyFileName(owner_->absFileName()))
1353 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1354 FileName(owner_->filePath()));
1355 if (tmpf.isFileEmpty())
1358 f = tmpf.absFileName();
1363 bool SVN::prepareFileRevisionEnabled()
1370 bool SVN::toggleReadOnlyEnabled()