GitClient: Make stashNameFromMessage() a static local function

Get rid of unused errorMessage arg.
Return the stash name directly.

Change-Id: I11e7b0ef4dcaa38293cbf5d20b7213cc06850257
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Jarek Kobus
2024-01-20 16:20:34 +01:00
parent 2d54995622
commit ee09a28e83
2 changed files with 11 additions and 20 deletions

View File

@@ -1831,29 +1831,23 @@ bool GitClient::executeSynchronousStash(const FilePath &workingDirectory,
} }
// Resolve a stash name from message // Resolve a stash name from message
bool GitClient::stashNameFromMessage(const FilePath &workingDirectory, static QString stashNameFromMessage(const FilePath &workingDirectory, const QString &message)
const QString &message, QString *name,
QString *errorMessage) const
{ {
// All happy // All happy
if (message.startsWith(stashNamePrefix)) { if (message.startsWith(stashNamePrefix))
*name = message; return message;
return true;
}
// Retrieve list and find via message // Retrieve list and find via message
QList<Stash> stashes; QList<Stash> stashes;
if (!synchronousStashList(workingDirectory, &stashes, errorMessage)) if (!gitClient().synchronousStashList(workingDirectory, &stashes))
return false; return {};
for (const Stash &s : std::as_const(stashes)) { for (const Stash &s : std::as_const(stashes)) {
if (s.message == message) { if (s.message == message)
*name = s.name; return s.name;
return true;
}
} }
//: Look-up of a stash via its descriptive message failed. //: Look-up of a stash via its descriptive message failed.
msgCannotRun(Tr::tr("Cannot resolve stash message \"%1\" in \"%2\".") msgCannotRun(Tr::tr("Cannot resolve stash message \"%1\" in \"%2\".")
.arg(message, workingDirectory.toUserOutput()), errorMessage); .arg(message, workingDirectory.toUserOutput()), nullptr);
return false; return {};
} }
bool GitClient::synchronousBranchCmd(const FilePath &workingDirectory, QStringList branchArgs, bool GitClient::synchronousBranchCmd(const FilePath &workingDirectory, QStringList branchArgs,
@@ -3601,8 +3595,8 @@ bool GitClient::StashInfo::stashingFailed() const
void GitClient::StashInfo::end() void GitClient::StashInfo::end()
{ {
if (m_stashResult == Stashed) { if (m_stashResult == Stashed) {
QString stashName; const QString stashName = stashNameFromMessage(m_workingDir, m_message);
if (gitClient().stashNameFromMessage(m_workingDir, m_message, &stashName)) if (!stashName.isEmpty())
gitClient().stashPop(m_workingDir, stashName); gitClient().stashPop(m_workingDir, stashName);
} }

View File

@@ -279,9 +279,6 @@ public:
void revertFiles(const QStringList &files, bool revertStaging); void revertFiles(const QStringList &files, bool revertStaging);
bool synchronousStashList(const Utils::FilePath &workingDirectory, QList<Stash> *stashes, bool synchronousStashList(const Utils::FilePath &workingDirectory, QList<Stash> *stashes,
QString *errorMessage = nullptr) const; QString *errorMessage = nullptr) const;
// Resolve a stash name from message (for IVersionControl's names).
bool stashNameFromMessage(const Utils::FilePath &workingDirectory, const QString &messge, QString *name,
QString *errorMessage = nullptr) const;
QString readGitVar(const Utils::FilePath &workingDirectory, const QString &configVar) const; QString readGitVar(const Utils::FilePath &workingDirectory, const QString &configVar) const;
QString readConfigValue(const Utils::FilePath &workingDirectory, const QString &configVar) const; QString readConfigValue(const Utils::FilePath &workingDirectory, const QString &configVar) const;