GitClient: Change synchronousStashList() signature

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

Change-Id: I9bf156c5ecda476a5def3c3490d6cb13d011a3cd
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Jarek Kobus
2024-01-20 16:59:51 +01:00
parent ee09a28e83
commit cbec5438b4
4 changed files with 16 additions and 24 deletions

View File

@@ -399,9 +399,8 @@ bool BranchView::checkout()
if (gitClient().gitStatus(m_repository, StatusMode(NoUntracked | NoSubmodules)) != GitClient::StatusChanged) if (gitClient().gitStatus(m_repository, StatusMode(NoUntracked | NoSubmodules)) != GitClient::StatusChanged)
branchCheckoutDialog.foundNoLocalChanges(); branchCheckoutDialog.foundNoLocalChanges();
QList<Stash> stashes; const QList<Stash> stashes = gitClient().synchronousStashList(m_repository);
gitClient().synchronousStashList(m_repository, &stashes); for (const Stash &stash : stashes) {
for (const Stash &stash : std::as_const(stashes)) {
if (stash.message.startsWith(popMessageStart)) { if (stash.message.startsWith(popMessageStart)) {
branchCheckoutDialog.foundStashForNextBranch(); branchCheckoutDialog.foundStashForNextBranch();
break; break;
@@ -433,10 +432,9 @@ bool BranchView::checkout()
if (moveChanges) { if (moveChanges) {
gitClient().endStashScope(m_repository); gitClient().endStashScope(m_repository);
} else if (popStash) { } else if (popStash) {
QList<Stash> stashes;
QString stashName; QString stashName;
gitClient().synchronousStashList(m_repository, &stashes); const QList<Stash> stashes = gitClient().synchronousStashList(m_repository);
for (const Stash &stash : std::as_const(stashes)) { for (const Stash &stash : stashes) {
if (stash.message.startsWith(popMessageStart)) { if (stash.message.startsWith(popMessageStart)) {
stashName = stash.name; stashName = stash.name;
break; break;

View File

@@ -1837,12 +1837,10 @@ static QString stashNameFromMessage(const FilePath &workingDirectory, const QStr
if (message.startsWith(stashNamePrefix)) if (message.startsWith(stashNamePrefix))
return message; return message;
// Retrieve list and find via message // Retrieve list and find via message
QList<Stash> stashes; const QList<Stash> stashes = gitClient().synchronousStashList(workingDirectory);
if (!gitClient().synchronousStashList(workingDirectory, &stashes)) for (const Stash &stash : stashes) {
return {}; if (stash.message == message)
for (const Stash &s : std::as_const(stashes)) { return stash.name;
if (s.message == message)
return s.name;
} }
//: 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\".")
@@ -3376,25 +3374,23 @@ static std::optional<Stash> parseStashLine(const QString &l)
l.mid(messagePos + 2)}; // skip blank l.mid(messagePos + 2)}; // skip blank
} }
bool GitClient::synchronousStashList(const FilePath &workingDirectory, QList<Stash> *stashes, QList<Stash> GitClient::synchronousStashList(const FilePath &workingDirectory) const
QString *errorMessage) const
{ {
stashes->clear();
const QStringList arguments = {"stash", "list", noColorOption}; const QStringList arguments = {"stash", "list", noColorOption};
const CommandResult result = vcsSynchronousExec(workingDirectory, arguments, const CommandResult result = vcsSynchronousExec(workingDirectory, arguments,
RunFlags::ForceCLocale); RunFlags::ForceCLocale);
if (result.result() != ProcessResult::FinishedWithSuccess) { if (result.result() != ProcessResult::FinishedWithSuccess) {
msgCannotRun(arguments, workingDirectory, result.cleanedStdErr(), errorMessage); msgCannotRun(arguments, workingDirectory, result.cleanedStdErr(), nullptr);
return false; return {};
} }
const QStringList lines = splitLines(result.cleanedStdOut()); const QStringList lines = splitLines(result.cleanedStdOut());
QList<Stash> stashes;
for (const QString &line : lines) { for (const QString &line : lines) {
const auto stash = parseStashLine(line); const auto stash = parseStashLine(line);
if (stash) if (stash)
stashes->push_back(*stash); stashes.push_back(*stash);
} }
return true; return stashes;
} }
// Read a single-line config value, return trimmed // Read a single-line config value, return trimmed

View File

@@ -277,8 +277,7 @@ public:
void stashPop(const Utils::FilePath &workingDirectory, const QString &stash = {}); void stashPop(const Utils::FilePath &workingDirectory, const QString &stash = {});
void revertFiles(const QStringList &files, bool revertStaging); void revertFiles(const QStringList &files, bool revertStaging);
bool synchronousStashList(const Utils::FilePath &workingDirectory, QList<Stash> *stashes, QList<Stash> synchronousStashList(const Utils::FilePath &workingDirectory) const;
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;

View File

@@ -169,8 +169,7 @@ void StashDialog::refresh(const FilePath &repository, bool force)
if (m_repository.isEmpty()) { if (m_repository.isEmpty()) {
m_model->setStashes({}); m_model->setStashes({});
} else { } else {
QList<Stash> stashes; const QList<Stash> stashes = gitClient().synchronousStashList(m_repository);
gitClient().synchronousStashList(m_repository, &stashes);
m_model->setStashes(stashes); m_model->setStashes(stashes);
if (!stashes.isEmpty()) { if (!stashes.isEmpty()) {
for (int c = 0; c < ColumnCount; c++) for (int c = 0; c < ColumnCount; c++)