forked from qt-creator/qt-creator
Git: Simplify use of conflict handler a bit
Disentangle binding to an existing command from the actual task of the conflict handler. This makes usage more clear. Also rename "command" to "abortCommand" which is also more clear as to what it is used for. Change-Id: I862cfec97fbf512a3121f0a7d58ae12f148879a6 Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -457,20 +457,30 @@ class ConflictHandler : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
ConflictHandler(VcsCommand *parentCommand,
|
static void attachToCommand(VcsCommand *command, const QString &abortCommand = QString()) {
|
||||||
const QString &workingDirectory,
|
ConflictHandler *handler = new ConflictHandler(command->workingDirectory(), abortCommand);
|
||||||
const QString &command = QString())
|
handler->setParent(command); // delete when command goes out of scope
|
||||||
: QObject(parentCommand),
|
|
||||||
m_workingDirectory(workingDirectory),
|
command->addFlags(VcsBasePlugin::ExpectRepoChanges);
|
||||||
m_command(command)
|
connect(command, &VcsCommand::output, handler, &ConflictHandler::readStdOut);
|
||||||
{
|
connect(command, &VcsCommand::errorText, handler, &ConflictHandler::readStdErr);
|
||||||
if (parentCommand) {
|
|
||||||
parentCommand->addFlags(VcsBasePlugin::ExpectRepoChanges);
|
|
||||||
connect(parentCommand, &VcsCommand::output, this, &ConflictHandler::readStdOut);
|
|
||||||
connect(parentCommand, &VcsCommand::errorText, this, &ConflictHandler::readStdErr);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void handleResponse(const Utils::SynchronousProcessResponse &response,
|
||||||
|
const QString &workingDirectory,
|
||||||
|
const QString &abortCommand = QString())
|
||||||
|
{
|
||||||
|
ConflictHandler handler(workingDirectory, abortCommand);
|
||||||
|
handler.readStdOut(response.stdOut);
|
||||||
|
handler.readStdErr(response.stdErr);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
ConflictHandler(const QString &workingDirectory, const QString &abortCommand) :
|
||||||
|
m_workingDirectory(workingDirectory),
|
||||||
|
m_abortCommand(abortCommand)
|
||||||
|
{ }
|
||||||
|
|
||||||
~ConflictHandler()
|
~ConflictHandler()
|
||||||
{
|
{
|
||||||
// If interactive rebase editor window is closed, plugin is terminated
|
// If interactive rebase editor window is closed, plugin is terminated
|
||||||
@@ -481,12 +491,11 @@ public:
|
|||||||
if (client->checkCommandInProgress(m_workingDirectory) == GitClient::NoCommand)
|
if (client->checkCommandInProgress(m_workingDirectory) == GitClient::NoCommand)
|
||||||
client->endStashScope(m_workingDirectory);
|
client->endStashScope(m_workingDirectory);
|
||||||
} else {
|
} else {
|
||||||
client->handleMergeConflicts(m_workingDirectory, m_commit, m_files, m_command);
|
client->handleMergeConflicts(m_workingDirectory, m_commit, m_files, m_abortCommand);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public slots:
|
|
||||||
void readStdOut(const QString &data)
|
void readStdOut(const QString &data)
|
||||||
{
|
{
|
||||||
static QRegExp patchFailedRE(QLatin1String("Patch failed at ([^\\n]*)"));
|
static QRegExp patchFailedRE(QLatin1String("Patch failed at ([^\\n]*)"));
|
||||||
@@ -494,9 +503,8 @@ public slots:
|
|||||||
if (patchFailedRE.indexIn(data) != -1)
|
if (patchFailedRE.indexIn(data) != -1)
|
||||||
m_commit = patchFailedRE.cap(1);
|
m_commit = patchFailedRE.cap(1);
|
||||||
int fileIndex = -1;
|
int fileIndex = -1;
|
||||||
while ((fileIndex = conflictedFilesRE.indexIn(data, fileIndex + 1)) != -1) {
|
while ((fileIndex = conflictedFilesRE.indexIn(data, fileIndex + 1)) != -1)
|
||||||
m_files.append(conflictedFilesRE.cap(1));
|
m_files.append(conflictedFilesRE.cap(1));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void readStdErr(const QString &data)
|
void readStdErr(const QString &data)
|
||||||
@@ -507,7 +515,7 @@ public slots:
|
|||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
QString m_workingDirectory;
|
QString m_workingDirectory;
|
||||||
QString m_command;
|
QString m_abortCommand;
|
||||||
QString m_commit;
|
QString m_commit;
|
||||||
QStringList m_files;
|
QStringList m_files;
|
||||||
};
|
};
|
||||||
@@ -2769,13 +2777,10 @@ bool GitClient::executeAndHandleConflicts(const QString &workingDirectory,
|
|||||||
| VcsBasePlugin::ExpectRepoChanges
|
| VcsBasePlugin::ExpectRepoChanges
|
||||||
| VcsBasePlugin::ShowSuccessMessage;
|
| VcsBasePlugin::ShowSuccessMessage;
|
||||||
const SynchronousProcessResponse resp = vcsSynchronousExec(workingDirectory, arguments, flags);
|
const SynchronousProcessResponse resp = vcsSynchronousExec(workingDirectory, arguments, flags);
|
||||||
ConflictHandler conflictHandler(0, workingDirectory, abortCommand);
|
|
||||||
// Notify about changed files or abort the rebase.
|
// Notify about changed files or abort the rebase.
|
||||||
const bool ok = resp.result == SynchronousProcessResponse::Finished;
|
const bool ok = resp.result == SynchronousProcessResponse::Finished;
|
||||||
if (!ok) {
|
if (!ok)
|
||||||
conflictHandler.readStdOut(resp.stdOut);
|
ConflictHandler::handleResponse(resp, workingDirectory, abortCommand);
|
||||||
conflictHandler.readStdErr(resp.stdErr);
|
|
||||||
}
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2974,7 +2979,7 @@ void GitClient::asyncCommand(const QString &workingDirectory, const QStringList
|
|||||||
QString gitCommand = arguments.first();
|
QString gitCommand = arguments.first();
|
||||||
VcsOutputWindow::appendCommand(workingDirectory, vcsBinary(), arguments);
|
VcsOutputWindow::appendCommand(workingDirectory, vcsBinary(), arguments);
|
||||||
VcsCommand *command = createCommand(workingDirectory, 0, VcsWindowOutputBind);
|
VcsCommand *command = createCommand(workingDirectory, 0, VcsWindowOutputBind);
|
||||||
new ConflictHandler(command, workingDirectory, gitCommand);
|
ConflictHandler::attachToCommand(command, gitCommand);
|
||||||
if (hasProgress)
|
if (hasProgress)
|
||||||
command->setProgressParser(new GitProgressParser);
|
command->setProgressParser(new GitProgressParser);
|
||||||
command->setCookie(workingDirectory);
|
command->setCookie(workingDirectory);
|
||||||
@@ -3043,7 +3048,7 @@ void GitClient::stashPop(const QString &workingDirectory, const QString &stash)
|
|||||||
arguments << stash;
|
arguments << stash;
|
||||||
VcsCommand *cmd = executeGit(workingDirectory, arguments, 0, true,
|
VcsCommand *cmd = executeGit(workingDirectory, arguments, 0, true,
|
||||||
VcsBasePlugin::ExpectRepoChanges);
|
VcsBasePlugin::ExpectRepoChanges);
|
||||||
new ConflictHandler(cmd, workingDirectory);
|
ConflictHandler::attachToCommand(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GitClient::synchronousStashRestore(const QString &workingDirectory,
|
bool GitClient::synchronousStashRestore(const QString &workingDirectory,
|
||||||
|
Reference in New Issue
Block a user