GitUtils: Get rid of unused Stash::clear() method

Make parseStashLine() a local static method returning optional Stash.

Change-Id: If702a4485ce87336ab829b522258e62a930589bf
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Jarek Kobus
2024-01-20 14:26:36 +01:00
parent 98c0e9764a
commit 2d54995622
4 changed files with 29 additions and 41 deletions

View File

@@ -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;
}

View File

@@ -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)
{

View File

@@ -14,9 +14,6 @@ namespace Git::Internal {
class Stash
{
public:
void clear();
bool parseStashLine(const QString &l);
QString name;
QString branch;
QString message;

View File

@@ -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);