Patchwork [1,of,2,v2] rebase: refactor and rename checkexternal - it is a getter more than a setter

login
register
mail settings
Submitter Mads Kiilerich
Date Oct. 24, 2013, 4:12 a.m.
Message ID <6e6a1ee0ab34df6dae57.1382587948@localhost.localdomain>
Download mbox | patch
Permalink /patch/2812/
State Accepted
Commit 2160c2e0d7d1984fdbd1b89c2d6c2e2ff666598b
Headers show

Comments

Mads Kiilerich - Oct. 24, 2013, 4:12 a.m.
# HG changeset patch
# User Mads Kiilerich <madski@unity3d.com>
# Date 1382587522 -28800
#      Thu Oct 24 12:05:22 2013 +0800
# Branch stable
# Node ID 6e6a1ee0ab34df6dae577832dc229054d42c58ed
# Parent  d51c4d85ec23a67292f07b3121a9353452364f6d
rebase: refactor and rename checkexternal - it is a getter more than a setter

Patch

diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -259,7 +259,7 @@  def rebase(ui, repo, **opts):
                 if collapsef:
                     targetancestors = repo.changelog.ancestors([target],
                                                                inclusive=True)
-                    external = checkexternal(repo, state, targetancestors)
+                    external = externalparent(repo, state, targetancestors)
 
         if keepbranchesf:
             # insert _savebranch at the start of extrafns so if
@@ -388,24 +388,26 @@  def rebase(ui, repo, **opts):
     finally:
         release(lock, wlock)
 
-def checkexternal(repo, state, targetancestors):
-    """Check whether one or more external revisions need to be taken in
-    consideration. In the latter case, abort.
+def externalparent(repo, state, targetancestors):
+    """Return the revision that should be used as the second parent
+    when the revisions in state is collapsed on top of targetancestors.
+    Abort if there is more than one parent.
     """
-    external = nullrev
+    parents = set()
     source = min(state)
     for rev in state:
         if rev == source:
             continue
-        # Check externals and fail if there are more than one
         for p in repo[rev].parents():
             if (p.rev() not in state
                         and p.rev() not in targetancestors):
-                if external != nullrev:
-                    raise util.Abort(_('unable to collapse, there is more '
-                            'than one external parent'))
-                external = p.rev()
-    return external
+                parents.add(p.rev())
+    if not parents:
+        return nullrev
+    if len(parents) == 1:
+        return parents.pop()
+    raise util.Abort(_('unable to collapse, there is more '
+                       'than one external parent'))
 
 def concludenode(repo, rev, p1, p2, commitmsg=None, editor=None, extrafn=None):
     'Commit the changes and store useful information in extra'