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

login
register
mail settings
Submitter Kostia Balytskyi
Date July 1, 2016, 12:29 p.m.
Message ID <AM3PR06MB14764D279113B9C86617BBDD3250@AM3PR06MB147.eurprd06.prod.outlook.com>
Download mbox | patch
Permalink /patch/15702/
State Accepted
Delegated to: Yuya Nishihara
Headers show

Comments

Kostia Balytskyi - July 1, 2016, 12:29 p.m.
# HG changeset patch
# User Kostia Balytskyi <ikostia@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.
Yuya Nishihara - July 3, 2016, 9:17 a.m.
On Fri, 1 Jul 2016 12:29:47 +0000, Kostiantyn Balytskyi wrote:
> # HG changeset patch
> # User Kostia Balytskyi <ikostia@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

The series looks good to me. Queued them, thanks.

I found a few nits, so please send follow-up patches if you think they are
reasonable. It wouldn't be worth rewriting the whole series just because the
nits I found.

> +    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)

We'd better refactor this function to abort() and continue(). Only thing abort()
would need is self.restorestatus().

Patch

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)