[PATCH 1 of 8 v8] rebase: move abort/continue prep to be a method of the RR class

Kostiantyn Balytskyi ikostia at fb.com
Fri Jul 1 08:29:47 EDT 2016


# HG changeset patch
# User Kostia Balytskyi <ikostia at fb.com>
# Date 1467374993 -7200
#      Fri Jul 01 14:09:53 2016 +0200
# Node ID 16792bbea1d2886c5f98178b22be8edc5d4efc31
# Parent  5b71a8d7f7ffc2662ceb58ad8eec806e147ae13d
rebase: move abort/continue prep to be a method of the RR class

This commit moves logic that prepares the execution of abort and
continue phases or rebase operation to be a method of the rebaseruntime
class.

diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -227,6 +227,37 @@ class rebaseruntime(object):
         self.external = external
         self.activebookmark = activebookmark
 
+    def _prepareabortorcontinue(self, isabort):
+        try:
+            self.restorestatus()
+            self.collapsemsg = restorecollapsemsg(self.repo)
+        except error.RepoLookupError:
+            if isabort:
+                clearstatus(self.repo)
+                clearcollapsemsg(self.repo)
+                self.repo.ui.warn(_('rebase aborted (no revision is removed,'
+                                    ' only broken state is cleared)\n'))
+                return 0
+            else:
+                msg = _('cannot continue inconsistent rebase')
+                hint = _('use "hg rebase --abort" to clear broken state')
+                raise error.Abort(msg, hint=hint)
+        if isabort:
+            return abort(self.repo, self.originalwd, self.target,
+                         self.state, activebookmark=self.activebookmark)
+
+        self.obsoletenotrebased = {}
+        if self.ui.configbool('experimental', 'rebaseskipobsolete',
+                              default=True):
+            rebaseobsrevs = set([r for r, st in self.state.items()
+                                    if st == revprecursor])
+            rebasesetrevs = set(self.state.keys())
+            self.obsoletenotrebased = _computeobsoletenotrebased(self.repo,
+                                            rebaseobsrevs, self.target)
+            rebaseobsskipped = set(self.obsoletenotrebased)
+            _checkobsrebase(self.repo, self.ui, rebaseobsrevs, rebasesetrevs,
+                            rebaseobsskipped)
+
 @command('rebase',
     [('s', 'source', '',
      _('rebase the specified changeset and descendants'), _('REV')),
@@ -381,36 +412,9 @@ def rebase(ui, repo, **opts):
             if abortf and opts.get('tool', False):
                 ui.warn(_('tool option will be ignored\n'))
 
-            try:
-                rbsrt.restorestatus()
-                rbsrt.collapsemsg = restorecollapsemsg(repo)
-            except error.RepoLookupError:
-                if abortf:
-                    clearstatus(repo)
-                    clearcollapsemsg(repo)
-                    repo.ui.warn(_('rebase aborted (no revision is removed,'
-                                   ' only broken state is cleared)\n'))
-                    return 0
-                else:
-                    msg = _('cannot continue inconsistent rebase')
-                    hint = _('use "hg rebase --abort" to clear broken state')
-                    raise error.Abort(msg, hint=hint)
-            if abortf:
-                return abort(repo, rbsrt.originalwd, rbsrt.target,
-                             rbsrt.state,
-                             activebookmark=rbsrt.activebookmark)
-
-            rbsrt.obsoletenotrebased = {}
-            if ui.configbool('experimental', 'rebaseskipobsolete',
-                             default=True):
-                rebaseobsrevs = set([r for r, st in rbsrt.state.items()
-                                     if st == revprecursor])
-                rebasesetrevs = set(rbsrt.state.keys())
-                rbsrt.obsoletenotrebased = _computeobsoletenotrebased(repo,
-                                                rebaseobsrevs, rbsrt.target)
-                rebaseobsskipped = set(rbsrt.obsoletenotrebased)
-                _checkobsrebase(repo, ui, rebaseobsrevs, rebasesetrevs,
-                                rebaseobsskipped)
+            retcode = rbsrt._prepareabortorcontinue(abortf)
+            if retcode is not None:
+                return retcode
         else:
             dest, rebaseset = _definesets(ui, repo, destf, srcf, basef, revf,
                                           destspace=destspace)


More information about the Mercurial-devel mailing list