summaryrefslogtreecommitdiff
path: root/src/plugins/git/gitclient.cpp
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2022-06-29 10:21:12 +0200
committerEike Ziller <eike.ziller@qt.io>2022-06-29 12:39:28 +0000
commitf4c60fdf58c95b872a8b9872b479d327f8fe5990 (patch)
tree701c060072d715dc1020cd9eda23a9363e4ad7ed /src/plugins/git/gitclient.cpp
parent70fb66f9ee232820cb3a00748c2866ddbb01dbbe (diff)
downloadqt-creator-f4c60fdf58c95b872a8b9872b479d327f8fe5990.tar.gz
Git: Do not run 'git --version' synchronously at startup
We can easily delay this, and if git acts up for some reason, we don't have to block startup. Task-number: QTCREATORBUG-27765 Change-Id: I25aa6f8d04d1fd4b9d87f8ccf7ffd591f7bbe519 Reviewed-by: hjk <hjk@qt.io> Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Diffstat (limited to 'src/plugins/git/gitclient.cpp')
-rw-r--r--src/plugins/git/gitclient.cpp65
1 files changed, 37 insertions, 28 deletions
diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp
index 8062383945..5ac84c5ac4 100644
--- a/src/plugins/git/gitclient.cpp
+++ b/src/plugins/git/gitclient.cpp
@@ -648,7 +648,7 @@ public:
static bool gitHasRgbColors()
{
- const unsigned gitVersion = GitClient::instance()->gitVersion();
+ const unsigned gitVersion = GitClient::instance()->gitVersion().result();
return gitVersion >= 0x020300U;
}
@@ -3611,36 +3611,10 @@ QString GitClient::readOneLine(const FilePath &workingDirectory, const QStringLi
return proc.cleanedStdOut().trimmed();
}
-// determine version as '(major << 16) + (minor << 8) + patch' or 0.
-unsigned GitClient::gitVersion(QString *errorMessage) const
-{
- const FilePath newGitBinary = vcsBinary();
- if (m_gitVersionForBinary != newGitBinary && !newGitBinary.isEmpty()) {
- // Do not execute repeatedly if that fails (due to git
- // not being installed) until settings are changed.
- m_cachedGitVersion = synchronousGitVersion(errorMessage);
- m_gitVersionForBinary = newGitBinary;
- }
- return m_cachedGitVersion;
-}
-
-// determine version as '(major << 16) + (minor << 8) + patch' or 0.
-unsigned GitClient::synchronousGitVersion(QString *errorMessage) const
+static unsigned parseGitVersion(const QString &output)
{
- if (vcsBinary().isEmpty())
- return 0;
-
- // run git --version
- QtcProcess proc;
- vcsSynchronousExec(proc, {}, {"--version"}, silentFlags);
- if (proc.result() != ProcessResult::FinishedWithSuccess) {
- msgCannotRun(tr("Cannot determine Git version: %1").arg(proc.cleanedStdErr()), errorMessage);
- return 0;
- }
-
// cut 'git version 1.6.5.1.sha'
// another form: 'git version 1.9.rc1'
- const QString output = proc.cleanedStdOut();
const QRegularExpression versionPattern("^[^\\d]+(\\d+)\\.(\\d+)\\.(\\d+|rc\\d).*$");
QTC_ASSERT(versionPattern.isValid(), return 0);
const QRegularExpressionMatch match = versionPattern.match(output);
@@ -3651,6 +3625,41 @@ unsigned GitClient::synchronousGitVersion(QString *errorMessage) const
return version(majorV, minorV, patchV);
}
+// determine version as '(major << 16) + (minor << 8) + patch' or 0.
+QFuture<unsigned> GitClient::gitVersion() const
+{
+ QFutureInterface<unsigned> fi;
+ fi.reportStarted();
+
+ // Do not execute repeatedly if that fails (due to git
+ // not being installed) until settings are changed.
+ const FilePath newGitBinary = vcsBinary();
+ const bool needToRunGit = m_gitVersionForBinary != newGitBinary && !newGitBinary.isEmpty();
+ if (needToRunGit) {
+ auto proc = new QtcProcess(const_cast<GitClient *>(this));
+ connect(proc, &QtcProcess::done, this, [this, proc, fi, newGitBinary]() mutable {
+ if (proc->result() == ProcessResult::FinishedWithSuccess) {
+ m_cachedGitVersion = parseGitVersion(proc->cleanedStdOut());
+ m_gitVersionForBinary = newGitBinary;
+ fi.reportResult(m_cachedGitVersion);
+ fi.reportFinished();
+ }
+ proc->deleteLater();
+ });
+
+ proc->setTimeoutS(vcsTimeoutS());
+ proc->setEnvironment(processEnvironment());
+ proc->setCommand({newGitBinary, {"--version"}});
+ proc->start();
+ } else {
+ // already cached
+ fi.reportResult(m_cachedGitVersion);
+ fi.reportFinished();
+ }
+
+ return fi.future();
+}
+
bool GitClient::StashInfo::init(const FilePath &workingDirectory, const QString &command,
StashFlag flag, PushAction pushAction)
{