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_;