Git: Use QVersionNumber for git version

Parse the version string with base 10 now.

Amends abee98b44817d1aee63b5cd9b673d0c3aa1733ba

Change-Id: I2f0b47380a9714b3f3de475ddabe78875db3b608
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Jarek Kobus
2024-01-20 14:10:06 +01:00
parent cd4f62ebf8
commit 98c0e9764a
6 changed files with 16 additions and 41 deletions

View File

@@ -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<unsigned> GitClient::gitVersion() const
QFuture<QVersionNumber> GitClient::gitVersion() const
{
QFutureInterface<unsigned> fi;
QFutureInterface<QVersionNumber> fi;
fi.reportStarted();
// Do not execute repeatedly if that fails (due to git

View File

@@ -15,8 +15,8 @@
#include <vcsbase/vcsbaseclient.h>
#include <QObject>
#include <QString>
#include <QStringList>
#include <QVersionNumber>
#include <QWidget>
QT_BEGIN_NAMESPACE
@@ -124,7 +124,7 @@ public:
~GitClient();
Utils::FilePath vcsBinary() const override;
QFuture<unsigned> gitVersion() const;
QFuture<QVersionNumber> 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<Utils::FilePath, StashInfo> m_stashInfo;

View File

@@ -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<QHBoxLayout>(layout)](unsigned version) {
if (version >= 0x021300 && pLayout) {
[this, pLayout = QPointer<QHBoxLayout>(layout)](const QVersionNumber &version) {
if (version >= QVersionNumber{2, 13} && pLayout) {
m_recurseSubmodules = new QCheckBox(Tr::tr("Recurse submodules"));
pLayout->addWidget(m_recurseSubmodules);
}

View File

@@ -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<IDocument> 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));
});
}

View File

@@ -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

View File

@@ -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