diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp index 8154a076ebd..ff0dbf3ec10 100644 --- a/src/plugins/git/gitclient.cpp +++ b/src/plugins/git/gitclient.cpp @@ -629,8 +629,7 @@ public: static bool gitHasRgbColors() { - const unsigned gitVersion = gitClient().gitVersion().result(); - return gitVersion >= 0x020300U; + return gitClient().gitVersion().result() >= QVersionNumber{2, 3}; } static QString logColorName(TextEditor::TextStyle style) @@ -3429,24 +3428,21 @@ void GitClient::readConfigAsync(const FilePath &workingDirectory, const QStringL configFileCodec()); } -static unsigned parseGitVersion(const QString &output) +static QVersionNumber parseGitVersion(const QString &output) { // cut 'git version 1.6.5.1.sha' // another form: 'git version 1.9.rc1' const QRegularExpression versionPattern("^[^\\d]+(\\d+)\\.(\\d+)\\.(\\d+|rc\\d).*$"); - QTC_ASSERT(versionPattern.isValid(), return 0); + QTC_ASSERT(versionPattern.isValid(), return {}); const QRegularExpressionMatch match = versionPattern.match(output); - QTC_ASSERT(match.hasMatch(), return 0); - const unsigned majorV = match.captured(1).toUInt(nullptr, 16); - const unsigned minorV = match.captured(2).toUInt(nullptr, 16); - const unsigned patchV = match.captured(3).toUInt(nullptr, 16); - return version(majorV, minorV, patchV); + QTC_ASSERT(match.hasMatch(), return {}); + return {match.captured(1).toInt(), match.captured(2).toInt(), match.captured(3).toInt()}; } // determine version as '(major << 16) + (minor << 8) + patch' or 0. -QFuture GitClient::gitVersion() const +QFuture GitClient::gitVersion() const { - QFutureInterface fi; + QFutureInterface fi; fi.reportStarted(); // Do not execute repeatedly if that fails (due to git diff --git a/src/plugins/git/gitclient.h b/src/plugins/git/gitclient.h index d92ea2031ed..0e9ab3e8e68 100644 --- a/src/plugins/git/gitclient.h +++ b/src/plugins/git/gitclient.h @@ -15,8 +15,8 @@ #include #include -#include #include +#include #include QT_BEGIN_NAMESPACE @@ -124,7 +124,7 @@ public: ~GitClient(); Utils::FilePath vcsBinary() const override; - QFuture gitVersion() const; + QFuture gitVersion() const; void vcsExecAbortable(const Utils::FilePath &workingDirectory, const QStringList &arguments, bool isRebase = false, const QString &abortCommand = {}, @@ -398,7 +398,7 @@ private: const QString &gitCommand, ContinueCommandMode continueMode); mutable Utils::FilePath m_gitVersionForBinary; - mutable unsigned m_cachedGitVersion = 0; + mutable QVersionNumber m_cachedGitVersion; QString m_gitQtcEditor; QMap m_stashInfo; diff --git a/src/plugins/git/gitgrep.cpp b/src/plugins/git/gitgrep.cpp index f4a2c4f452b..2f1f0bda49a 100644 --- a/src/plugins/git/gitgrep.cpp +++ b/src/plugins/git/gitgrep.cpp @@ -202,8 +202,8 @@ GitGrep::GitGrep() layout->addWidget(m_treeLineEdit); // asynchronously check git version, add "recurse submodules" option if available Utils::onResultReady(gitClient().gitVersion(), this, - [this, pLayout = QPointer(layout)](unsigned version) { - if (version >= 0x021300 && pLayout) { + [this, pLayout = QPointer(layout)](const QVersionNumber &version) { + if (version >= QVersionNumber{2, 13} && pLayout) { m_recurseSubmodules = new QCheckBox(Tr::tr("Recurse submodules")); pLayout->addWidget(m_recurseSubmodules); } diff --git a/src/plugins/git/gitplugin.cpp b/src/plugins/git/gitplugin.cpp index 5485fa15cbc..91a309412c5 100644 --- a/src/plugins/git/gitplugin.cpp +++ b/src/plugins/git/gitplugin.cpp @@ -132,7 +132,7 @@ public: GitLogEditorWidgetT() : GitLogEditorWidget(new Editor) {} }; -const unsigned minimumRequiredVersion = 0x010900; +static const QVersionNumber minimumRequiredVersion{1, 9}; const VcsBaseSubmitEditorParameters submitParameters { Git::Constants::SUBMIT_MIMETYPE, @@ -1306,8 +1306,8 @@ void GitPluginPrivate::updateVersionWarning() QPointer curDocument = EditorManager::currentDocument(); if (!curDocument) return; - Utils::onResultReady(gitClient().gitVersion(), this, [curDocument](unsigned version) { - if (!curDocument || !version || version >= minimumRequiredVersion) + Utils::onResultReady(gitClient().gitVersion(), this, [curDocument](const QVersionNumber &version) { + if (!curDocument || version.isNull() || version >= minimumRequiredVersion) return; InfoBar *infoBar = curDocument->infoBar(); Id gitVersionWarning("GitVersionWarning"); @@ -1316,7 +1316,7 @@ void GitPluginPrivate::updateVersionWarning() infoBar->addInfo( InfoBarEntry(gitVersionWarning, Tr::tr("Unsupported version of Git found. Git %1 or later required.") - .arg(versionString(minimumRequiredVersion)), + .arg(minimumRequiredVersion.toString()), InfoBarEntry::GlobalSuppression::Enabled)); }); } diff --git a/src/plugins/git/gitutils.cpp b/src/plugins/git/gitutils.cpp index f75fe9cf451..f7684141a9e 100644 --- a/src/plugins/git/gitutils.cpp +++ b/src/plugins/git/gitutils.cpp @@ -58,17 +58,4 @@ bool inputText(QWidget *parent, const QString &title, const QString &prompt, QSt return true; } -static inline QString versionPart(unsigned part) -{ - return QString::number(part & 0xff, 16); -} - -QString versionString(unsigned ver) -{ - return QString::fromLatin1("%1.%2.%3") - .arg(versionPart(ver >> 16)) - .arg(versionPart(ver >> 8)) - .arg(versionPart(ver)); -} - } // Git::Internal diff --git a/src/plugins/git/gitutils.h b/src/plugins/git/gitutils.h index 928c8001ea9..69c60649b09 100644 --- a/src/plugins/git/gitutils.h +++ b/src/plugins/git/gitutils.h @@ -25,12 +25,4 @@ public: // Make QInputDialog play nicely bool inputText(QWidget *parent, const QString &title, const QString &prompt, QString *s); -// Version information following Qt convention -inline unsigned version(unsigned major, unsigned minor, unsigned patch) -{ - return (major << 16) + (minor << 8) + patch; -} - -QString versionString(unsigned ver); - } // Git::Internal