Git: Reduce PATH searches for executable

This reduces executions in BranchModel::updateUpstreamStatus (which is
called for each local branch with a tracking branch) from 3s to ~700ms
on Windows.

Change-Id: I92651ba8f37987bef49a80b46963964ae8cacb3c
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
Orgad Shaneh
2023-02-13 19:17:38 +02:00
committed by Orgad Shaneh
parent 728e73ea9d
commit c2cfe596b9
2 changed files with 14 additions and 5 deletions

View File

@@ -116,6 +116,9 @@ GitSettings::GitSettings()
refLogShowDate.setSettingsKey("RefLogShowDate");
timeout.setDefaultValue(Utils::HostOsInfo::isWindowsHost() ? 60 : 30);
connect(&binaryPath, &StringAspect::valueChanged, this, [this] { tryResolve = true; });
connect(&path, &StringAspect::valueChanged, this, [this] { tryResolve = true; });
}
FilePath GitSettings::gitExecutable(bool *ok, QString *errorMessage) const
@@ -126,18 +129,21 @@ FilePath GitSettings::gitExecutable(bool *ok, QString *errorMessage) const
if (errorMessage)
errorMessage->clear();
FilePath binPath = binaryPath.filePath();
if (!binPath.isAbsolutePath())
binPath = binPath.searchInPath({path.filePath()}, FilePath::PrependToPath);
if (tryResolve) {
resolvedBinPath = binaryPath.filePath();
if (!resolvedBinPath.isAbsolutePath())
resolvedBinPath = resolvedBinPath.searchInPath({path.filePath()}, FilePath::PrependToPath);
tryResolve = false;
}
if (binPath.isEmpty()) {
if (resolvedBinPath.isEmpty()) {
if (ok)
*ok = false;
if (errorMessage)
*errorMessage = Tr::tr("The binary \"%1\" could not be located in the path \"%2\"")
.arg(binaryPath.value(), path.value());
}
return binPath;
return resolvedBinPath;
}
// GitSettingsPage

View File

@@ -40,6 +40,9 @@ public:
Utils::BoolAspect refLogShowDate;
Utils::BoolAspect instantBlame;
mutable Utils::FilePath resolvedBinPath;
mutable bool tryResolve = true;
Utils::FilePath gitExecutable(bool *ok = nullptr, QString *errorMessage = nullptr) const;
};