aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/vcsbase/vcsbaseplugin.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <[email protected]>2011-03-24 15:44:39 +0100
committerFriedemann Kleint <[email protected]>2011-03-24 15:46:09 +0100
commit491a27163a9a843356a686ea405723608b10aa11 (patch)
treef0803cb3ef8483091ec960b037cbfbbcfc50f587 /src/plugins/vcsbase/vcsbaseplugin.cpp
parentfbe9925d8cc424a82987ac4ab98a66fbe320b09c (diff)
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 <[email protected]>
Diffstat (limited to 'src/plugins/vcsbase/vcsbaseplugin.cpp')
-rw-r--r--src/plugins/vcsbase/vcsbaseplugin.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/plugins/vcsbase/vcsbaseplugin.cpp b/src/plugins/vcsbase/vcsbaseplugin.cpp
index 359e02b8684..24f28b86510 100644
--- a/src/plugins/vcsbase/vcsbaseplugin.cpp
+++ b/src/plugins/vcsbase/vcsbaseplugin.cpp
@@ -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"