From c6f6d20cdbddcfffea9ec26bd5288b39134f9308 Mon Sep 17 00:00:00 2001 From: Pavel Sanda Date: Fri, 12 Feb 2010 11:07:28 +0000 Subject: [PATCH] Slowly toward version control + comparison git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33443 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/VCBackend.cpp | 33 +++++++++++++++++++++++++++++++++ src/VCBackend.h | 10 +++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/VCBackend.cpp b/src/VCBackend.cpp index c7e06508b8..fd48b79e8a 100644 --- a/src/VCBackend.cpp +++ b/src/VCBackend.cpp @@ -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(rev_file_cache_); + // go back for minus rev + else if (rev < 0) { + rev = rev + convert(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(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; diff --git a/src/VCBackend.h b/src/VCBackend.h index 7a277edcc6..e5d03331b5 100644 --- a/src/VCBackend.h +++ b/src/VCBackend.h @@ -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_; -- 2.39.5