diff --git a/src/common.h b/src/common.h index 4e1e8514..dca50e78 100644 --- a/src/common.h +++ b/src/common.h @@ -66,7 +66,7 @@ uint qHash(const ShaString&); // optimized custom hash for sha strings namespace QGit { // minimum git version required - extern const QString GIT_VERSION; + extern const QString GIT_VERSION_REQUIRED; // tab pages enum TabType { diff --git a/src/git.cpp b/src/git.cpp index 6a80e700..e5033c2e 100644 --- a/src/git.cpp +++ b/src/git.cpp @@ -67,18 +67,54 @@ Git::Git(QObject* p) : QObject(p) { revsFiles.reserve(MAX_DICT_SIZE); } +int Git::gitVersionCompare(QString lhs, QString rhs) { + lhs = lhs.trimmed(); + rhs = rhs.trimmed(); + + QRegExp versionRegex("\\d+\\.\\d+\\.\\d+(-rc\\d+)?"); + if (!versionRegex.exactMatch(lhs)) { + dbp("ASSERT: Incorrect git version given: \"%1\"", lhs); + return -1; + } + if (!versionRegex.exactMatch(rhs)) { + dbp("ASSERT: Incorrect git version given: \"%1\"", rhs); + return -1; + } + + lhs.replace("-rc", "."); + rhs.replace("-rc", "."); + QStringList lcs = lhs.split('.'); + QStringList rcs = rhs.split('.'); + + for (int i = 0; i < 3; ++i) { + uint lc = lcs.takeFirst().toUInt(); + uint rc = rcs.takeFirst().toUInt(); + if (lc != rc) + return lc < rc ? -1 : 1; + } + if (lcs.isEmpty() != rcs.isEmpty()) // -rc present in one only + return lcs.isEmpty() ? 1 : -1; + if (lcs.isEmpty()) { // -rc present in both + uint lc = lcs.takeFirst().toUInt(); + uint rc = rcs.takeFirst().toUInt(); + if (lc != rc) + return lc < rc ? -1 : 1; + } + return 0; +} + void Git::checkEnvironment() { QString version; if (run("git --version", &version)) { version = version.section(' ', -1, -1).section('.', 0, 2); - if (version < GIT_VERSION) { + if (gitVersionCompare(version, GIT_VERSION_REQUIRED) < 0) { // simply send information, the 'not compatible version' // policy should be implemented upstream const QString cmd("Current git version is " + version + - " but is required " + GIT_VERSION + " or better"); + " but is required " + GIT_VERSION_REQUIRED + " or better"); const QString errorDesc("Your installed git is too old." "\nPlease upgrade to avoid possible misbehaviours."); @@ -86,6 +122,7 @@ void Git::checkEnvironment() { MainExecErrorEvent* e = new MainExecErrorEvent(cmd, errorDesc); QApplication::postEvent(parent(), e); } + gitVersion = version; } else { dbs("Cannot find git files"); return; @@ -2166,6 +2203,9 @@ bool Git::startRevList(SCList args, FileHistory* fh) { } else {} // initCmd << QString("--early-output"); currently disabled + if (gitVersionCompare(gitVersion, "2.10.0") >= 0) + initCmd << "--no-show-signature"; + return startParseProc(initCmd + args, fh, QString()); } @@ -2185,6 +2225,10 @@ bool Git::startUnappliedList() { "--pretty=format:" GIT_LOG_FORMAT "%b ^HEAD"); QStringList sl(cmd.split(' ')); + + if (gitVersionCompare(gitVersion, "2.10.0") >= 0) + sl << "--no-show-signature"; + sl << unAppliedShaList; return startParseProc(sl, revData, QString()); } diff --git a/src/git.h b/src/git.h index aa4da442..a1576e2a 100644 --- a/src/git.h +++ b/src/git.h @@ -56,6 +56,7 @@ Q_OBJECT typedef QList TreeInfo; void setDefaultModel(FileHistory* fh) { revData = fh; } + static int gitVersionCompare(QString lhs, QString rhs); void checkEnvironment(); void userInfo(SList info); const QStringList getGitConfigList(bool global); @@ -267,6 +268,7 @@ private slots: QString curBranchName; int filesLoadingStartOfs; bool cacheNeedsUpdate; + QString gitVersion; bool errorReportingEnabled; bool isMergeHead; bool isStGIT; diff --git a/src/namespace_def.cpp b/src/namespace_def.cpp index 29de3537..883b279c 100644 --- a/src/namespace_def.cpp +++ b/src/namespace_def.cpp @@ -124,7 +124,7 @@ const ShaString QGit::toPersistentSha(const QString& sha, QVector& v } // minimum git version required -const QString QGit::GIT_VERSION = "1.5.5"; +const QString QGit::GIT_VERSION_REQUIRED = "1.5.5"; // colors const QColor QGit::BROWN = QColor(150, 75, 0);