From 0882bb5cea28d7c9d35b65edcef7debdaa119a3d Mon Sep 17 00:00:00 2001 From: Jaak Ristioja Date: Fri, 10 May 2019 22:09:02 +0300 Subject: [PATCH 1/4] Renamed GIT_VERSION to GIT_VERSION_REQUIRED. --- src/common.h | 2 +- src/git.cpp | 4 ++-- src/namespace_def.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) 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..e1db6599 100644 --- a/src/git.cpp +++ b/src/git.cpp @@ -73,12 +73,12 @@ void Git::checkEnvironment() { if (run("git --version", &version)) { version = version.section(' ', -1, -1).section('.', 0, 2); - if (version < GIT_VERSION) { + if (version < GIT_VERSION_REQUIRED) { // 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."); 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); From 33db97148085fd1d3379acd135af57eee3a9c6c2 Mon Sep 17 00:00:00 2001 From: Jaak Ristioja Date: Fri, 10 May 2019 22:12:08 +0300 Subject: [PATCH 2/4] Git: Also store git version. Although qgit requires git version GIT_VERSION_REQUIRED or later, git has introduced new features and behavior since then. Hence qgit might need to distinguish between different git versions for running some commands. --- src/git.cpp | 1 + src/git.h | 1 + 2 files changed, 2 insertions(+) diff --git a/src/git.cpp b/src/git.cpp index e1db6599..891fd889 100644 --- a/src/git.cpp +++ b/src/git.cpp @@ -86,6 +86,7 @@ void Git::checkEnvironment() { MainExecErrorEvent* e = new MainExecErrorEvent(cmd, errorDesc); QApplication::postEvent(parent(), e); } + gitVersion = version; } else { dbs("Cannot find git files"); return; diff --git a/src/git.h b/src/git.h index aa4da442..c84d3c82 100644 --- a/src/git.h +++ b/src/git.h @@ -267,6 +267,7 @@ private slots: QString curBranchName; int filesLoadingStartOfs; bool cacheNeedsUpdate; + QString gitVersion; bool errorReportingEnabled; bool isMergeHead; bool isStGIT; From d315fd45afd6208cc64005536fef3d9f11cf5d47 Mon Sep 17 00:00:00 2001 From: Jaak Ristioja Date: Fri, 10 May 2019 22:21:16 +0300 Subject: [PATCH 3/4] Use --no-show-signature for "git log" for git >= 2.10.0. This is a workaround for not yet having proper support for parsing GPG signatures. Closes #66. --- src/git.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/git.cpp b/src/git.cpp index 891fd889..c5ff1b44 100644 --- a/src/git.cpp +++ b/src/git.cpp @@ -2167,6 +2167,9 @@ bool Git::startRevList(SCList args, FileHistory* fh) { } else {} // initCmd << QString("--early-output"); currently disabled + if (gitVersion >= "2.10.0") + initCmd << "--no-show-signature"; + return startParseProc(initCmd + args, fh, QString()); } @@ -2186,6 +2189,10 @@ bool Git::startUnappliedList() { "--pretty=format:" GIT_LOG_FORMAT "%b ^HEAD"); QStringList sl(cmd.split(' ')); + + if (gitVersion >= "2.10.0") + sl << "--no-show-signature"; + sl << unAppliedShaList; return startParseProc(sl, revData, QString()); } From ae562871fcb08033680d20603081a61abd9bb14e Mon Sep 17 00:00:00 2001 From: Jaak Ristioja Date: Sat, 11 May 2019 00:01:57 +0300 Subject: [PATCH 4/4] git: Fixed comparisons of git versions. Lexicographical comparison of version QStrings just doesn't work properly in all cases. --- src/git.cpp | 42 +++++++++++++++++++++++++++++++++++++++--- src/git.h | 1 + 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/git.cpp b/src/git.cpp index c5ff1b44..e5033c2e 100644 --- a/src/git.cpp +++ b/src/git.cpp @@ -67,13 +67,49 @@ 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_REQUIRED) { + if (gitVersionCompare(version, GIT_VERSION_REQUIRED) < 0) { // simply send information, the 'not compatible version' // policy should be implemented upstream @@ -2167,7 +2203,7 @@ bool Git::startRevList(SCList args, FileHistory* fh) { } else {} // initCmd << QString("--early-output"); currently disabled - if (gitVersion >= "2.10.0") + if (gitVersionCompare(gitVersion, "2.10.0") >= 0) initCmd << "--no-show-signature"; return startParseProc(initCmd + args, fh, QString()); @@ -2190,7 +2226,7 @@ bool Git::startUnappliedList() { QStringList sl(cmd.split(' ')); - if (gitVersion >= "2.10.0") + if (gitVersionCompare(gitVersion, "2.10.0") >= 0) sl << "--no-show-signature"; sl << unAppliedShaList; diff --git a/src/git.h b/src/git.h index c84d3c82..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);