forked from qt-creator/qt-creator
Git: Reuse handleResponse() inside vcsExecAbortable()
Remove ConflictHandler::attachToCommand(). Rename handleResponse() into handleConflictResponse() and move it out of ConflictHandler class. Change-Id: I0a64bd19f288d9377a93cdb5eea2c44b65bf6fdb Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -721,38 +721,18 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class ConflictHandler
|
static void handleConflictResponse(const VcsBase::CommandResult &result,
|
||||||
{
|
|
||||||
public:
|
|
||||||
static void attachToCommand(VcsCommand *command, const FilePath &workingDirectory,
|
|
||||||
const QString &abortCommand = {}) {
|
|
||||||
command->addFlags(RunFlags::ExpectRepoChanges);
|
|
||||||
QObject::connect(command, &VcsCommand::done, command, [=] {
|
|
||||||
finalize(workingDirectory, abortCommand,
|
|
||||||
command->cleanedStdOut(), command->cleanedStdErr());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
static void handleResponse(const VcsBase::CommandResult &result,
|
|
||||||
const FilePath &workingDirectory,
|
const FilePath &workingDirectory,
|
||||||
const QString &abortCommand = {})
|
const QString &abortCommand = {})
|
||||||
{
|
{
|
||||||
const bool success = result.result() == ProcessResult::FinishedWithSuccess;
|
const bool success = result.result() == ProcessResult::FinishedWithSuccess;
|
||||||
const QString stdOutData = success ? QString() : result.cleanedStdOut();
|
const QString stdOutData = success ? QString() : result.cleanedStdOut();
|
||||||
const QString stdErrData = success ? QString() : result.cleanedStdErr();
|
const QString stdErrData = success ? QString() : result.cleanedStdErr();
|
||||||
finalize(workingDirectory, abortCommand, stdOutData, stdErrData);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
static void finalize(const FilePath &workingDirectory, const QString &abortCommand,
|
|
||||||
const QString &stdOutData, const QString &stdErrData)
|
|
||||||
{
|
|
||||||
QString commit;
|
|
||||||
QStringList files;
|
|
||||||
|
|
||||||
static const QRegularExpression patchFailedRE("Patch failed at ([^\\n]*)");
|
static const QRegularExpression patchFailedRE("Patch failed at ([^\\n]*)");
|
||||||
static const QRegularExpression conflictedFilesRE("Merge conflict in ([^\\n]*)");
|
static const QRegularExpression conflictedFilesRE("Merge conflict in ([^\\n]*)");
|
||||||
static const QRegularExpression couldNotApplyRE("[Cc]ould not (?:apply|revert) ([^\\n]*)");
|
static const QRegularExpression couldNotApplyRE("[Cc]ould not (?:apply|revert) ([^\\n]*)");
|
||||||
|
QString commit;
|
||||||
|
QStringList files;
|
||||||
|
|
||||||
const QRegularExpressionMatch outMatch = patchFailedRE.match(stdOutData);
|
const QRegularExpressionMatch outMatch = patchFailedRE.match(stdOutData);
|
||||||
if (outMatch.hasMatch())
|
if (outMatch.hasMatch())
|
||||||
@@ -772,8 +752,7 @@ private:
|
|||||||
} else {
|
} else {
|
||||||
m_instance->handleMergeConflicts(workingDirectory, commit, files, abortCommand);
|
m_instance->handleMergeConflicts(workingDirectory, commit, files, abortCommand);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
class GitProgressParser
|
class GitProgressParser
|
||||||
{
|
{
|
||||||
@@ -3095,7 +3074,7 @@ bool GitClient::executeAndHandleConflicts(const FilePath &workingDirectory,
|
|||||||
| RunFlags::ShowSuccessMessage;
|
| RunFlags::ShowSuccessMessage;
|
||||||
const CommandResult result = vcsSynchronousExec(workingDirectory, arguments, flags);
|
const CommandResult result = vcsSynchronousExec(workingDirectory, arguments, flags);
|
||||||
// Notify about changed files or abort the rebase.
|
// Notify about changed files or abort the rebase.
|
||||||
ConflictHandler::handleResponse(result, workingDirectory, abortCommand);
|
handleConflictResponse(result, workingDirectory, abortCommand);
|
||||||
return result.result() == ProcessResult::FinishedWithSuccess;
|
return result.result() == ProcessResult::FinishedWithSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3374,13 +3353,13 @@ void GitClient::vcsExecAbortable(const FilePath &workingDirectory, const QString
|
|||||||
// For rebase, Git might request an editor (which means the process keeps running until the
|
// For rebase, Git might request an editor (which means the process keeps running until the
|
||||||
// user closes it), so run without timeout.
|
// user closes it), so run without timeout.
|
||||||
command->addJob({vcsBinary(), arguments}, isRebase ? 0 : vcsTimeoutS());
|
command->addJob({vcsBinary(), arguments}, isRebase ? 0 : vcsTimeoutS());
|
||||||
ConflictHandler::attachToCommand(command, workingDirectory, abortString);
|
|
||||||
if (handler) {
|
|
||||||
const QObject *actualContext = context ? context : this;
|
const QObject *actualContext = context ? context : this;
|
||||||
connect(command, &VcsCommand::done, actualContext, [command, handler] {
|
connect(command, &VcsCommand::done, actualContext, [=] {
|
||||||
handler(CommandResult(*command));
|
const CommandResult result = CommandResult(*command);
|
||||||
|
handleConflictResponse(result, workingDirectory, abortString);
|
||||||
|
if (handler)
|
||||||
|
handler(result);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
if (isRebase)
|
if (isRebase)
|
||||||
command->setProgressParser(GitProgressParser());
|
command->setProgressParser(GitProgressParser());
|
||||||
command->start();
|
command->start();
|
||||||
@@ -3440,7 +3419,7 @@ void GitClient::stashPop(const FilePath &workingDirectory, const QString &stash)
|
|||||||
if (!stash.isEmpty())
|
if (!stash.isEmpty())
|
||||||
arguments << stash;
|
arguments << stash;
|
||||||
const auto commandHandler = [workingDirectory](const CommandResult &result) {
|
const auto commandHandler = [workingDirectory](const CommandResult &result) {
|
||||||
ConflictHandler::handleResponse(result, workingDirectory);
|
handleConflictResponse(result, workingDirectory);
|
||||||
};
|
};
|
||||||
vcsExecWithHandler(workingDirectory, arguments, this, commandHandler,
|
vcsExecWithHandler(workingDirectory, arguments, this, commandHandler,
|
||||||
RunFlags::ShowStdOut | RunFlags::ExpectRepoChanges);
|
RunFlags::ShowStdOut | RunFlags::ExpectRepoChanges);
|
||||||
|
|||||||
Reference in New Issue
Block a user