forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user