]> git.lyx.org Git - lyx.git/commitdiff
Slowly toward version control + comparison
authorPavel Sanda <sanda@lyx.org>
Fri, 12 Feb 2010 11:07:28 +0000 (11:07 +0000)
committerPavel Sanda <sanda@lyx.org>
Fri, 12 Feb 2010 11:07:28 +0000 (11:07 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33443 a592a061-630c-0410-9148-cb99ea01b6c8

src/VCBackend.cpp
src/VCBackend.h

index c7e06508b86c97b62ebb218d657e0970b838303b..fd48b79e8a4173e87fd181387374a96307b6a473 100644 (file)
@@ -19,6 +19,7 @@
 #include "frontends/alert.h"
 #include "frontends/Application.h"
 
+#include "support/convert.h"
 #include "support/debug.h"
 #include "support/filetools.h"
 #include "support/gettext.h"
@@ -981,6 +982,38 @@ void SVN::getLog(FileName const & tmpf)
 }
 
 
+bool SVN::prepareFileRevision(int rev, string & f)
+{
+       if (rev <= 0)
+               if (!getFileRevisionInfo())
+                       return false;
+       if (rev == 0)
+               rev = convert<int>(rev_file_cache_);
+       // go back for minus rev
+       else if (rev < 0) {
+               rev = rev + convert<int>(rev_file_cache_);
+               if (rev < 1)
+                       return false;
+       }
+
+       FileName tmpf = FileName::tempName("lyxvcrev");
+       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()))
+                     + " > " + quoteName(tmpf.toFilesystemEncoding()),
+               FileName(owner_->filePath()));
+       if (tmpf.isFileEmpty())
+               return false;
+
+       f = tmpf.absFilename();
+       return true;
+}
+
+
 bool SVN::toggleReadOnlyEnabled()
 {
        return false;
index 7a277edcc6393f76dc4003334e3269c017e5bf97..e5d03331b5b25a277e8e58a516fbf6b87814a467 100644 (file)
@@ -275,6 +275,14 @@ protected:
        bool isLocked() const;
        /// acquire/release write lock for the current file
        void fileLock(bool lock, support::FileName const & tmpf, std::string & status);
+       /**
+        * Prepare revision rev of the file into newly created temporary file
+        * and save the filename into parameter f.
+        * Parameter rev can be either revision number or negative number
+        * which is interpreted as how many revision back from the current
+        * one do we want. rev=0 is reserved for the last (committed) revision.
+        */
+       bool prepareFileRevision(int rev, std::string & f);
 
 private:
        support::FileName file_;
@@ -287,7 +295,7 @@ private:
         * was already unsuccessful.
         */
        bool getFileRevisionInfo();
-       /// cache for file revision number, "?" if already unsuccessful
+       /// cache for file revision number, "?" if already unsuccessful, isNumber==true
        std::string rev_file_cache_;
        /// cache for author of last commit
        std::string rev_author_cache_;