aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJarek Kobus <[email protected]>2024-01-20 14:26:36 +0100
committerJarek Kobus <[email protected]>2024-01-20 16:40:28 +0000
commit2d5499562274504960ee70e425ba807953dbdcf2 (patch)
treec2164a1f812629d4c65881240ee045233f57abe5
parent98c0e9764a77bf60c6f57b62cedbc0835f8f3e9e (diff)
GitUtils: Get rid of unused Stash::clear() method
Make parseStashLine() a local static method returning optional Stash. Change-Id: If702a4485ce87336ab829b522258e62a930589bf Reviewed-by: <[email protected]> Reviewed-by: Orgad Shaneh <[email protected]>
-rw-r--r--src/plugins/git/gitclient.cpp31
-rw-r--r--src/plugins/git/gitutils.cpp34
-rw-r--r--src/plugins/git/gitutils.h3
-rw-r--r--src/plugins/git/stashdialog.cpp2
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
+ * <base_sha1>+subject):
+\code
+stash@{1}: WIP on <branch>: <base_sha1> <subject_base_sha1>
+stash@{2}: On <branch>: <message>
+\endcode */
+
+static std::optional<Stash> 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<Stash> *stashes,
QString *errorMessage) const
{
@@ -3369,11 +3394,11 @@ bool GitClient::synchronousStashList(const FilePath &workingDirectory, QList<Sta
msgCannotRun(arguments, workingDirectory, result.cleanedStdErr(), errorMessage);
return false;
}
- Stash stash;
const QStringList lines = splitLines(result.cleanedStdOut());
for (const QString &line : lines) {
- if (stash.parseStashLine(line))
- stashes->push_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
- * <base_sha1>+subject):
-\code
-stash@{1}: WIP on <branch>: <base_sha1> <subject_base_sha1>
-stash@{2}: On <branch>: <message>
-\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<Stash>());
+ m_model->setStashes({});
} else {
QList<Stash> stashes;
gitClient().synchronousStashList(m_repository, &stashes);