]> git.lyx.org Git - lyx.git/blobdiff - src/VCBackend.cpp
typo
[lyx.git] / src / VCBackend.cpp
index bf52e7006b7ec430142b8980ea2cf3850e3d527e..e6d6015ce0283680eab64004c95e73fff0c27e41 100644 (file)
 #include "support/lstrings.h"
 #include "support/Path.h"
 #include "support/Systemcall.h"
-
-#include <boost/regex.hpp>
+#include "support/regex.h"
 
 #include <fstream>
 
 using namespace std;
 using namespace lyx::support;
 
-using boost::regex;
-using boost::regex_match;
-using boost::smatch;
+
 
 namespace lyx {
 
@@ -84,7 +81,7 @@ RCS::RCS(FileName const & m)
 FileName const RCS::findFile(FileName const & file)
 {
        // Check if *,v exists.
-       FileName tmp(file.absFilename() + ",v");
+       FileName tmp(file.absFileName() + ",v");
        LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under rcs: " << tmp);
        if (tmp.isReadableFile()) {
                LYXERR(Debug::LYXVC, "Yes, " << file << " is under rcs.");
@@ -92,7 +89,7 @@ FileName const RCS::findFile(FileName const & file)
        }
 
        // Check if RCS/*,v exists.
-       tmp = FileName(addName(addPath(onlyPath(file.absFilename()), "RCS"), file.absFilename()) + ",v");
+       tmp = FileName(addName(addPath(onlyPath(file.absFileName()), "RCS"), file.absFileName()) + ",v");
        LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under rcs: " << tmp);
        if (tmp.isReadableFile()) {
                LYXERR(Debug::LYXVC, "Yes, " << file << " is under rcs.");
@@ -179,7 +176,7 @@ void RCS::registrer(string const & msg)
        string cmd = "ci -q -u -i -t-\"";
        cmd += msg;
        cmd += "\" ";
-       cmd += quoteName(onlyFilename(owner_->absFileName()));
+       cmd += quoteName(onlyFileName(owner_->absFileName()));
        doVCCommand(cmd, FileName(owner_->filePath()));
 }
 
@@ -187,7 +184,7 @@ void RCS::registrer(string const & msg)
 string RCS::checkIn(string const & msg)
 {
        int ret = doVCCommand("ci -q -u -m\"" + msg + "\" "
-                   + quoteName(onlyFilename(owner_->absFileName())),
+                   + quoteName(onlyFileName(owner_->absFileName())),
                    FileName(owner_->filePath()));
        return ret ? string() : "RCS: Proceeded";
 }
@@ -202,7 +199,7 @@ bool RCS::checkInEnabled()
 string RCS::checkOut()
 {
        owner_->markClean();
-       int ret = doVCCommand("co -q -l " + quoteName(onlyFilename(owner_->absFileName())),
+       int ret = doVCCommand("co -q -l " + quoteName(onlyFileName(owner_->absFileName())),
                    FileName(owner_->filePath()));
        return ret ? string() : "RCS: Proceeded";
 }
@@ -243,7 +240,7 @@ bool RCS::lockingToggleEnabled()
 void RCS::revert()
 {
        doVCCommand("co -f -u" + version_ + " "
-                   + quoteName(onlyFilename(owner_->absFileName())),
+                   + quoteName(onlyFileName(owner_->absFileName())),
                    FileName(owner_->filePath()));
        // We ignore changes and just reload!
        owner_->markClean();
@@ -254,7 +251,7 @@ void RCS::undoLast()
 {
        LYXERR(Debug::LYXVC, "LyXVC: undoLast");
        doVCCommand("rcs -o" + version_ + " "
-                   + quoteName(onlyFilename(owner_->absFileName())),
+                   + quoteName(onlyFileName(owner_->absFileName())),
                    FileName(owner_->filePath()));
 }
 
@@ -267,7 +264,7 @@ bool RCS::undoLastEnabled()
 
 void RCS::getLog(FileName const & tmpf)
 {
-       doVCCommand("rlog " + quoteName(onlyFilename(owner_->absFileName()))
+       doVCCommand("rlog " + quoteName(onlyFileName(owner_->absFileName()))
                    + " > " + quoteName(tmpf.toFilesystemEncoding()),
                    FileName(owner_->filePath()));
 }
@@ -290,15 +287,56 @@ string RCS::revisionInfo(LyXVC::RevisionInfo const info)
 }
 
 
-bool RCS::prepareFileRevision(string const &, string &)
+bool RCS::prepareFileRevision(string const &revis, string & f)
 {
-       return false;
+       string rev = revis;
+
+       if (isStrInt(rev)) {
+               int back = convert<int>(rev);
+               // if positive use as the last number in the whole revision string
+               if (back > 0) {
+                       string base;
+                       rsplit(version_, base , '.' );
+                       rev = base + "." + rev;
+               }
+               if (back == 0)
+                       rev = version_;
+               // we care about the last number from revision string
+               // in case of backward indexing
+               if (back < 0) {
+                       string cur, base;
+                       cur = rsplit(version_, base , '.' );
+                       if (!isStrInt(cur))
+                               return false;
+                       int want = convert<int>(cur) + back;
+                       if (want <= 0)
+                               return false;
+
+                       rev = base + "." + convert<string>(want);
+               }
+       }
+
+       FileName tmpf = FileName::tempName("lyxvcrev_" + rev + "_");
+       if (tmpf.empty()) {
+               LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
+               return N_("Error: Could not generate logfile.");
+       }
+
+       doVCCommand("co -p" + rev + " "
+                     + quoteName(onlyFileName(owner_->absFileName()))
+                     + " > " + quoteName(tmpf.toFilesystemEncoding()),
+               FileName(owner_->filePath()));
+       if (tmpf.isFileEmpty())
+               return false;
+
+       f = tmpf.absFileName();
+       return true;
 }
 
 
 bool RCS::prepareFileRevisionEnabled()
 {
-       return false;
+       return true;
 }
 
 
@@ -320,8 +358,8 @@ FileName const CVS::findFile(FileName const & file)
 {
        // First we look for the CVS/Entries in the same dir
        // where we have file.
-       FileName const entries(onlyPath(file.absFilename()) + "/CVS/Entries");
-       string const tmpf = '/' + onlyFilename(file.absFilename()) + '/';
+       FileName const entries(onlyPath(file.absFileName()) + "/CVS/Entries");
+       string const tmpf = '/' + onlyFileName(file.absFileName()) + '/';
        LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under cvs in `" << entries
                             << "' for `" << tmpf << '\'');
        if (entries.isReadableFile()) {
@@ -345,7 +383,7 @@ void CVS::scanMaster()
        LYXERR(Debug::LYXVC, "LyXVC::CVS: scanMaster. \n     Checking: " << master_);
        // Ok now we do the real scan...
        ifstream ifs(master_.toFilesystemEncoding().c_str());
-       string tmpf = '/' + onlyFilename(file_.absFilename()) + '/';
+       string tmpf = '/' + onlyFileName(file_.absFileName()) + '/';
        LYXERR(Debug::LYXVC, "\tlooking for `" << tmpf << '\'');
        string line;
        static regex const reg("/(.*)/(.*)/(.*)/(.*)/(.*)");
@@ -375,7 +413,7 @@ void CVS::scanMaster()
                                locker_ = "Unlocked";
                                vcstatus = UNLOCKED;
                        } else {
-                               // Here we should also to some more checking
+                               // Here we should also do some more checking
                                // to see if there are conflicts or not.
                                locker_ = "Locked";
                                vcstatus = LOCKED;
@@ -389,7 +427,7 @@ void CVS::scanMaster()
 void CVS::registrer(string const & msg)
 {
        doVCCommand("cvs -q add -m \"" + msg + "\" "
-                   + quoteName(onlyFilename(owner_->absFileName())),
+                   + quoteName(onlyFileName(owner_->absFileName())),
                    FileName(owner_->filePath()));
 }
 
@@ -397,7 +435,7 @@ void CVS::registrer(string const & msg)
 string CVS::checkIn(string const & msg)
 {
        int ret = doVCCommand("cvs -q commit -m \"" + msg + "\" "
-                   + quoteName(onlyFilename(owner_->absFileName())),
+                   + quoteName(onlyFileName(owner_->absFileName())),
                    FileName(owner_->filePath()));
        return ret ? string() : "CVS: Proceeded";
 }
@@ -405,23 +443,32 @@ string CVS::checkIn(string const & msg)
 
 bool CVS::checkInEnabled()
 {
-       return true;
+       return !owner_->isReadonly();
 }
 
 
 string CVS::checkOut()
 {
-       // cvs update or perhaps for cvs this should be a noop
-       // we need to detect conflict (eg "C" in output)
-       // before we can do this.
-       lyxerr << "Sorry, not implemented." << endl;
-       return string();
+       // to be sure we test it again...
+       if (!checkOutEnabled())
+               return string();
+
+       int ret = doVCCommand("cvs -q edit "
+                                                 + quoteName(onlyFileName(owner_->absFileName())),
+                                                 FileName(owner_->filePath()));
+       if (ret)
+               return string();
+
+       ret = doVCCommand("cvs update "
+                                         + quoteName(onlyFileName(owner_->absFileName())),
+                                         FileName(owner_->filePath()));
+       return ret ? string() : "CVS: Proceeded";
 }
 
 
 bool CVS::checkOutEnabled()
 {
-       return false;
+       return owner_->isReadonly();
 }
 
 
@@ -455,14 +502,14 @@ void CVS::revert()
 {
        // Reverts to the version in CVS repository and
        // gets the updated version from the repository.
-       string const fil = quoteName(onlyFilename(owner_->absFileName()));
+       string const fil = quoteName(onlyFileName(owner_->absFileName()));
        // This is sensitive operation, so at lest some check about
        // existence of cvs program and its file
        if (doVCCommand("cvs log "+ fil, FileName(owner_->filePath())))
                return;
        FileName f(owner_->absFileName());
        f.removeFile();
-       doVCCommand("cvs update " + fil,
+       doVCCommand("cvs -q update " + fil,
                    FileName(owner_->filePath()));
        owner_->markClean();
 }
@@ -485,7 +532,7 @@ bool CVS::undoLastEnabled()
 
 void CVS::getLog(FileName const & tmpf)
 {
-       doVCCommand("cvs log " + quoteName(onlyFilename(owner_->absFileName()))
+       doVCCommand("cvs log " + quoteName(onlyFileName(owner_->absFileName()))
                    + " > " + quoteName(tmpf.toFilesystemEncoding()),
                    FileName(owner_->filePath()));
 }
@@ -537,8 +584,8 @@ FileName const SVN::findFile(FileName const & file)
 {
        // First we look for the .svn/entries in the same dir
        // where we have file.
-       FileName const entries(onlyPath(file.absFilename()) + "/.svn/entries");
-       string const tmpf = onlyFilename(file.absFilename());
+       FileName const entries(onlyPath(file.absFileName()) + "/.svn/entries");
+       string const tmpf = onlyFileName(file.absFileName());
        LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under svn in `" << entries
                             << "' for `" << tmpf << '\'');
        if (entries.isReadableFile()) {
@@ -615,7 +662,7 @@ bool SVN::isLocked() const
 
 void SVN::registrer(string const & /*msg*/)
 {
-       doVCCommand("svn add -q " + quoteName(onlyFilename(owner_->absFileName())),
+       doVCCommand("svn add -q " + quoteName(onlyFileName(owner_->absFileName())),
                    FileName(owner_->filePath()));
 }
 
@@ -629,7 +676,7 @@ string SVN::checkIn(string const & msg)
        }
 
        doVCCommand("svn commit -m \"" + msg + "\" "
-                   + quoteName(onlyFilename(owner_->absFileName()))
+                   + quoteName(onlyFileName(owner_->absFileName()))
                    + " > " + quoteName(tmpf.toFilesystemEncoding()),
                    FileName(owner_->filePath()));
 
@@ -691,7 +738,7 @@ void SVN::fileLock(bool lock, FileName const & tmpf, string &status)
                return;
 
        string const arg = lock ? "lock " : "unlock ";
-       doVCCommand("svn "+ arg + quoteName(onlyFilename(owner_->absFileName()))
+       doVCCommand("svn "+ arg + quoteName(onlyFileName(owner_->absFileName()))
                    + " > " + quoteName(tmpf.toFilesystemEncoding()),
                    FileName(owner_->filePath()));
 
@@ -706,13 +753,13 @@ void SVN::fileLock(bool lock, FileName const & tmpf, string &status)
 
        if (!isLocked() && lock)
                frontend::Alert::error(_("Revision control error."),
-                       _("Error when acquiring write lock.\n"
-                       "Most probably another user is editing\n"
+                       _("Error while acquiring write lock.\n"
+                       "Another user is most probably editing\n"
                        "the current document now!\n"
                        "Also check the access to the repository."));
        if (isLocked() && !lock)
                frontend::Alert::error(_("Revision control error."),
-                       _("Error when releasing write lock.\n"
+                       _("Error while releasing write lock.\n"
                        "Check the access to the repository."));
 }
 
@@ -725,12 +772,12 @@ string SVN::checkOut()
                return N_("Error: Could not generate logfile.");
        }
 
-       doVCCommand("svn update --non-interactive " + quoteName(onlyFilename(owner_->absFileName()))
+       doVCCommand("svn update --non-interactive " + quoteName(onlyFileName(owner_->absFileName()))
                    + " > " + quoteName(tmpf.toFilesystemEncoding()),
                    FileName(owner_->filePath()));
 
        string log;
-       string res = scanLogFile(tmpf, log);
+       string const res = scanLogFile(tmpf, log);
        if (!res.empty())
                frontend::Alert::error(_("Revision control error."),
                        bformat(_("Error when updating from repository.\n"
@@ -777,7 +824,7 @@ string SVN::repoUpdate()
                int ret = frontend::Alert::prompt(_("Changes detected"),
                                text, 0, 1, _("&Yes"), _("&No"), _("View &Log ..."));
                if (ret == 2 ) {
-                       dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + tmpf.absFilename()));
+                       dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + tmpf.absFileName()));
                        ret = frontend::Alert::prompt(_("Changes detected"),
                                text, 0, 1, _("&Yes"), _("&No"));
                        hideDialogs("file", 0);
@@ -818,7 +865,7 @@ string SVN::lockingToggle()
                return N_("Error: Could not generate logfile.");
        }
 
-       int ret = doVCCommand("svn proplist " + quoteName(onlyFilename(owner_->absFileName()))
+       int ret = doVCCommand("svn proplist " + quoteName(onlyFileName(owner_->absFileName()))
                    + " > " + quoteName(tmpf.toFilesystemEncoding()),
                    FileName(owner_->filePath()));
        if (ret)
@@ -829,12 +876,12 @@ string SVN::lockingToggle()
        bool locking = contains(res, "svn:needs-lock");
        if (!locking)
                ret = doVCCommand("svn propset svn:needs-lock ON "
-                   + quoteName(onlyFilename(owner_->absFileName()))
+                   + quoteName(onlyFileName(owner_->absFileName()))
                    + " > " + quoteName(tmpf.toFilesystemEncoding()),
                    FileName(owner_->filePath()));
        else
                ret = doVCCommand("svn propdel svn:needs-lock "
-                   + quoteName(onlyFilename(owner_->absFileName()))
+                   + quoteName(onlyFileName(owner_->absFileName()))
                    + " > " + quoteName(tmpf.toFilesystemEncoding()),
                    FileName(owner_->filePath()));
        if (ret)
@@ -860,7 +907,7 @@ void SVN::revert()
 {
        // Reverts to the version in CVS repository and
        // gets the updated version from the repository.
-       string const fil = quoteName(onlyFilename(owner_->absFileName()));
+       string const fil = quoteName(onlyFileName(owner_->absFileName()));
 
        doVCCommand("svn revert -q " + fil,
                    FileName(owner_->filePath()));
@@ -927,7 +974,7 @@ bool SVN::getFileRevisionInfo()
                return N_("Error: Could not generate logfile.");
        }
 
-       doVCCommand("svn info --xml " + quoteName(onlyFilename(owner_->absFileName()))
+       doVCCommand("svn info --xml " + quoteName(onlyFileName(owner_->absFileName()))
                    + " > " + quoteName(tmpf.toFilesystemEncoding()),
                    FileName(owner_->filePath()));
 
@@ -1000,7 +1047,7 @@ bool SVN::getTreeRevisionInfo()
 
 void SVN::getLog(FileName const & tmpf)
 {
-       doVCCommand("svn log " + quoteName(onlyFilename(owner_->absFileName()))
+       doVCCommand("svn log " + quoteName(onlyFileName(owner_->absFileName()))
                    + " > " + quoteName(tmpf.toFilesystemEncoding()),
                    FileName(owner_->filePath()));
 }
@@ -1024,20 +1071,21 @@ bool SVN::prepareFileRevision(string const & revis, string & f)
                        return false;
        }
 
-       FileName tmpf = FileName::tempName("lyxvcrev");
+       string revname = convert<string>(rev);
+       FileName tmpf = FileName::tempName("lyxvcrev_" + revname + "_");
        if (tmpf.empty()) {
                LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
                return N_("Error: Could not generate logfile.");
        }
 
-       doVCCommand("svn cat -r " + convert<string>(rev) + " "
-                     + quoteName(onlyFilename(owner_->absFileName()))
+       doVCCommand("svn cat -r " + revname + " "
+                     + quoteName(onlyFileName(owner_->absFileName()))
                      + " > " + quoteName(tmpf.toFilesystemEncoding()),
                FileName(owner_->filePath()));
        if (tmpf.isFileEmpty())
                return false;
 
-       f = tmpf.absFilename();
+       f = tmpf.absFileName();
        return true;
 }