changeset 3312:8e9ea8307cdd

stablerange: use the filterparents utility
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 18 Dec 2017 07:20:14 +0100
parents df399e00c10b
children efceae0bfa35
files hgext3rd/evolve/stablerange.py
diffstat 1 files changed, 17 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/stablerange.py	Mon Dec 18 07:10:43 2017 +0100
+++ b/hgext3rd/evolve/stablerange.py	Mon Dec 18 07:20:14 2017 +0100
@@ -26,8 +26,11 @@
 from . import (
     stablesort,
     exthelper,
+    utility,
 )
 
+filterparents = utility.filterparents
+
 eh = exthelper.exthelper()
 eh.merge(stablesort.eh)
 
@@ -365,14 +368,14 @@
         We are looking for that `min(parents(REV))`. Since the subrange are
         based on the sort, we can reuse its subrange as well.
         """
-        p1, p2 = repo.changelog.parentrevs(headrev)
-        relevant_parent = None
-        if p2 == nodemod.nullrev:
-            relevant_parent = p1
+        ps = filterparents(repo.changelog.parentrevs(headrev))
+        if not ps:
+            return nodemod.nullrev
+        elif len(ps) == 1:
+            return ps[0]
         else:
             tiebreaker = stablesort._mergepoint_tie_breaker(repo)
-            relevant_parent = min(p1, p2, key=tiebreaker)
-        return relevant_parent
+            return min(ps, key=tiebreaker)
 
     def _parentrange(self, repo, rangeid):
         stable_parent = self._stableparent(repo, rangeid[0])
@@ -706,10 +709,12 @@
 
         This function also have the important task to update the revscache of
         the parent rev s if possible and needed"""
-        p1, p2 = self._parents(rangeid[0], repo.changelog.parentrevs)
-        if p2 == nodemod.nullrev:
+        ps = filterparents(self._parents(rangeid[0], repo.changelog.parentrevs))
+        if not ps:
+            return None
+        elif len(ps) == 1:
             # regular changesets, we pick the parent
-            reusablerev = p1
+            reusablerev = ps[0]
         else:
             # merge, we try the inheritance point
             # if it is too low, it will be ditched by the depth check anyway
@@ -729,9 +734,9 @@
         return reurange
 
     def _slicesrangeat(self, repo, rangeid, globalindex):
-        p1, p2 = self._parents(rangeid[0], repo.changelog.parentrevs)
-        if p2 == nodemod.nullrev:
-            reuserev = p1
+        ps = self._parents(rangeid[0], repo.changelog.parentrevs)
+        if len(ps) == 1:
+            reuserev = ps[0]
         else:
             index, reuserev = self._inheritancepoint(repo, rangeid[0])
             if index < globalindex: