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)
369 have_rev_info_ = false;
374 FileName const CVS::findFile(FileName const & file)
376 // First we look for the CVS/Entries in the same dir
377 // where we have file.
378 FileName const entries(onlyPath(file.absFileName()) + "/CVS/Entries");
379 string const tmpf = '/' + onlyFileName(file.absFileName()) + '/';
380 LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under cvs in `" << entries
381 << "' for `" << tmpf << '\'');
382 if (entries.isReadableFile()) {
383 // Ok we are at least in a CVS dir. Parse the CVS/Entries
384 // and see if we can find this file. We do a fast and
386 ifstream ifs(entries.toFilesystemEncoding().c_str());
388 while (getline(ifs, line)) {
389 LYXERR(Debug::LYXVC, "\tEntries: " << line);
390 if (contains(line, tmpf))
398 void CVS::scanMaster()
400 LYXERR(Debug::LYXVC, "LyXVC::CVS: scanMaster. \n Checking: " << master_);
401 // Ok now we do the real scan...
402 ifstream ifs(master_.toFilesystemEncoding().c_str());
403 string name = onlyFileName(file_.absFileName());
404 string tmpf = '/' + name + '/';
405 LYXERR(Debug::LYXVC, "\tlooking for `" << tmpf << '\'');
407 static regex const reg("/(.*)/(.*)/(.*)/(.*)/(.*)");
408 while (getline(ifs, line)) {
409 LYXERR(Debug::LYXVC, "\t line: " << line);
410 if (contains(line, tmpf)) {
411 // Ok extract the fields.
414 regex_match(line, sm, reg);
416 //sm[0]; // whole matched string
418 version_ = sm.str(2);
419 string const file_date = sm.str(3);
422 //sm[5]; // tag or tagdate
423 if (file_.isReadableFile()) {
424 time_t mod = file_.lastModified();
425 string mod_date = rtrim(asctime(gmtime(&mod)), "\n");
426 LYXERR(Debug::LYXVC, "Date in Entries: `" << file_date
427 << "'\nModification date of file: `" << mod_date << '\'');
428 if (file_.isReadOnly()) {
429 // readonly checkout is unlocked
432 FileName bdir(addPath(master_.onlyPath().absFileName(),"Base"));
433 FileName base(addName(bdir.absFileName(),name));
434 // if base version is existent "cvs edit" was used to lock
435 vcstatus = base.isReadableFile() ? LOCKED : NOLOCKING;
438 vcstatus = NOLOCKING;
446 string const CVS::getTarget(OperationMode opmode) const
450 // in client server mode CVS does not like full path operand for directory operation
451 // since LyX switches to the repo dir "." is good enough as target
454 return quoteName(onlyFileName(owner_->absFileName()));
460 docstring CVS::toString(CvsStatus status) const
464 return _("Up-to-date");
465 case LocallyModified:
466 return _("Locally Modified");
468 return _("Locally Added");
470 return _("Needs Merge");
472 return _("Needs Checkout");
474 return _("No CVS file");
476 return _("Cannot retrieve CVS status");
482 int CVS::doVCCommandWithOutput(string const & cmd, FileName const & path,
483 FileName const & output, bool reportError)
485 string redirection = output.empty() ? "" : " > " + quoteName(output.toFilesystemEncoding());
486 return doVCCommand(cmd + redirection, path, reportError);
490 int CVS::doVCCommandCallWithOutput(std::string const & cmd,
491 support::FileName const & path,
492 support::FileName const & output)
494 string redirection = output.empty() ? "" : " > " + quoteName(output.toFilesystemEncoding());
495 return doVCCommandCall(cmd + redirection, path);
499 CVS::CvsStatus CVS::getStatus()
501 FileName tmpf = FileName::tempName("lyxvcout");
503 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
507 if (doVCCommandCallWithOutput("cvs status " + getTarget(File),
508 FileName(owner_->filePath()), tmpf)) {
513 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
514 CvsStatus status = NoCvsFile;
519 LYXERR(Debug::LYXVC, line << "\n");
520 if (prefixIs(line, "File:")) {
521 if (contains(line, "Up-to-date"))
523 else if (contains(line, "Locally Modified"))
524 status = LocallyModified;
525 else if (contains(line, "Locally Added"))
526 status = LocallyAdded;
527 else if (contains(line, "Needs Merge"))
529 else if (contains(line, "Needs Checkout"))
530 status = NeedsCheckout;
537 void CVS::getRevisionInfo()
541 have_rev_info_ = true;
542 FileName tmpf = FileName::tempName("lyxvcout");
544 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
548 int rc = doVCCommandCallWithOutput("cvs log -r" + version_
549 + " " + getTarget(File),
550 FileName(owner_->filePath()), tmpf);
553 LYXERR(Debug::LYXVC, "cvs log failed with exit code " << rc);
557 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
558 static regex const reg("date: (.*) (.*) (.*); author: (.*); state: (.*);(.*)");
563 LYXERR(Debug::LYXVC, line << "\n");
564 if (prefixIs(line, "date:")) {
566 regex_match(line, sm, reg);
567 //sm[0]; // whole matched string
568 rev_date_cache_ = sm[1];
569 rev_time_cache_ = sm[2];
570 //sm[3]; // GMT offset
571 rev_author_cache_ = sm[4];
576 if (rev_author_cache_.empty())
578 "Could not retrieve revision info for " << version_ <<
579 " of " << getTarget(File));
583 void CVS::registrer(string const & msg)
585 doVCCommand("cvs -q add -m \"" + msg + "\" "
587 FileName(owner_->filePath()));
591 void CVS::getDiff(OperationMode opmode, FileName const & tmpf)
593 doVCCommandWithOutput("cvs diff " + getTarget(opmode),
594 FileName(owner_->filePath()), tmpf, false);
601 return doVCCommand("cvs -q edit " + getTarget(File),
602 FileName(owner_->filePath()));
609 return doVCCommand("cvs -q unedit " + getTarget(File),
610 FileName(owner_->filePath()));
614 int CVS::update(OperationMode opmode, FileName const & tmpf)
616 return doVCCommandWithOutput("cvs -q update "
618 FileName(owner_->filePath()), tmpf, false);
622 string CVS::scanLogFile(FileName const & f, string & status)
624 ifstream ifs(f.toFilesystemEncoding().c_str());
629 LYXERR(Debug::LYXVC, line << "\n");
631 status += line + "; ";
632 if (prefixIs(line, "C ")) {
642 string CVS::checkIn(string const & msg)
644 CvsStatus status = getStatus();
647 if (vcstatus != NOLOCKING)
649 return "CVS: Proceeded";
650 case LocallyModified:
652 int rc = doVCCommand("cvs -q commit -m \"" + msg + "\" "
654 FileName(owner_->filePath()));
655 return rc ? string() : "CVS: Proceeded";
659 frontend::Alert::error(_("Revision control error."),
660 _("The repository version is newer then the current check out.\n"
661 "You have to update from repository first or revert your changes.")) ;
664 frontend::Alert::error(_("Revision control error."),
665 bformat(_("Bad status when checking in changes.\n"
674 bool CVS::isLocked() const
676 FileName fn(owner_->absFileName());
678 return !fn.isReadOnly();
682 bool CVS::checkInEnabled()
684 if (vcstatus != NOLOCKING)
691 bool CVS::isCheckInWithConfirmation()
693 CvsStatus status = getStatus();
694 return status == LocallyModified || status == LocallyAdded;
698 string CVS::checkOut()
700 if (vcstatus != NOLOCKING && edit())
702 FileName tmpf = FileName::tempName("lyxvcout");
704 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
708 int rc = update(File, tmpf);
710 string const res = scanLogFile(tmpf, log);
712 frontend::Alert::error(_("Revision control error."),
713 bformat(_("Error when updating from repository.\n"
714 "You have to manually resolve the conflicts NOW!\n'%1$s'.\n\n"
715 "After pressing OK, LyX will try to reopen the resolved document."),
716 from_local8bit(res)));
721 return rc ? string() : log.empty() ? "CVS: Proceeded" : "CVS: " + log;
725 bool CVS::checkOutEnabled()
727 if (vcstatus != NOLOCKING)
734 string CVS::repoUpdate()
736 FileName tmpf = FileName::tempName("lyxvcout");
738 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
742 getDiff(Directory, tmpf);
743 docstring res = tmpf.fileContents("UTF-8");
745 LYXERR(Debug::LYXVC, "Diff detected:\n" << res);
746 docstring const file = from_utf8(owner_->filePath());
747 docstring text = bformat(_("There were detected changes "
748 "in the working directory:\n%1$s\n\n"
749 "In case of file conflict you have to resolve them "
750 "manually or revert to repository version later."), file);
751 int ret = frontend::Alert::prompt(_("Changes detected"),
752 text, 0, 1, _("&Continue"), _("&Abort"), _("View &Log ..."));
754 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + tmpf.absFileName()));
755 ret = frontend::Alert::prompt(_("Changes detected"),
756 text, 0, 1, _("&Continue"), _("&Abort"));
757 hideDialogs("file", 0);
765 int rc = update(Directory, tmpf);
766 res += "Update log:\n" + tmpf.fileContents("UTF-8");
767 LYXERR(Debug::LYXVC, res);
770 string sres = scanLogFile(tmpf, log);
772 docstring const file = owner_->fileName().displayName(20);
773 frontend::Alert::error(_("Revision control error."),
774 bformat(_("Error when updating document %1$s from repository.\n"
775 "You have to manually resolve the conflicts NOW!\n'%2$s'.\n\n"
776 "After pressing OK, LyX will try to reopen the resolved document."),
777 file, from_local8bit(sres)));
783 return rc ? string() : log.empty() ? "CVS: Proceeded" : "CVS: " + log;
787 bool CVS::repoUpdateEnabled()
793 string CVS::lockingToggle()
795 lyxerr << "Sorry, not implemented." << endl;
800 bool CVS::lockingToggleEnabled()
806 bool CVS::isRevertWithConfirmation()
808 CvsStatus status = getStatus();
809 return !owner_->isClean() || status == LocallyModified || status == NeedsMerge;
815 // Reverts to the version in CVS repository and
816 // gets the updated version from the repository.
817 CvsStatus status = getStatus();
820 if (vcstatus != NOLOCKING)
825 case LocallyModified: {
826 FileName f(owner_->absFileName());
828 update(File, FileName());
833 docstring const file = owner_->fileName().displayName(20);
834 frontend::Alert::error(_("Revision control error."),
835 bformat(_("The document %1$s is not in repository.\n"
836 "You have to check in the first revision before you can revert."),
841 docstring const file = owner_->fileName().displayName(20);
842 frontend::Alert::error(_("Revision control error."),
843 bformat(_("Cannot revert document %1$s to repository version.\n"
844 "The status '%2$s' is unexpected."),
845 file, toString(status)));
854 // merge the current with the previous version
855 // in a reverse patch kind of way, so that the
856 // result is to revert the last changes.
857 lyxerr << "Sorry, not implemented." << endl;
861 bool CVS::undoLastEnabled()
867 void CVS::getLog(FileName const & tmpf)
869 doVCCommandWithOutput("cvs log " + getTarget(File),
870 FileName(owner_->filePath()),
875 bool CVS::toggleReadOnlyEnabled()
881 string CVS::revisionInfo(LyXVC::RevisionInfo const info)
883 if (!version_.empty()) {
889 return rev_author_cache_;
891 return rev_date_cache_;
893 return rev_time_cache_;
901 bool CVS::prepareFileRevision(string const &, string &)
907 bool CVS::prepareFileRevisionEnabled()
913 /////////////////////////////////////////////////////////////////////
917 /////////////////////////////////////////////////////////////////////
919 SVN::SVN(FileName const & m, FileName const & f)
929 FileName const SVN::findFile(FileName const & file)
931 // First we look for the .svn/entries in the same dir
932 // where we have file.
933 FileName const entries(onlyPath(file.absFileName()) + "/.svn/entries");
934 string const tmpf = onlyFileName(file.absFileName());
935 LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under svn in `" << entries
936 << "' for `" << tmpf << '\'');
937 if (entries.isReadableFile()) {
938 // Ok we are at least in a SVN dir. Parse the .svn/entries
939 // and see if we can find this file. We do a fast and
941 ifstream ifs(entries.toFilesystemEncoding().c_str());
942 string line, oldline;
943 while (getline(ifs, line)) {
944 if (line == "dir" || line == "file")
945 LYXERR(Debug::LYXVC, "\tEntries: " << oldline);
946 if (oldline == tmpf && line == "file")
955 void SVN::scanMaster()
957 // vcstatus code is somewhat superflous, until we want
958 // to implement read-only toggle for svn.
959 vcstatus = NOLOCKING;
960 if (checkLockMode()) {
970 bool SVN::checkLockMode()
972 FileName tmpf = FileName::tempName("lyxvcout");
974 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
975 return N_("Error: Could not generate logfile.");
978 LYXERR(Debug::LYXVC, "Detecting locking mode...");
979 if (doVCCommandCall("svn proplist " + quoteName(file_.onlyFileName())
980 + " > " + quoteName(tmpf.toFilesystemEncoding()),
984 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
990 LYXERR(Debug::LYXVC, line);
991 if (contains(line, "svn:needs-lock"))
994 LYXERR(Debug::LYXVC, "Locking enabled: " << ret);
1002 bool SVN::isLocked() const
1005 return !file_.isReadOnly();
1009 void SVN::registrer(string const & /*msg*/)
1011 doVCCommand("svn add -q " + quoteName(onlyFileName(owner_->absFileName())),
1012 FileName(owner_->filePath()));
1016 string SVN::checkIn(string const & msg)
1018 FileName tmpf = FileName::tempName("lyxvcout");
1020 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1021 return N_("Error: Could not generate logfile.");
1024 doVCCommand("svn commit -m \"" + msg + "\" "
1025 + quoteName(onlyFileName(owner_->absFileName()))
1026 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1027 FileName(owner_->filePath()));
1030 string res = scanLogFile(tmpf, log);
1032 frontend::Alert::error(_("Revision control error."),
1033 _("Error when committing to repository.\n"
1034 "You have to manually resolve the problem.\n"
1035 "LyX will reopen the document after you press OK."));
1037 fileLock(false, tmpf, log);
1040 return log.empty() ? string() : "SVN: " + log;
1044 bool SVN::checkInEnabled()
1053 bool SVN::isCheckInWithConfirmation()
1060 // FIXME Correctly return code should be checked instead of this.
1061 // This would need another solution than just plain startscript.
1062 // Hint from Andre': QProcess::readAllStandardError()...
1063 string SVN::scanLogFile(FileName const & f, string & status)
1065 ifstream ifs(f.toFilesystemEncoding().c_str());
1070 LYXERR(Debug::LYXVC, line << "\n");
1072 status += line + "; ";
1073 if (prefixIs(line, "C ") || prefixIs(line, "CU ")
1074 || contains(line, "Commit failed")) {
1078 if (contains(line, "svn:needs-lock")) {
1088 void SVN::fileLock(bool lock, FileName const & tmpf, string &status)
1090 if (!locked_mode_ || (isLocked() == lock))
1093 string const arg = lock ? "lock " : "unlock ";
1094 doVCCommand("svn "+ arg + quoteName(onlyFileName(owner_->absFileName()))
1095 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1096 FileName(owner_->filePath()));
1098 // Lock error messages go unfortunately on stderr and are unreachible this way.
1099 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1103 if (!line.empty()) status += line + "; ";
1107 if (!isLocked() && lock)
1108 frontend::Alert::error(_("Revision control error."),
1109 _("Error while acquiring write lock.\n"
1110 "Another user is most probably editing\n"
1111 "the current document now!\n"
1112 "Also check the access to the repository."));
1113 if (isLocked() && !lock)
1114 frontend::Alert::error(_("Revision control error."),
1115 _("Error while releasing write lock.\n"
1116 "Check the access to the repository."));
1120 string SVN::checkOut()
1122 FileName tmpf = FileName::tempName("lyxvcout");
1124 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1125 return N_("Error: Could not generate logfile.");
1128 doVCCommand("svn update --non-interactive " + quoteName(onlyFileName(owner_->absFileName()))
1129 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1130 FileName(owner_->filePath()));
1133 string const res = scanLogFile(tmpf, log);
1135 frontend::Alert::error(_("Revision control error."),
1136 bformat(_("Error when updating from repository.\n"
1137 "You have to manually resolve the conflicts NOW!\n'%1$s'.\n\n"
1138 "After pressing OK, LyX will try to reopen the resolved document."),
1139 from_local8bit(res)));
1141 fileLock(true, tmpf, log);
1144 return log.empty() ? string() : "SVN: " + log;
1148 bool SVN::checkOutEnabled()
1157 string SVN::repoUpdate()
1159 FileName tmpf = FileName::tempName("lyxvcout");
1161 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1162 return N_("Error: Could not generate logfile.");
1165 doVCCommand("svn diff " + quoteName(owner_->filePath())
1166 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1167 FileName(owner_->filePath()));
1168 docstring res = tmpf.fileContents("UTF-8");
1170 LYXERR(Debug::LYXVC, "Diff detected:\n" << res);
1171 docstring const file = from_utf8(owner_->filePath());
1172 docstring text = bformat(_("There were detected changes "
1173 "in the working directory:\n%1$s\n\n"
1174 "In case of file conflict version of the local directory files "
1175 "will be preferred."
1176 "\n\nContinue?"), file);
1177 int ret = frontend::Alert::prompt(_("Changes detected"),
1178 text, 0, 1, _("&Yes"), _("&No"), _("View &Log ..."));
1180 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + tmpf.absFileName()));
1181 ret = frontend::Alert::prompt(_("Changes detected"),
1182 text, 0, 1, _("&Yes"), _("&No"));
1183 hideDialogs("file", 0);
1191 // Reverting looks too harsh, see bug #6255.
1192 // doVCCommand("svn revert -R " + quoteName(owner_->filePath())
1193 // + " > " + quoteName(tmpf.toFilesystemEncoding()),
1194 // FileName(owner_->filePath()));
1195 // res = "Revert log:\n" + tmpf.fileContents("UTF-8");
1196 doVCCommand("svn update --accept mine-full " + quoteName(owner_->filePath())
1197 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1198 FileName(owner_->filePath()));
1199 res += "Update log:\n" + tmpf.fileContents("UTF-8");
1201 LYXERR(Debug::LYXVC, res);
1203 return to_utf8(res);
1207 bool SVN::repoUpdateEnabled()
1213 string SVN::lockingToggle()
1215 FileName tmpf = FileName::tempName("lyxvcout");
1217 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1218 return N_("Error: Could not generate logfile.");
1221 int ret = doVCCommand("svn proplist " + quoteName(onlyFileName(owner_->absFileName()))
1222 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1223 FileName(owner_->filePath()));
1228 string res = scanLogFile(tmpf, log);
1229 bool locking = contains(res, "svn:needs-lock");
1231 ret = doVCCommand("svn propset svn:needs-lock ON "
1232 + quoteName(onlyFileName(owner_->absFileName()))
1233 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1234 FileName(owner_->filePath()));
1236 ret = doVCCommand("svn propdel svn:needs-lock "
1237 + quoteName(onlyFileName(owner_->absFileName()))
1238 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1239 FileName(owner_->filePath()));
1244 frontend::Alert::warning(_("VCN File Locking"),
1245 (locking ? _("Locking property unset.") : _("Locking property set.")) + "\n"
1246 + _("Do not forget to commit the locking property into the repository."),
1249 return string("SVN: ") + N_("Locking property set.");
1253 bool SVN::lockingToggleEnabled()
1261 // Reverts to the version in SVN repository and
1262 // gets the updated version from the repository.
1263 string const fil = quoteName(onlyFileName(owner_->absFileName()));
1265 doVCCommand("svn revert -q " + fil,
1266 FileName(owner_->filePath()));
1267 owner_->markClean();
1271 bool SVN::isRevertWithConfirmation()
1273 //FIXME owner && diff
1278 void SVN::undoLast()
1280 // merge the current with the previous version
1281 // in a reverse patch kind of way, so that the
1282 // result is to revert the last changes.
1283 lyxerr << "Sorry, not implemented." << endl;
1287 bool SVN::undoLastEnabled()
1293 string SVN::revisionInfo(LyXVC::RevisionInfo const info)
1295 if (info == LyXVC::Tree) {
1296 if (rev_tree_cache_.empty())
1297 if (!getTreeRevisionInfo())
1298 rev_tree_cache_ = "?";
1299 if (rev_tree_cache_ == "?")
1302 return rev_tree_cache_;
1305 // fill the rest of the attributes for a single file
1306 if (rev_file_cache_.empty())
1307 if (!getFileRevisionInfo())
1308 rev_file_cache_ = "?";
1312 if (rev_file_cache_ == "?")
1314 return rev_file_cache_;
1316 return rev_author_cache_;
1318 return rev_date_cache_;
1320 return rev_time_cache_;
1329 bool SVN::getFileRevisionInfo()
1331 FileName tmpf = FileName::tempName("lyxvcout");
1333 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1334 return N_("Error: Could not generate logfile.");
1337 doVCCommand("svn info --xml " + quoteName(onlyFileName(owner_->absFileName()))
1338 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1339 FileName(owner_->filePath()));
1344 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1352 LYXERR(Debug::LYXVC, line);
1353 if (prefixIs(line, "<commit"))
1355 if (c && prefixIs(line, " revision=\"") && suffixIs(line, "\">")) {
1356 string l1 = subst(line, "revision=\"", "");
1357 string l2 = trim(subst(l1, "\">", ""));
1359 rev_file_cache_ = rev = l2;
1361 if (c && prefixIs(line, "<author>") && suffixIs(line, "</author>")) {
1362 string l1 = subst(line, "<author>", "");
1363 string l2 = subst(l1, "</author>", "");
1364 rev_author_cache_ = l2;
1366 if (c && prefixIs(line, "<date>") && suffixIs(line, "</date>")) {
1367 string l1 = subst(line, "<date>", "");
1368 string l2 = subst(l1, "</date>", "");
1369 l2 = split(l2, l1, 'T');
1370 rev_date_cache_ = l1;
1371 l2 = split(l2, l1, '.');
1372 rev_time_cache_ = l1;
1378 return !rev.empty();
1382 bool SVN::getTreeRevisionInfo()
1384 FileName tmpf = FileName::tempName("lyxvcout");
1386 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1387 return N_("Error: Could not generate logfile.");
1390 doVCCommand("svnversion -n . > " + quoteName(tmpf.toFilesystemEncoding()),
1391 FileName(owner_->filePath()));
1396 // only first line in case something bad happens.
1397 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1403 rev_tree_cache_ = line;
1404 return !line.empty();
1408 void SVN::getLog(FileName const & tmpf)
1410 doVCCommand("svn log " + quoteName(onlyFileName(owner_->absFileName()))
1411 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1412 FileName(owner_->filePath()));
1416 bool SVN::prepareFileRevision(string const & revis, string & f)
1418 if (!isStrInt(revis))
1421 int rev = convert<int>(revis);
1423 if (!getFileRevisionInfo())
1426 rev = convert<int>(rev_file_cache_);
1427 // go back for minus rev
1429 rev = rev + convert<int>(rev_file_cache_);
1434 string revname = convert<string>(rev);
1435 FileName tmpf = FileName::tempName("lyxvcrev_" + revname + "_");
1437 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1438 return N_("Error: Could not generate logfile.");
1441 doVCCommand("svn cat -r " + revname + " "
1442 + quoteName(onlyFileName(owner_->absFileName()))
1443 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1444 FileName(owner_->filePath()));
1445 if (tmpf.isFileEmpty())
1448 f = tmpf.absFileName();
1453 bool SVN::prepareFileRevisionEnabled()
1460 bool SVN::toggleReadOnlyEnabled()