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 bool RCS::isCheckInWithConfirmation()
201 // FIXME one day common getDiff for all backends
203 // if (getDiff(file, diff) && diff.empty())
206 FileName tmpf = FileName::tempName("lyxvcout");
208 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
212 doVCCommandCall("rcsdiff " + quoteName(owner_->absFileName())
213 + " > " + quoteName(tmpf.toFilesystemEncoding()),
214 FileName(owner_->filePath()));
216 docstring diff = tmpf.fileContents("UTF-8");
226 string RCS::checkOut()
229 int ret = doVCCommand("co -q -l " + quoteName(onlyFileName(owner_->absFileName())),
230 FileName(owner_->filePath()));
231 return ret ? string() : "RCS: Proceeded";
235 bool RCS::checkOutEnabled()
237 return owner_ && owner_->isReadonly();
241 string RCS::repoUpdate()
243 lyxerr << "Sorry, not implemented." << endl;
248 bool RCS::repoUpdateEnabled()
254 string RCS::lockingToggle()
256 //FIXME this might be actually possible, study rcs -U, rcs -L.
257 //State should be easy to get inside scanMaster.
258 //It would fix #4370 and make rcs/svn usage even more closer.
259 lyxerr << "Sorry, not implemented." << endl;
264 bool RCS::lockingToggleEnabled()
272 doVCCommand("co -f -u" + version_ + " "
273 + quoteName(onlyFileName(owner_->absFileName())),
274 FileName(owner_->filePath()));
275 // We ignore changes and just reload!
280 bool RCS::isRevertWithConfirmation()
282 //FIXME owner && diff ?
289 LYXERR(Debug::LYXVC, "LyXVC: undoLast");
290 doVCCommand("rcs -o" + version_ + " "
291 + quoteName(onlyFileName(owner_->absFileName())),
292 FileName(owner_->filePath()));
296 bool RCS::undoLastEnabled()
302 void RCS::getLog(FileName const & tmpf)
304 doVCCommand("rlog " + quoteName(onlyFileName(owner_->absFileName()))
305 + " > " + quoteName(tmpf.toFilesystemEncoding()),
306 FileName(owner_->filePath()));
310 bool RCS::toggleReadOnlyEnabled()
312 // This got broken somewhere along lfuns dispatch reorganization.
313 // reloadBuffer would be needed after this, but thats problematic
314 // since we are inside Buffer::dispatch.
319 string RCS::revisionInfo(LyXVC::RevisionInfo const info)
321 if (info == LyXVC::File)
327 bool RCS::prepareFileRevision(string const &revis, string & f)
332 int back = convert<int>(rev);
333 // if positive use as the last number in the whole revision string
336 rsplit(version_, base , '.' );
337 rev = base + "." + rev;
341 // we care about the last number from revision string
342 // in case of backward indexing
345 cur = rsplit(version_, base , '.' );
348 int want = convert<int>(cur) + back;
352 rev = base + "." + convert<string>(want);
356 FileName tmpf = FileName::tempName("lyxvcrev_" + rev + "_");
358 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
359 return N_("Error: Could not generate logfile.");
362 doVCCommand("co -p" + rev + " "
363 + quoteName(onlyFileName(owner_->absFileName()))
364 + " > " + quoteName(tmpf.toFilesystemEncoding()),
365 FileName(owner_->filePath()));
366 if (tmpf.isFileEmpty())
369 f = tmpf.absFileName();
374 bool RCS::prepareFileRevisionEnabled()
380 /////////////////////////////////////////////////////////////////////
384 /////////////////////////////////////////////////////////////////////
386 CVS::CVS(FileName const & m, FileName const & f)
390 have_rev_info_ = false;
395 FileName const CVS::findFile(FileName const & file)
397 // First we look for the CVS/Entries in the same dir
398 // where we have file.
399 FileName const entries(onlyPath(file.absFileName()) + "/CVS/Entries");
400 string const tmpf = '/' + onlyFileName(file.absFileName()) + '/';
401 LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under cvs in `" << entries
402 << "' for `" << tmpf << '\'');
403 if (entries.isReadableFile()) {
404 // Ok we are at least in a CVS dir. Parse the CVS/Entries
405 // and see if we can find this file. We do a fast and
407 ifstream ifs(entries.toFilesystemEncoding().c_str());
409 while (getline(ifs, line)) {
410 LYXERR(Debug::LYXVC, "\tEntries: " << line);
411 if (contains(line, tmpf))
419 void CVS::scanMaster()
421 LYXERR(Debug::LYXVC, "LyXVC::CVS: scanMaster. \n Checking: " << master_);
422 // Ok now we do the real scan...
423 ifstream ifs(master_.toFilesystemEncoding().c_str());
424 string name = onlyFileName(file_.absFileName());
425 string tmpf = '/' + name + '/';
426 LYXERR(Debug::LYXVC, "\tlooking for `" << tmpf << '\'');
428 static regex const reg("/(.*)/(.*)/(.*)/(.*)/(.*)");
429 while (getline(ifs, line)) {
430 LYXERR(Debug::LYXVC, "\t line: " << line);
431 if (contains(line, tmpf)) {
432 // Ok extract the fields.
435 regex_match(line, sm, reg);
437 //sm[0]; // whole matched string
439 version_ = sm.str(2);
440 string const file_date = sm.str(3);
443 //sm[5]; // tag or tagdate
444 if (file_.isReadableFile()) {
445 time_t mod = file_.lastModified();
446 string mod_date = rtrim(asctime(gmtime(&mod)), "\n");
447 LYXERR(Debug::LYXVC, "Date in Entries: `" << file_date
448 << "'\nModification date of file: `" << mod_date << '\'');
449 if (file_.isReadOnly()) {
450 // readonly checkout is unlocked
453 FileName bdir(addPath(master_.onlyPath().absFileName(),"Base"));
454 FileName base(addName(bdir.absFileName(),name));
455 // if base version is existent "cvs edit" was used to lock
456 vcstatus = base.isReadableFile() ? LOCKED : NOLOCKING;
459 vcstatus = NOLOCKING;
467 string const CVS::getTarget(OperationMode opmode) const
471 // in client server mode CVS does not like full path operand for directory operation
472 // since LyX switches to the repo dir "." is good enough as target
475 return quoteName(onlyFileName(owner_->absFileName()));
481 docstring CVS::toString(CvsStatus status) const
485 return _("Up-to-date");
486 case LocallyModified:
487 return _("Locally Modified");
489 return _("Locally Added");
491 return _("Needs Merge");
493 return _("Needs Checkout");
495 return _("No CVS file");
497 return _("Cannot retrieve CVS status");
503 int CVS::doVCCommandWithOutput(string const & cmd, FileName const & path,
504 FileName const & output, bool reportError)
506 string redirection = output.empty() ? "" : " > " + quoteName(output.toFilesystemEncoding());
507 return doVCCommand(cmd + redirection, path, reportError);
511 int CVS::doVCCommandCallWithOutput(std::string const & cmd,
512 support::FileName const & path,
513 support::FileName const & output)
515 string redirection = output.empty() ? "" : " > " + quoteName(output.toFilesystemEncoding());
516 return doVCCommandCall(cmd + redirection, path);
520 CVS::CvsStatus CVS::getStatus()
522 FileName tmpf = FileName::tempName("lyxvcout");
524 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
528 if (doVCCommandCallWithOutput("cvs status " + getTarget(File),
529 FileName(owner_->filePath()), tmpf)) {
534 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
535 CvsStatus status = NoCvsFile;
540 LYXERR(Debug::LYXVC, line << "\n");
541 if (prefixIs(line, "File:")) {
542 if (contains(line, "Up-to-date"))
544 else if (contains(line, "Locally Modified"))
545 status = LocallyModified;
546 else if (contains(line, "Locally Added"))
547 status = LocallyAdded;
548 else if (contains(line, "Needs Merge"))
550 else if (contains(line, "Needs Checkout"))
551 status = NeedsCheckout;
558 void CVS::getRevisionInfo()
562 have_rev_info_ = true;
563 FileName tmpf = FileName::tempName("lyxvcout");
565 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
569 int rc = doVCCommandCallWithOutput("cvs log -r" + version_
570 + " " + getTarget(File),
571 FileName(owner_->filePath()), tmpf);
574 LYXERR(Debug::LYXVC, "cvs log failed with exit code " << rc);
578 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
579 static regex const reg("date: (.*) (.*) (.*); author: (.*); state: (.*);(.*)");
584 LYXERR(Debug::LYXVC, line << "\n");
585 if (prefixIs(line, "date:")) {
587 regex_match(line, sm, reg);
588 //sm[0]; // whole matched string
589 rev_date_cache_ = sm[1];
590 rev_time_cache_ = sm[2];
591 //sm[3]; // GMT offset
592 rev_author_cache_ = sm[4];
597 if (rev_author_cache_.empty())
599 "Could not retrieve revision info for " << version_ <<
600 " of " << getTarget(File));
604 void CVS::registrer(string const & msg)
606 doVCCommand("cvs -q add -m \"" + msg + "\" "
608 FileName(owner_->filePath()));
612 void CVS::getDiff(OperationMode opmode, FileName const & tmpf)
614 doVCCommandWithOutput("cvs diff " + getTarget(opmode),
615 FileName(owner_->filePath()), tmpf, false);
622 return doVCCommand("cvs -q edit " + getTarget(File),
623 FileName(owner_->filePath()));
630 return doVCCommand("cvs -q unedit " + getTarget(File),
631 FileName(owner_->filePath()));
635 int CVS::update(OperationMode opmode, FileName const & tmpf)
637 return doVCCommandWithOutput("cvs -q update "
639 FileName(owner_->filePath()), tmpf, false);
643 string CVS::scanLogFile(FileName const & f, string & status)
645 ifstream ifs(f.toFilesystemEncoding().c_str());
650 LYXERR(Debug::LYXVC, line << "\n");
652 status += line + "; ";
653 if (prefixIs(line, "C ")) {
663 string CVS::checkIn(string const & msg)
665 CvsStatus status = getStatus();
668 if (vcstatus != NOLOCKING)
670 return "CVS: Proceeded";
671 case LocallyModified:
673 int rc = doVCCommand("cvs -q commit -m \"" + msg + "\" "
675 FileName(owner_->filePath()));
676 return rc ? string() : "CVS: Proceeded";
680 frontend::Alert::error(_("Revision control error."),
681 _("The repository version is newer then the current check out.\n"
682 "You have to update from repository first or revert your changes.")) ;
685 frontend::Alert::error(_("Revision control error."),
686 bformat(_("Bad status when checking in changes.\n"
695 bool CVS::isLocked() const
697 FileName fn(owner_->absFileName());
699 return !fn.isReadOnly();
703 bool CVS::checkInEnabled()
705 if (vcstatus != NOLOCKING)
712 bool CVS::isCheckInWithConfirmation()
714 CvsStatus status = getStatus();
715 return status == LocallyModified || status == LocallyAdded;
719 string CVS::checkOut()
721 if (vcstatus != NOLOCKING && edit())
723 FileName tmpf = FileName::tempName("lyxvcout");
725 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
729 int rc = update(File, tmpf);
731 string const res = scanLogFile(tmpf, log);
733 frontend::Alert::error(_("Revision control error."),
734 bformat(_("Error when updating from repository.\n"
735 "You have to manually resolve the conflicts NOW!\n'%1$s'.\n\n"
736 "After pressing OK, LyX will try to reopen the resolved document."),
737 from_local8bit(res)));
742 return rc ? string() : log.empty() ? "CVS: Proceeded" : "CVS: " + log;
746 bool CVS::checkOutEnabled()
748 if (vcstatus != NOLOCKING)
755 string CVS::repoUpdate()
757 FileName tmpf = FileName::tempName("lyxvcout");
759 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
763 getDiff(Directory, tmpf);
764 docstring res = tmpf.fileContents("UTF-8");
766 LYXERR(Debug::LYXVC, "Diff detected:\n" << res);
767 docstring const file = from_utf8(owner_->filePath());
768 docstring text = bformat(_("There were detected changes "
769 "in the working directory:\n%1$s\n\n"
770 "In case of file conflict you have to resolve them "
771 "manually or revert to repository version later."), file);
772 int ret = frontend::Alert::prompt(_("Changes detected"),
773 text, 0, 1, _("&Continue"), _("&Abort"), _("View &Log ..."));
775 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + tmpf.absFileName()));
776 ret = frontend::Alert::prompt(_("Changes detected"),
777 text, 0, 1, _("&Continue"), _("&Abort"));
778 hideDialogs("file", 0);
786 int rc = update(Directory, tmpf);
787 res += "Update log:\n" + tmpf.fileContents("UTF-8");
788 LYXERR(Debug::LYXVC, res);
791 string sres = scanLogFile(tmpf, log);
793 docstring const file = owner_->fileName().displayName(20);
794 frontend::Alert::error(_("Revision control error."),
795 bformat(_("Error when updating document %1$s from repository.\n"
796 "You have to manually resolve the conflicts NOW!\n'%2$s'.\n\n"
797 "After pressing OK, LyX will try to reopen the resolved document."),
798 file, from_local8bit(sres)));
804 return rc ? string() : log.empty() ? "CVS: Proceeded" : "CVS: " + log;
808 bool CVS::repoUpdateEnabled()
814 string CVS::lockingToggle()
816 lyxerr << "Sorry, not implemented." << endl;
821 bool CVS::lockingToggleEnabled()
827 bool CVS::isRevertWithConfirmation()
829 CvsStatus status = getStatus();
830 return !owner_->isClean() || status == LocallyModified || status == NeedsMerge;
836 // Reverts to the version in CVS repository and
837 // gets the updated version from the repository.
838 CvsStatus status = getStatus();
841 if (vcstatus != NOLOCKING)
846 case LocallyModified: {
847 FileName f(owner_->absFileName());
849 update(File, FileName());
854 docstring const file = owner_->fileName().displayName(20);
855 frontend::Alert::error(_("Revision control error."),
856 bformat(_("The document %1$s is not in repository.\n"
857 "You have to check in the first revision before you can revert."),
862 docstring const file = owner_->fileName().displayName(20);
863 frontend::Alert::error(_("Revision control error."),
864 bformat(_("Cannot revert document %1$s to repository version.\n"
865 "The status '%2$s' is unexpected."),
866 file, toString(status)));
875 // merge the current with the previous version
876 // in a reverse patch kind of way, so that the
877 // result is to revert the last changes.
878 lyxerr << "Sorry, not implemented." << endl;
882 bool CVS::undoLastEnabled()
888 void CVS::getLog(FileName const & tmpf)
890 doVCCommandWithOutput("cvs log " + getTarget(File),
891 FileName(owner_->filePath()),
896 bool CVS::toggleReadOnlyEnabled()
902 string CVS::revisionInfo(LyXVC::RevisionInfo const info)
904 if (!version_.empty()) {
910 return rev_author_cache_;
912 return rev_date_cache_;
914 return rev_time_cache_;
922 bool CVS::prepareFileRevision(string const &, string &)
928 bool CVS::prepareFileRevisionEnabled()
934 /////////////////////////////////////////////////////////////////////
938 /////////////////////////////////////////////////////////////////////
940 SVN::SVN(FileName const & m, FileName const & f)
950 FileName const SVN::findFile(FileName const & file)
952 // First we look for the .svn/entries in the same dir
953 // where we have file.
954 FileName const entries(onlyPath(file.absFileName()) + "/.svn/entries");
955 string const tmpf = onlyFileName(file.absFileName());
956 LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under svn in `" << entries
957 << "' for `" << tmpf << '\'');
958 if (entries.isReadableFile()) {
959 // Ok we are at least in a SVN dir. Parse the .svn/entries
960 // and see if we can find this file. We do a fast and
962 ifstream ifs(entries.toFilesystemEncoding().c_str());
963 string line, oldline;
964 while (getline(ifs, line)) {
965 if (line == "dir" || line == "file")
966 LYXERR(Debug::LYXVC, "\tEntries: " << oldline);
967 if (oldline == tmpf && line == "file")
976 void SVN::scanMaster()
978 // vcstatus code is somewhat superflous, until we want
979 // to implement read-only toggle for svn.
980 vcstatus = NOLOCKING;
981 if (checkLockMode()) {
991 bool SVN::checkLockMode()
993 FileName tmpf = FileName::tempName("lyxvcout");
995 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
996 return N_("Error: Could not generate logfile.");
999 LYXERR(Debug::LYXVC, "Detecting locking mode...");
1000 if (doVCCommandCall("svn proplist " + quoteName(file_.onlyFileName())
1001 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1005 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1011 LYXERR(Debug::LYXVC, line);
1012 if (contains(line, "svn:needs-lock"))
1015 LYXERR(Debug::LYXVC, "Locking enabled: " << ret);
1023 bool SVN::isLocked() const
1026 return !file_.isReadOnly();
1030 void SVN::registrer(string const & /*msg*/)
1032 doVCCommand("svn add -q " + quoteName(onlyFileName(owner_->absFileName())),
1033 FileName(owner_->filePath()));
1037 string SVN::checkIn(string const & msg)
1039 FileName tmpf = FileName::tempName("lyxvcout");
1041 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1042 return N_("Error: Could not generate logfile.");
1045 doVCCommand("svn commit -m \"" + msg + "\" "
1046 + quoteName(onlyFileName(owner_->absFileName()))
1047 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1048 FileName(owner_->filePath()));
1051 string res = scanLogFile(tmpf, log);
1053 frontend::Alert::error(_("Revision control error."),
1054 _("Error when committing to repository.\n"
1055 "You have to manually resolve the problem.\n"
1056 "LyX will reopen the document after you press OK."));
1058 fileLock(false, tmpf, log);
1061 return log.empty() ? string() : "SVN: " + log;
1065 bool SVN::checkInEnabled()
1074 bool SVN::isCheckInWithConfirmation()
1076 // FIXME one day common getDiff and perhaps OpMode for all backends
1078 FileName tmpf = FileName::tempName("lyxvcout");
1080 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1084 doVCCommandCall("svn diff " + quoteName(owner_->absFileName())
1085 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1086 FileName(owner_->filePath()));
1088 docstring diff = tmpf.fileContents("UTF-8");
1098 // FIXME Correctly return code should be checked instead of this.
1099 // This would need another solution than just plain startscript.
1100 // Hint from Andre': QProcess::readAllStandardError()...
1101 string SVN::scanLogFile(FileName const & f, string & status)
1103 ifstream ifs(f.toFilesystemEncoding().c_str());
1108 LYXERR(Debug::LYXVC, line << "\n");
1110 status += line + "; ";
1111 if (prefixIs(line, "C ") || prefixIs(line, "CU ")
1112 || contains(line, "Commit failed")) {
1116 if (contains(line, "svn:needs-lock")) {
1126 void SVN::fileLock(bool lock, FileName const & tmpf, string &status)
1128 if (!locked_mode_ || (isLocked() == lock))
1131 string const arg = lock ? "lock " : "unlock ";
1132 doVCCommand("svn "+ arg + quoteName(onlyFileName(owner_->absFileName()))
1133 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1134 FileName(owner_->filePath()));
1136 // Lock error messages go unfortunately on stderr and are unreachible this way.
1137 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1141 if (!line.empty()) status += line + "; ";
1145 if (!isLocked() && lock)
1146 frontend::Alert::error(_("Revision control error."),
1147 _("Error while acquiring write lock.\n"
1148 "Another user is most probably editing\n"
1149 "the current document now!\n"
1150 "Also check the access to the repository."));
1151 if (isLocked() && !lock)
1152 frontend::Alert::error(_("Revision control error."),
1153 _("Error while releasing write lock.\n"
1154 "Check the access to the repository."));
1158 string SVN::checkOut()
1160 FileName tmpf = FileName::tempName("lyxvcout");
1162 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1163 return N_("Error: Could not generate logfile.");
1166 doVCCommand("svn update --non-interactive " + quoteName(onlyFileName(owner_->absFileName()))
1167 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1168 FileName(owner_->filePath()));
1171 string const res = scanLogFile(tmpf, log);
1173 frontend::Alert::error(_("Revision control error."),
1174 bformat(_("Error when updating from repository.\n"
1175 "You have to manually resolve the conflicts NOW!\n'%1$s'.\n\n"
1176 "After pressing OK, LyX will try to reopen the resolved document."),
1177 from_local8bit(res)));
1179 fileLock(true, tmpf, log);
1182 return log.empty() ? string() : "SVN: " + log;
1186 bool SVN::checkOutEnabled()
1195 string SVN::repoUpdate()
1197 FileName tmpf = FileName::tempName("lyxvcout");
1199 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1200 return N_("Error: Could not generate logfile.");
1203 doVCCommand("svn diff " + quoteName(owner_->filePath())
1204 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1205 FileName(owner_->filePath()));
1206 docstring res = tmpf.fileContents("UTF-8");
1208 LYXERR(Debug::LYXVC, "Diff detected:\n" << res);
1209 docstring const file = from_utf8(owner_->filePath());
1210 docstring text = bformat(_("There were detected changes "
1211 "in the working directory:\n%1$s\n\n"
1212 "In case of file conflict version of the local directory files "
1213 "will be preferred."
1214 "\n\nContinue?"), file);
1215 int ret = frontend::Alert::prompt(_("Changes detected"),
1216 text, 0, 1, _("&Yes"), _("&No"), _("View &Log ..."));
1218 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + tmpf.absFileName()));
1219 ret = frontend::Alert::prompt(_("Changes detected"),
1220 text, 0, 1, _("&Yes"), _("&No"));
1221 hideDialogs("file", 0);
1229 // Reverting looks too harsh, see bug #6255.
1230 // doVCCommand("svn revert -R " + quoteName(owner_->filePath())
1231 // + " > " + quoteName(tmpf.toFilesystemEncoding()),
1232 // FileName(owner_->filePath()));
1233 // res = "Revert log:\n" + tmpf.fileContents("UTF-8");
1234 doVCCommand("svn update --accept mine-full " + quoteName(owner_->filePath())
1235 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1236 FileName(owner_->filePath()));
1237 res += "Update log:\n" + tmpf.fileContents("UTF-8");
1239 LYXERR(Debug::LYXVC, res);
1241 return to_utf8(res);
1245 bool SVN::repoUpdateEnabled()
1251 string SVN::lockingToggle()
1253 FileName tmpf = FileName::tempName("lyxvcout");
1255 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1256 return N_("Error: Could not generate logfile.");
1259 int ret = doVCCommand("svn proplist " + quoteName(onlyFileName(owner_->absFileName()))
1260 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1261 FileName(owner_->filePath()));
1266 string res = scanLogFile(tmpf, log);
1267 bool locking = contains(res, "svn:needs-lock");
1269 ret = doVCCommand("svn propset svn:needs-lock ON "
1270 + quoteName(onlyFileName(owner_->absFileName()))
1271 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1272 FileName(owner_->filePath()));
1274 ret = doVCCommand("svn propdel svn:needs-lock "
1275 + quoteName(onlyFileName(owner_->absFileName()))
1276 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1277 FileName(owner_->filePath()));
1282 frontend::Alert::warning(_("VCN File Locking"),
1283 (locking ? _("Locking property unset.") : _("Locking property set.")) + "\n"
1284 + _("Do not forget to commit the locking property into the repository."),
1287 return string("SVN: ") + N_("Locking property set.");
1291 bool SVN::lockingToggleEnabled()
1299 // Reverts to the version in SVN repository and
1300 // gets the updated version from the repository.
1301 string const fil = quoteName(onlyFileName(owner_->absFileName()));
1303 doVCCommand("svn revert -q " + fil,
1304 FileName(owner_->filePath()));
1305 owner_->markClean();
1309 bool SVN::isRevertWithConfirmation()
1311 //FIXME owner && diff
1316 void SVN::undoLast()
1318 // merge the current with the previous version
1319 // in a reverse patch kind of way, so that the
1320 // result is to revert the last changes.
1321 lyxerr << "Sorry, not implemented." << endl;
1325 bool SVN::undoLastEnabled()
1331 string SVN::revisionInfo(LyXVC::RevisionInfo const info)
1333 if (info == LyXVC::Tree) {
1334 if (rev_tree_cache_.empty())
1335 if (!getTreeRevisionInfo())
1336 rev_tree_cache_ = "?";
1337 if (rev_tree_cache_ == "?")
1340 return rev_tree_cache_;
1343 // fill the rest of the attributes for a single file
1344 if (rev_file_cache_.empty())
1345 if (!getFileRevisionInfo())
1346 rev_file_cache_ = "?";
1350 if (rev_file_cache_ == "?")
1352 return rev_file_cache_;
1354 return rev_author_cache_;
1356 return rev_date_cache_;
1358 return rev_time_cache_;
1367 bool SVN::getFileRevisionInfo()
1369 FileName tmpf = FileName::tempName("lyxvcout");
1371 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1372 return N_("Error: Could not generate logfile.");
1375 doVCCommand("svn info --xml " + quoteName(onlyFileName(owner_->absFileName()))
1376 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1377 FileName(owner_->filePath()));
1382 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1390 LYXERR(Debug::LYXVC, line);
1391 if (prefixIs(line, "<commit"))
1393 if (c && prefixIs(line, " revision=\"") && suffixIs(line, "\">")) {
1394 string l1 = subst(line, "revision=\"", "");
1395 string l2 = trim(subst(l1, "\">", ""));
1397 rev_file_cache_ = rev = l2;
1399 if (c && prefixIs(line, "<author>") && suffixIs(line, "</author>")) {
1400 string l1 = subst(line, "<author>", "");
1401 string l2 = subst(l1, "</author>", "");
1402 rev_author_cache_ = l2;
1404 if (c && prefixIs(line, "<date>") && suffixIs(line, "</date>")) {
1405 string l1 = subst(line, "<date>", "");
1406 string l2 = subst(l1, "</date>", "");
1407 l2 = split(l2, l1, 'T');
1408 rev_date_cache_ = l1;
1409 l2 = split(l2, l1, '.');
1410 rev_time_cache_ = l1;
1416 return !rev.empty();
1420 bool SVN::getTreeRevisionInfo()
1422 FileName tmpf = FileName::tempName("lyxvcout");
1424 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1425 return N_("Error: Could not generate logfile.");
1428 doVCCommand("svnversion -n . > " + quoteName(tmpf.toFilesystemEncoding()),
1429 FileName(owner_->filePath()));
1434 // only first line in case something bad happens.
1435 ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1441 rev_tree_cache_ = line;
1442 return !line.empty();
1446 void SVN::getLog(FileName const & tmpf)
1448 doVCCommand("svn log " + quoteName(onlyFileName(owner_->absFileName()))
1449 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1450 FileName(owner_->filePath()));
1454 bool SVN::prepareFileRevision(string const & revis, string & f)
1456 if (!isStrInt(revis))
1459 int rev = convert<int>(revis);
1461 if (!getFileRevisionInfo())
1464 rev = convert<int>(rev_file_cache_);
1465 // go back for minus rev
1467 rev = rev + convert<int>(rev_file_cache_);
1472 string revname = convert<string>(rev);
1473 FileName tmpf = FileName::tempName("lyxvcrev_" + revname + "_");
1475 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1476 return N_("Error: Could not generate logfile.");
1479 doVCCommand("svn cat -r " + revname + " "
1480 + quoteName(onlyFileName(owner_->absFileName()))
1481 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1482 FileName(owner_->filePath()));
1483 if (tmpf.isFileEmpty())
1486 f = tmpf.absFileName();
1491 bool SVN::prepareFileRevisionEnabled()
1498 bool SVN::toggleReadOnlyEnabled()