Author: switt
Date: Sat Nov  6 13:18:09 2010
New Revision: 36161
URL: http://www.lyx.org/trac/changeset/36161

Log:
implementation for "Compare with older revision" for CVS, correct return value 
of SVN::prepareFileRevision for failure to create tmp file

Modified:
   lyx-devel/trunk/src/VCBackend.cpp
   lyx-devel/trunk/src/VCBackend.h

Modified: lyx-devel/trunk/src/VCBackend.cpp
==============================================================================
--- lyx-devel/trunk/src/VCBackend.cpp   Sat Nov  6 12:54:08 2010        (r36160)
+++ lyx-devel/trunk/src/VCBackend.cpp   Sat Nov  6 13:18:09 2010        (r36161)
@@ -65,6 +65,40 @@
 }
 
 
+bool VCS::makeRCSRevision(string const &version, string &revis) const
+{
+       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);
+               }
+       }
+
+       revis = rev;
+       return true;
+}
+       
+       
 /////////////////////////////////////////////////////////////////////
 //
 // RCS
@@ -329,31 +363,8 @@
 bool RCS::prepareFileRevision(string const &revis, string & f)
 {
        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);
-               }
-       }
+       if (!VCS::makeRCSRevision(version_, rev))
+               return false;
 
        FileName tmpf = FileName::tempName("lyxvcrev_" + rev + "_");
        if (tmpf.empty()) {
@@ -922,15 +933,32 @@
 }
 
 
-bool CVS::prepareFileRevision(string const &, string &)
+bool CVS::prepareFileRevision(string const & revis, string & f)
 {
-       return false;
+       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 false;
+       return true;
 }
 
 
@@ -1478,7 +1506,7 @@
        FileName tmpf = FileName::tempName("lyxvcrev_" + revname + "_");
        if (tmpf.empty()) {
                LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
-               return N_("Error: Could not generate logfile.");
+               return false;
        }
 
        doVCCommand("svn cat -r " + revname + " "

Modified: lyx-devel/trunk/src/VCBackend.h
==============================================================================
--- lyx-devel/trunk/src/VCBackend.h     Sat Nov  6 12:54:08 2010        (r36160)
+++ lyx-devel/trunk/src/VCBackend.h     Sat Nov  6 13:18:09 2010        (r36161)
@@ -91,6 +91,10 @@
        /// parse information from the version file
        virtual void scanMaster() = 0;
 
+       /// make a relative version identifier
+       /// suitable for RCS and CVS
+       bool makeRCSRevision(std::string const &version, std::string &revis) 
const;
+       
        // GUI container for doVCCommandCall
        int doVCCommand(std::string const & cmd, support::FileName const & 
path, bool reportError = true);
        /**

Reply via email to