Patchwork D2914: rebase: extract common _concludenode()

login
register
mail settings
Submitter phabricator
Date March 21, 2018, 6:11 p.m.
Message ID <differential-rev-PHID-DREV-okelpb4kaphz6ytf7en4-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/29701/
State Superseded
Headers show

Comments

phabricator - March 21, 2018, 6:11 p.m.
martinvonz created this revision.
martinvonz added a reviewer: phillco.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  _rebasenode() and _finishrebase() had a lot of code in common. This
  commit extracts some of that. This means we will also have a single
  caller of concludenode() and concludememorynode(), which gives us a
  place to put code that is common between those two functions (which is
  quite a bit).

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2914

AFFECTED FILES
  hgext/rebase.py

CHANGE DETAILS




To: martinvonz, phillco, #hg-reviewers
Cc: mercurial-devel
phabricator - March 21, 2018, 11:32 p.m.
indygreg accepted this revision.
indygreg added a comment.
This revision is now accepted and ready to land.


  Nice.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2914

To: martinvonz, phillco, #hg-reviewers, indygreg
Cc: indygreg, mercurial-devel

Patch

diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -448,6 +448,36 @@ 
         ui.progress(_('rebasing'), None)
         ui.note(_('rebase merging completed\n'))
 
+    def _concludenode(self, rev, p1, p2, editor, commitmsg=None):
+        '''Commit the wd changes with parents p1 and p2.
+
+        Reuse commit info from rev but also store useful information in extra.
+        Return node of committed revision.'''
+        repo = self.repo
+        if self.inmemory:
+            newnode = concludememorynode(repo, rev, p1, p2,
+                wctx=self.wctx,
+                extrafn=_makeextrafn(self.extrafns),
+                commitmsg=commitmsg,
+                editor=editor,
+                keepbranches=self.keepbranchesf,
+                date=self.date)
+            mergemod.mergestate.clean(repo)
+        else:
+            newnode = concludenode(repo, rev, p1, p2,
+                extrafn=_makeextrafn(self.extrafns),
+                commitmsg=commitmsg,
+                editor=editor,
+                keepbranches=self.keepbranchesf,
+                date=self.date)
+
+        if newnode is None:
+            # If it ended up being a no-op commit, then the normal
+            # merge state clean-up path doesn't happen, so do it
+            # here. Fix issue5494
+            mergemod.mergestate.clean(repo)
+        return newnode
+
     def _rebasenode(self, tr, rev, allowdivergence, progressfn):
         repo, ui, opts = self.repo, self.ui, self.opts
         dest = self.destmap[rev]
@@ -503,26 +533,7 @@ 
                 editform = cmdutil.mergeeditform(merging, 'rebase')
                 editor = cmdutil.getcommiteditor(editform=editform,
                                                  **pycompat.strkwargs(opts))
-                if self.inmemory:
-                    newnode = concludememorynode(repo, rev, p1, p2,
-                        wctx=self.wctx,
-                        extrafn=_makeextrafn(self.extrafns),
-                        editor=editor,
-                        keepbranches=self.keepbranchesf,
-                        date=self.date)
-                    mergemod.mergestate.clean(repo)
-                else:
-                    newnode = concludenode(repo, rev, p1, p2,
-                        extrafn=_makeextrafn(self.extrafns),
-                        editor=editor,
-                        keepbranches=self.keepbranchesf,
-                        date=self.date)
-
-                if newnode is None:
-                    # If it ended up being a no-op commit, then the normal
-                    # merge state clean-up path doesn't happen, so do it
-                    # here. Fix issue5494
-                    mergemod.mergestate.clean(repo)
+                newnode = self._concludenode(rev, p1, p2, editor)
             else:
                 # Skip commit if we are collapsing
                 if self.inmemory:
@@ -572,27 +583,9 @@ 
             editor = cmdutil.getcommiteditor(edit=editopt, editform=editform)
             revtoreuse = max(self.state)
 
-            if self.inmemory:
-                newnode = concludememorynode(repo, revtoreuse, p1,
-                    self.external,
-                    commitmsg=commitmsg,
-                    extrafn=_makeextrafn(self.extrafns),
-                    editor=editor,
-                    keepbranches=self.keepbranchesf,
-                    date=self.date, wctx=self.wctx)
-            else:
-                newnode = concludenode(repo, revtoreuse, p1, self.external,
-                    commitmsg=commitmsg,
-                    extrafn=_makeextrafn(self.extrafns),
-                    editor=editor,
-                    keepbranches=self.keepbranchesf,
-                    date=self.date)
+            newnode = self._concludenode(revtoreuse, p1, self.external,
+                                         editor, commitmsg=commitmsg)
 
-            if newnode is None:
-                # If it ended up being a no-op commit, then the normal
-                # merge state clean-up path doesn't happen, so do it
-                # here. Fix issue5494
-                mergemod.mergestate.clean(repo)
             if newnode is not None:
                 newrev = repo[newnode].rev()
                 for oldrev in self.state: