From 2d5499562274504960ee70e425ba807953dbdcf2 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Sat, 20 Jan 2024 14:26:36 +0100 Subject: [PATCH] GitUtils: Get rid of unused Stash::clear() method Make parseStashLine() a local static method returning optional Stash. Change-Id: If702a4485ce87336ab829b522258e62a930589bf Reviewed-by: Reviewed-by: Orgad Shaneh --- src/plugins/git/gitclient.cpp | 31 +++++++++++++++++++++++++++--- src/plugins/git/gitutils.cpp | 34 --------------------------------- src/plugins/git/gitutils.h | 3 --- src/plugins/git/stashdialog.cpp | 2 +- 4 files changed, 29 insertions(+), 41 deletions(-) diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp index ff0dbf3ec10..505ffb24fe5 100644 --- a/src/plugins/git/gitclient.cpp +++ b/src/plugins/git/gitclient.cpp @@ -3357,6 +3357,31 @@ bool GitClient::synchronousStashRemove(const FilePath &workingDirectory, const Q return false; } +/* Parse a stash line in its 2 manifestations (with message/without message containing + * +subject): +\code +stash@{1}: WIP on : +stash@{2}: On : +\endcode */ + +static std::optional parseStashLine(const QString &l) +{ + const QChar colon = ':'; + const int branchPos = l.indexOf(colon); + if (branchPos < 0) + return {}; + const int messagePos = l.indexOf(colon, branchPos + 1); + if (messagePos < 0) + return {}; + // Branch spec + const int onIndex = l.indexOf("on ", branchPos + 2, Qt::CaseInsensitive); + if (onIndex == -1 || onIndex >= messagePos) + return {}; + return Stash{l.left(branchPos), + l.mid(onIndex + 3, messagePos - onIndex - 3), + l.mid(messagePos + 2)}; // skip blank +} + bool GitClient::synchronousStashList(const FilePath &workingDirectory, QList *stashes, QString *errorMessage) const { @@ -3369,11 +3394,11 @@ bool GitClient::synchronousStashList(const FilePath &workingDirectory, QListpush_back(stash); + const auto stash = parseStashLine(line); + if (stash) + stashes->push_back(*stash); } return true; } diff --git a/src/plugins/git/gitutils.cpp b/src/plugins/git/gitutils.cpp index f7684141a9e..3730efef325 100644 --- a/src/plugins/git/gitutils.cpp +++ b/src/plugins/git/gitutils.cpp @@ -8,40 +8,6 @@ namespace Git::Internal { -void Stash::clear() -{ - name.clear(); - branch.clear(); - message.clear(); -} - -/* Parse a stash line in its 2 manifestations (with message/without message containing - * +subject): -\code -stash@{1}: WIP on : -stash@{2}: On : -\endcode */ - -bool Stash::parseStashLine(const QString &l) -{ - const QChar colon = ':'; - const int branchPos = l.indexOf(colon); - if (branchPos < 0) - return false; - const int messagePos = l.indexOf(colon, branchPos + 1); - if (messagePos < 0) - return false; - // Branch spec - const int onIndex = l.indexOf("on ", branchPos + 2, Qt::CaseInsensitive); - if (onIndex == -1 || onIndex >= messagePos) - return false; - // Happy! - name = l.left(branchPos); - branch = l.mid(onIndex + 3, messagePos - onIndex - 3); - message = l.mid(messagePos + 2); // skip blank - return true; -} - // Make QInputDialog play nicely, widen it a bit. bool inputText(QWidget *parent, const QString &title, const QString &prompt, QString *s) { diff --git a/src/plugins/git/gitutils.h b/src/plugins/git/gitutils.h index 69c60649b09..e626365bb96 100644 --- a/src/plugins/git/gitutils.h +++ b/src/plugins/git/gitutils.h @@ -14,9 +14,6 @@ namespace Git::Internal { class Stash { public: - void clear(); - bool parseStashLine(const QString &l); - QString name; QString branch; QString message; diff --git a/src/plugins/git/stashdialog.cpp b/src/plugins/git/stashdialog.cpp index b0d2625761b..680f1a172d2 100644 --- a/src/plugins/git/stashdialog.cpp +++ b/src/plugins/git/stashdialog.cpp @@ -167,7 +167,7 @@ void StashDialog::refresh(const FilePath &repository, bool force) m_repository = repository; m_repositoryLabel->setText(msgRepositoryLabel(repository)); if (m_repository.isEmpty()) { - m_model->setStashes(QList()); + m_model->setStashes({}); } else { QList stashes; gitClient().synchronousStashList(m_repository, &stashes);