From 75090250d4c61245d7b61326b9469754bf34a61a Mon Sep 17 00:00:00 2001 From: Pavel Sanda Date: Sat, 9 Feb 2013 19:28:01 -0800 Subject: [PATCH] Add very simple revision comparison for git. At this moment we do not allow comparison between arbitrary hashes, but except GUI the code is ready. Thanks to the powerful way of git addressing we could even ask for comparisons like '-2 weeks back' if someone wants to play with GuiCompareHistory. --- src/VCBackend.cpp | 45 +++++++++++++++++++++++-- src/frontends/qt4/GuiCompareHistory.cpp | 22 +++++++++--- 2 files changed, 59 insertions(+), 8 deletions(-) diff --git a/src/VCBackend.cpp b/src/VCBackend.cpp index 599e331364..bb963f1f15 100644 --- a/src/VCBackend.cpp +++ b/src/VCBackend.cpp @@ -2213,15 +2213,54 @@ void GIT::getLog(FileName const & tmpf) } -bool GIT::prepareFileRevision(string const & /*revis*/, string & /*f*/) +//at this moment we don't accept revision SHA, but just number of revision steps back +//GUI and infrastucture needs to be changed first +bool GIT::prepareFileRevision(string const & revis, string & f) { - return false; + // anything positive means we got hash, not "0" or minus revision + int rev = 1; + + // hash is rarely number and should be long + if (isStrInt(revis) && revis.length()<20) + rev = convert(revis); + + // revision and filename + string pointer; + + // go back for "minus" revisions + if (rev <= 0) + pointer = "HEAD~" + convert(-rev); + // normal hash + else + pointer = revis; + + pointer += ":"; + + if (rev <= 0) + if (!getFileRevisionInfo()) + return false; + + FileName tmpf = FileName::tempName("lyxvcrev_" + revis + "_"); + if (tmpf.empty()) { + LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf); + return false; + } + + doVCCommand("git show " + pointer + "./" + + quoteName(onlyFileName(owner_->absFileName())) + + " > " + quoteName(tmpf.toFilesystemEncoding()), + FileName(owner_->filePath())); + if (tmpf.isFileEmpty()) + return false; + + f = tmpf.absFileName(); + return true; } bool GIT::prepareFileRevisionEnabled() { - return false; + return true; } diff --git a/src/frontends/qt4/GuiCompareHistory.cpp b/src/frontends/qt4/GuiCompareHistory.cpp index 711cd51dcb..d176a387c4 100644 --- a/src/frontends/qt4/GuiCompareHistory.cpp +++ b/src/frontends/qt4/GuiCompareHistory.cpp @@ -10,6 +10,7 @@ #include #include +#include #include "GuiCompareHistory.h" @@ -51,11 +52,22 @@ bool GuiCompareHistory::initialiseParams(std::string const &) int rev=0; string tmp; - // RCS case - if (!isStrInt(revstring)) - revstring = rsplit(revstring, tmp , '.' ); - if (isStrInt(revstring)) - rev = convert(revstring); + bool enableBetween = true; + // GIT case, hash is long + if (revstring.length() > 20) { + enableBetween = false; + rev = numeric_limits::max(); + } else { + // RCS case + if (!isStrInt(revstring)) + revstring = rsplit(revstring, tmp , '.' ); + // both SVN & RCS cases + if (isStrInt(revstring)) + rev = convert(revstring); + } + + // later we can provide comparison between two hashes + betweenrevRB->setEnabled(enableBetween); okPB->setEnabled(rev); rev1SB->setMaximum(rev);