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.
This commit is contained in:
Pavel Sanda 2013-02-09 19:28:01 -08:00
parent a95ed3a2b9
commit 75090250d4
2 changed files with 59 additions and 8 deletions

View File

@ -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<int>(revis);
// revision and filename
string pointer;
// go back for "minus" revisions
if (rev <= 0)
pointer = "HEAD~" + convert<string>(-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;
}

View File

@ -10,6 +10,7 @@
#include <config.h>
#include <support/debug.h>
#include <limits>
#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<int>(revstring);
bool enableBetween = true;
// GIT case, hash is long
if (revstring.length() > 20) {
enableBetween = false;
rev = numeric_limits<int>::max();
} else {
// RCS case
if (!isStrInt(revstring))
revstring = rsplit(revstring, tmp , '.' );
// both SVN & RCS cases
if (isStrInt(revstring))
rev = convert<int>(revstring);
}
// later we can provide comparison between two hashes
betweenrevRB->setEnabled(enableBetween);
okPB->setEnabled(rev);
rev1SB->setMaximum(rev);