forked from qt-creator/qt-creator
VCS[git]: Add 'Revert this chunk' context menu option to diff view.
Implement in git. Add infrastructure to revert single chhunks by using patch -R. Currently only implemented in git since only that has functionality to re-run diff. Rubber-stamped-by: hunger <tobias.hunger@nokia.com>
This commit is contained in:
@@ -49,6 +49,7 @@
|
||||
#include <projectexplorer/project.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/synchronousprocess.h>
|
||||
#include <utils/environment.h>
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtCore/QDir>
|
||||
@@ -883,6 +884,54 @@ Utils::SynchronousProcessResponse
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
bool VCSBasePlugin::runPatch(const QByteArray &input, const QString &workingDirectory,
|
||||
int strip, bool reverse)
|
||||
{
|
||||
VCSBaseOutputWindow *ow = VCSBaseOutputWindow::instance();
|
||||
const QString patch = Internal::VCSPlugin::instance()->settings().patchCommand;
|
||||
if (patch.isEmpty()) {
|
||||
ow->appendError(tr("There is no patch-command configured in the commone 'Version Control' settings."));
|
||||
return false;
|
||||
}
|
||||
|
||||
QProcess patchProcess;
|
||||
if (!workingDirectory.isEmpty())
|
||||
patchProcess.setWorkingDirectory(workingDirectory);
|
||||
QStringList args(QLatin1String("-p") + QString::number(strip));
|
||||
if (reverse)
|
||||
args << QLatin1String("-R");
|
||||
ow->appendCommand(QString(), patch, args);
|
||||
patchProcess.start(patch, args);
|
||||
if (!patchProcess.waitForStarted()) {
|
||||
ow->appendError(tr("Unable to launch '%1': %2").arg(patch, patchProcess.errorString()));
|
||||
return false;
|
||||
}
|
||||
patchProcess.write(input);
|
||||
patchProcess.closeWriteChannel();
|
||||
QByteArray stdOut;
|
||||
QByteArray stdErr;
|
||||
if (!Utils::SynchronousProcess::readDataFromProcess(patchProcess, 30000, &stdOut, &stdErr, true)) {
|
||||
Utils::SynchronousProcess::stopProcess(patchProcess);
|
||||
ow->appendError(tr("A timeout occurred running '%1'").arg(patch));
|
||||
return false;
|
||||
|
||||
}
|
||||
if (!stdOut.isEmpty())
|
||||
ow->append(QString::fromLocal8Bit(stdOut));
|
||||
if (!stdErr.isEmpty())
|
||||
ow->append(QString::fromLocal8Bit(stdErr));
|
||||
|
||||
if (patchProcess.exitStatus() != QProcess::NormalExit) {
|
||||
ow->appendError(tr("'%1' crashed.").arg(patch));
|
||||
return false;
|
||||
}
|
||||
if (patchProcess.exitCode() != 0) {
|
||||
ow->appendError(tr("'%1' failed (exit code %2).").arg(patchProcess.exitCode()));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace VCSBase
|
||||
|
||||
#include "vcsbaseplugin.moc"
|
||||
|
||||
Reference in New Issue
Block a user