diff options
author | Jarek Kobus <jaroslaw.kobus@qt.io> | 2022-10-07 16:16:35 +0200 |
---|---|---|
committer | Jarek Kobus <jaroslaw.kobus@qt.io> | 2022-10-07 14:52:14 +0000 |
commit | 93dfa93b7dd6d338539927a43b52f5d5e96b03e4 (patch) | |
tree | c777644c21b7dcdc63b9a9a3e2b31ce98a5f2849 /src/plugins/git | |
parent | 8eb4d52342fe3a6ede1c1dce3174d95bfa0cea88 (diff) |
VcsCommand: Simplify ProgressParser
Get rid of abstract base ProgressParser and replace
it with ProgressParser function. The only one former
subclass GitProgressParser is now functor object.
Pass future interface directly to the ProgressParser
function, along with input text to be parsed.
Change-Id: Icbcf0b6e55097f8b38eb8a32ceaa4414723116d0
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Diffstat (limited to 'src/plugins/git')
-rw-r--r-- | src/plugins/git/gitclient.cpp | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp index 002d603a43..fdc1c9a625 100644 --- a/src/plugins/git/gitclient.cpp +++ b/src/plugins/git/gitclient.cpp @@ -791,26 +791,19 @@ private: QStringList m_files; }; -class GitProgressParser : public ProgressParser +class GitProgressParser { public: - static void attachToCommand(VcsCommand *command) - { - command->setProgressParser(new GitProgressParser); + void operator()(QFutureInterface<void> &fi, const QString &inputText) const { + const QRegularExpressionMatch match = m_progressExp.match(inputText); + if (match.hasMatch()) { + fi.setProgressRange(0, match.captured(2).toInt()); + fi.setProgressValue(match.captured(1).toInt()); + } } private: - GitProgressParser() : m_progressExp("\\((\\d+)/(\\d+)\\)") // e.g. Rebasing (7/42) - { } - - void parseProgress(const QString &text) override - { - const QRegularExpressionMatch match = m_progressExp.match(text); - if (match.hasMatch()) - setProgressAndMaximum(match.captured(1).toInt(), match.captured(2).toInt()); - } - - const QRegularExpression m_progressExp; + const QRegularExpression m_progressExp{"\\((\\d+)/(\\d+)\\)"}; // e.g. Rebasing (7/42) }; static inline QString msgRepositoryNotFound(const FilePath &dir) @@ -3404,7 +3397,7 @@ VcsCommand *GitClient::vcsExecAbortable(const FilePath &workingDirectory, command->addJob({vcsBinary(), arguments}, isRebase ? 0 : vcsTimeoutS()); ConflictHandler::attachToCommand(command, workingDirectory, abortCommand); if (isRebase) - GitProgressParser::attachToCommand(command); + command->setProgressParser(GitProgressParser()); command->start(); return command; |