From 096daac0bd06e4adbfd176976c586bb8fc078531 Mon Sep 17 00:00:00 2001
From: Orgad Shaneh <orgad.shaneh@audiocodes.com>
Date: Fri, 14 Jun 2013 18:35:38 +0300
Subject: [PATCH] Git: Execute rebase asynchronously

Rebase --continue might request an editor, which hangs if run
synchronously

Change-Id: I28127884408f6f8fbd351bb1024dc8d3c2b339b8
Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
---
 src/plugins/git/branchdialog.cpp |  2 +-
 src/plugins/git/gitclient.cpp    | 38 +++++++++++++-------------------
 src/plugins/git/gitclient.h      |  4 +---
 src/plugins/git/gitplugin.cpp    |  4 ++--
 4 files changed, 19 insertions(+), 29 deletions(-)

diff --git a/src/plugins/git/branchdialog.cpp b/src/plugins/git/branchdialog.cpp
index 001664f2f20..848fb293e9c 100644
--- a/src/plugins/git/branchdialog.cpp
+++ b/src/plugins/git/branchdialog.cpp
@@ -303,7 +303,7 @@ void BranchDialog::rebase()
     const QString baseBranch = m_model->branchName(idx);
     GitClient *client = GitPlugin::instance()->gitClient();
     if (client->beginStashScope(m_repository, QLatin1String("rebase")))
-        client->synchronousRebase(m_repository, baseBranch);
+        client->rebase(m_repository, baseBranch);
 }
 
 QModelIndex BranchDialog::selectedIndex()
diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp
index f1d85b753e0..79db65edc82 100644
--- a/src/plugins/git/gitclient.cpp
+++ b/src/plugins/git/gitclient.cpp
@@ -2350,21 +2350,10 @@ void GitClient::continuePreviousGitCommand(const QString &workingDirectory,
         synchronousAbortCommand(workingDirectory, gitCommand);
         break;
     default: // Continue/Skip
-        if (isRebase) {
-            // Git might request an editor, so this must be done asynchronously
-            // and without timeout
-            QStringList arguments;
-            arguments << gitCommand << QLatin1String(hasChanges ? "--continue" : "--skip");
-            outputWindow()->appendCommand(workingDirectory,
-                                          settings()->stringValue(GitSettings::binaryPathKey),
-                                          arguments);
-            VcsBase::Command *command = createCommand(workingDirectory, 0, true);
-            new ConflictHandler(command, workingDirectory, gitCommand);
-            command->addJob(arguments, -1);
-            command->execute();
-        } else {
+        if (isRebase)
+            rebase(workingDirectory, QLatin1String(hasChanges ? "--continue" : "--skip"));
+        else
             GitPlugin::instance()->startCommit();
-        }
     }
 }
 
@@ -2997,17 +2986,20 @@ bool GitClient::canRebase(const QString &workingDirectory) const
     return true;
 }
 
-bool GitClient::synchronousRebase(const QString &workingDirectory, const QString &baseBranch,
-                                  const QString &topicBranch)
+void GitClient::rebase(const QString &workingDirectory, const QString &baseBranch)
 {
-    QString command = QLatin1String("rebase");
+    // Git might request an editor, so this must be done asynchronously
+    // and without timeout
+    QString gitCommand = QLatin1String("rebase");
     QStringList arguments;
-
-    arguments << command << baseBranch;
-    if (!topicBranch.isEmpty())
-        arguments << topicBranch;
-
-    return executeAndHandleConflicts(workingDirectory, arguments, command);
+    arguments << gitCommand << baseBranch;
+    outputWindow()->appendCommand(workingDirectory,
+                                  settings()->stringValue(GitSettings::binaryPathKey),
+                                  arguments);
+    VcsBase::Command *command = createCommand(workingDirectory, 0, true);
+    new ConflictHandler(command, workingDirectory, gitCommand);
+    command->addJob(arguments, -1);
+    command->execute();
 }
 
 bool GitClient::synchronousRevert(const QString &workingDirectory, const QString &commit)
diff --git a/src/plugins/git/gitclient.h b/src/plugins/git/gitclient.h
index e6feb43866f..cf0ead6c0de 100644
--- a/src/plugins/git/gitclient.h
+++ b/src/plugins/git/gitclient.h
@@ -240,9 +240,7 @@ public:
     void push(const QString &workingDirectory, const QStringList &pushArgs = QStringList());
     bool synchronousMerge(const QString &workingDirectory, const QString &branch);
     bool canRebase(const QString &workingDirectory) const;
-    bool synchronousRebase(const QString &workingDirectory,
-                           const QString &baseBranch,
-                           const QString &topicBranch = QString());
+    void rebase(const QString &workingDirectory, const QString &baseBranch);
     bool synchronousRevert(const QString &workingDirectory, const QString &commit);
     bool synchronousCherryPick(const QString &workingDirectory, const QString &commit);
     void interactiveRebase(const QString &workingDirectory, const QString &commit, bool fixup);
diff --git a/src/plugins/git/gitplugin.cpp b/src/plugins/git/gitplugin.cpp
index 6f051f9af3a..65a0f91f2b0 100644
--- a/src/plugins/git/gitplugin.cpp
+++ b/src/plugins/git/gitplugin.cpp
@@ -1149,13 +1149,13 @@ void GitPlugin::continueOrAbortCommand()
     if (action == m_abortMergeAction)
         m_gitClient->synchronousMerge(state.topLevel(), QLatin1String("--abort"));
     else if (action == m_abortRebaseAction)
-        m_gitClient->synchronousRebase(state.topLevel(), QLatin1String("--abort"));
+        m_gitClient->rebase(state.topLevel(), QLatin1String("--abort"));
     else if (action == m_abortCherryPickAction)
         m_gitClient->synchronousCherryPick(state.topLevel(), QLatin1String("--abort"));
     else if (action == m_abortRevertAction)
         m_gitClient->synchronousRevert(state.topLevel(), QLatin1String("--abort"));
     else if (action == m_continueRebaseAction)
-        m_gitClient->synchronousRebase(state.topLevel(), QLatin1String("--continue"));
+        m_gitClient->rebase(state.topLevel(), QLatin1String("--continue"));
     else if (action == m_continueCherryPickAction)
         m_gitClient->synchronousCherryPick(state.topLevel(), QLatin1String("--continue"));
     else if (action == m_continueRevertAction)
-- 
GitLab