From 70e013fd254bbc27eff82a2d64af1b3f882e0b56 Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Thu, 8 Feb 2024 11:21:32 +0100 Subject: [PATCH] Git: Cleanup gitExecutable() Using expected removes a bunch of handling code. Change-Id: Id524912d82aa693fbb39c7e7fa34abd77153f92e Reviewed-by: Reviewed-by: Orgad Shaneh --- src/plugins/git/gitclient.cpp | 8 ++------ src/plugins/git/gitplugin.cpp | 8 +++----- src/plugins/git/gitsettings.cpp | 15 +++------------ src/plugins/git/gitsettings.h | 2 +- 4 files changed, 9 insertions(+), 24 deletions(-) diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp index 6f9224dda04..5523ba1b48a 100644 --- a/src/plugins/git/gitclient.cpp +++ b/src/plugins/git/gitclient.cpp @@ -929,7 +929,7 @@ void GitClient::requestReload(const QString &documentId, const FilePath &source, QTC_ASSERT(document, return); GitBaseDiffEditorController *controller = factory(document); QTC_ASSERT(controller, return); - controller->setVcsBinary(settings().gitExecutable()); + controller->setVcsBinary(settings().gitExecutable().value_or(FilePath{})); controller->setProcessEnvironment(processEnvironment()); controller->setWorkingDirectory(workingDirectory); @@ -2546,11 +2546,7 @@ bool GitClient::launchGitBash(const FilePath &workingDirectory) FilePath GitClient::vcsBinary() const { - bool ok; - Utils::FilePath binary = settings().gitExecutable(&ok); - if (!ok) - return {}; - return binary; + return settings().gitExecutable().value_or(FilePath{}); } // returns first line from log and removes it diff --git a/src/plugins/git/gitplugin.cpp b/src/plugins/git/gitplugin.cpp index c3ac447c570..993ea54fb49 100644 --- a/src/plugins/git/gitplugin.cpp +++ b/src/plugins/git/gitplugin.cpp @@ -409,11 +409,9 @@ void GitPluginPrivate::onApplySettings() { emit configurationChanged(); updateRepositoryBrowserAction(); - bool gitFoundOk; - QString errorMessage; - settings().gitExecutable(&gitFoundOk, &errorMessage); - if (!gitFoundOk) { - QTimer::singleShot(0, this, [errorMessage] { + const expected_str result = settings().gitExecutable(); + if (!result) { + QTimer::singleShot(0, this, [errorMessage = result.error()] { AsynchronousMessageBox::warning(Tr::tr("Git Settings"), errorMessage); }); } diff --git a/src/plugins/git/gitsettings.cpp b/src/plugins/git/gitsettings.cpp index 43b0e8ae6c7..95938a41d88 100644 --- a/src/plugins/git/gitsettings.cpp +++ b/src/plugins/git/gitsettings.cpp @@ -164,14 +164,8 @@ GitSettings::GitSettings() readSettings(); } -FilePath GitSettings::gitExecutable(bool *ok, QString *errorMessage) const +expected_str GitSettings::gitExecutable() const { - // Locate binary in path if one is specified, otherwise default to pathless binary. - if (ok) - *ok = true; - if (errorMessage) - errorMessage->clear(); - if (tryResolve) { resolvedBinPath = binaryPath(); if (!resolvedBinPath.isAbsolutePath()) @@ -180,11 +174,8 @@ FilePath GitSettings::gitExecutable(bool *ok, QString *errorMessage) const } 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().toUserOutput(), path()); + return make_unexpected(Tr::tr("The binary \"%1\" could not be located in the path \"%2\"") + .arg(binaryPath().toUserOutput(), path())); } return resolvedBinPath; } diff --git a/src/plugins/git/gitsettings.h b/src/plugins/git/gitsettings.h index f6ec650c2e8..2932cc78c0a 100644 --- a/src/plugins/git/gitsettings.h +++ b/src/plugins/git/gitsettings.h @@ -44,7 +44,7 @@ public: mutable Utils::FilePath resolvedBinPath; mutable bool tryResolve = true; - Utils::FilePath gitExecutable(bool *ok = nullptr, QString *errorMessage = nullptr) const; + Utils::expected_str gitExecutable() const; static QString trIgnoreWhitespaceChanges(); static QString trIgnoreLineMoves();