+
+bool CVS::undoLastEnabled()
+{
+ return false;
+}
+
+
+void CVS::getLog(FileName const & tmpf)
+{
+ doVCCommandWithOutput("cvs log " + getTarget(File),
+ FileName(owner_->filePath()),
+ tmpf);
+}
+
+
+bool CVS::toggleReadOnlyEnabled()
+{
+ return false;
+}
+
+
+string CVS::revisionInfo(LyXVC::RevisionInfo const info)
+{
+ if (!version_.empty()) {
+ getRevisionInfo();
+ switch (info) {
+ case LyXVC::File:
+ return version_;
+ case LyXVC::Author:
+ return rev_author_cache_;
+ case LyXVC::Date:
+ return rev_date_cache_;
+ case LyXVC::Time:
+ return rev_time_cache_;
+ default: ;
+ }
+ }
+ return string();
+}
+
+
+bool CVS::prepareFileRevision(string const & revis, string & f)
+{
+ string rev = revis;
+ if (!VCS::makeRCSRevision(version_, rev))
+ return false;
+
+ FileName tmpf = FileName::tempName("lyxvcrev_" + rev + "_");
+ if (tmpf.empty()) {
+ LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
+ return false;
+ }
+
+ doVCCommandWithOutput("cvs update -p -r" + rev + " "
+ + getTarget(File),
+ FileName(owner_->filePath()), tmpf);
+ if (tmpf.isFileEmpty())
+ return false;
+
+ f = tmpf.absFileName();
+ return true;
+}
+
+
+bool CVS::prepareFileRevisionEnabled()
+{
+ return true;
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// SVN
+//
+/////////////////////////////////////////////////////////////////////
+
+SVN::SVN(FileName const & m, FileName const & f)
+{
+ owner_ = 0;
+ master_ = m;
+ file_ = f;
+ locked_mode_ = 0;
+ scanMaster();
+}
+
+
+FileName const SVN::findFile(FileName const & file)
+{
+ // First we check the existence of repository meta data.
+ if (!VCS::checkparentdirs(file, ".svn")) {
+ LYXERR(Debug::LYXVC, "Cannot find SVN meta data for " << file);
+ return FileName();
+ }
+
+ // Now we check the status of the file.
+ FileName tmpf = FileName::tempName("lyxvcout");
+ if (tmpf.empty()) {
+ LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
+ return FileName();
+ }
+
+ string const fname = onlyFileName(file.absFileName());
+ LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under svn control for `" << fname << '\'');
+ bool found = 0 == doVCCommandCall("svn info " + quoteName(fname)
+ + " > " + quoteName(tmpf.toFilesystemEncoding()),
+ file.onlyPath());
+ LYXERR(Debug::LYXVC, "SVN control: " << (found ? "enabled" : "disabled"));
+ return found ? file : FileName();
+}
+
+
+void SVN::scanMaster()
+{
+ // vcstatus code is somewhat superflous, until we want
+ // to implement read-only toggle for svn.
+ vcstatus = NOLOCKING;
+ if (checkLockMode()) {
+ if (isLocked()) {
+ vcstatus = LOCKED;
+ } else {
+ vcstatus = UNLOCKED;
+ }
+ }
+}
+
+
+bool SVN::checkLockMode()
+{
+ FileName tmpf = FileName::tempName("lyxvcout");
+ if (tmpf.empty()){
+ LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
+ return false;
+ }
+
+ LYXERR(Debug::LYXVC, "Detecting locking mode...");
+ if (doVCCommandCall("svn proplist " + quoteName(file_.onlyFileName())
+ + " > " + quoteName(tmpf.toFilesystemEncoding()),
+ file_.onlyPath()))
+ return false;
+
+ ifstream ifs(tmpf.toFilesystemEncoding().c_str());
+ string line;
+ bool ret = false;
+
+ while (ifs && !ret) {
+ getline(ifs, line);
+ LYXERR(Debug::LYXVC, line);
+ if (contains(line, "svn:needs-lock"))
+ ret = true;
+ }
+ LYXERR(Debug::LYXVC, "Locking enabled: " << ret);
+ ifs.close();
+ locked_mode_ = ret;
+ return ret;
+
+}
+
+
+bool SVN::isLocked() const
+{
+ file_.refresh();
+ return !file_.isReadOnly();
+}
+
+
+void SVN::registrer(string const & /*msg*/)
+{
+ doVCCommand("svn add -q " + quoteName(onlyFileName(owner_->absFileName())),
+ FileName(owner_->filePath()));
+}
+
+
+string SVN::checkIn(string const & msg)
+{
+ FileName tmpf = FileName::tempName("lyxvcout");
+ if (tmpf.empty()){
+ LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
+ return N_("Error: Could not generate logfile.");
+ }
+
+ doVCCommand("svn commit -m \"" + msg + "\" "
+ + quoteName(onlyFileName(owner_->absFileName()))
+ + " > " + quoteName(tmpf.toFilesystemEncoding()),
+ FileName(owner_->filePath()));
+
+ string log;
+ string res = scanLogFile(tmpf, log);
+ if (!res.empty())
+ frontend::Alert::error(_("Revision control error."),
+ _("Error when committing to repository.\n"
+ "You have to manually resolve the problem.\n"
+ "LyX will reopen the document after you press OK."));
+ else
+ fileLock(false, tmpf, log);
+
+ tmpf.erase();
+ return log.empty() ? string() : "SVN: " + log;
+}
+
+
+bool SVN::checkInEnabled()
+{
+ if (locked_mode_)
+ return isLocked();
+ else
+ return true;
+}
+
+
+bool SVN::isCheckInWithConfirmation()
+{
+ // FIXME one day common getDiff and perhaps OpMode for all backends
+
+ FileName tmpf = FileName::tempName("lyxvcout");
+ if (tmpf.empty()) {
+ LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
+ return true;
+ }
+
+ doVCCommandCall("svn diff " + quoteName(owner_->absFileName())
+ + " > " + quoteName(tmpf.toFilesystemEncoding()),
+ FileName(owner_->filePath()));
+
+ docstring diff = tmpf.fileContents("UTF-8");
+ tmpf.erase();
+
+ if (diff.empty())
+ return false;
+
+ return true;
+}
+
+
+// FIXME Correctly return code should be checked instead of this.
+// This would need another solution than just plain startscript.
+// Hint from Andre': QProcess::readAllStandardError()...
+string SVN::scanLogFile(FileName const & f, string & status)
+{
+ ifstream ifs(f.toFilesystemEncoding().c_str());
+ string line;
+
+ while (ifs) {
+ getline(ifs, line);
+ LYXERR(Debug::LYXVC, line << "\n");
+ if (!line.empty())
+ status += line + "; ";
+ if (prefixIs(line, "C ") || prefixIs(line, "CU ")
+ || contains(line, "Commit failed")) {
+ ifs.close();
+ return line;
+ }
+ if (contains(line, "svn:needs-lock")) {
+ ifs.close();
+ return line;
+ }
+ }
+ ifs.close();
+ return string();
+}
+
+
+void SVN::fileLock(bool lock, FileName const & tmpf, string &status)
+{
+ if (!locked_mode_ || (isLocked() == lock))
+ return;
+
+ string const arg = lock ? "lock " : "unlock ";
+ doVCCommand("svn "+ arg + quoteName(onlyFileName(owner_->absFileName()))
+ + " > " + quoteName(tmpf.toFilesystemEncoding()),