refactor: extract obs fate algorithm from _getobsoletereason
authorBoris Feld <boris.feld@octobus.net>
Fri, 26 May 2017 13:18:26 +0200
changeset 2488 1bdbe8f55339
parent 2487 590da9c523ae
child 2489 84a8219a2f9a
refactor: extract obs fate algorithm from _getobsoletereason Refactor _getobsoletereason to extract the obs fate computation into a separate function, it will be used later and put it in obshistory as it will be needed in other files. Rename _getobsoletereason to _getobsoletefateandsuccessors.
hgext3rd/evolve/__init__.py
hgext3rd/evolve/obshistory.py
--- a/hgext3rd/evolve/__init__.py	Fri May 26 10:05:37 2017 +0200
+++ b/hgext3rd/evolve/__init__.py	Fri May 26 13:18:26 2017 +0200
@@ -523,29 +523,6 @@
 
 # This section take care of issue warning to the user when troubles appear
 
-
-def _getobsoletereason(repo, revnode):
-    """ Return a tuple containing:
-    - the reason a revision is obsolete (diverged, pruned or superseed)
-    - the list of successors short node if the revision is neither pruned
-    or has diverged
-    """
-    successorssets = obsolete.successorssets(repo, revnode)
-
-    if len(successorssets) == 0:
-        # The commit has been pruned
-        return ('pruned', [])
-    elif len(successorssets) > 1:
-        return ('diverged', [])
-    else:
-        # No divergence, only one set of successors
-        successors = [node.short(node_id) for node_id in successorssets[0]]
-
-        if len(successors) == 1:
-            return ('superseed', successors)
-        else:
-            return ('superseed_split', successors)
-
 def _warnobsoletewc(ui, repo):
     rev = repo['.']
 
@@ -562,7 +539,7 @@
         return
 
     # Show a warning for helping the user to solve the issue
-    reason, successors = _getobsoletereason(repo, rev.node())
+    reason, successors = obshistory._getobsfateandsuccs(repo, rev.node())
 
     if reason == 'pruned':
         solvemsg = _("use 'hg evolve' to update to its parent successor")
@@ -600,7 +577,7 @@
 
             unfilteredrepo = repo.unfiltered()
             rev = unfilteredrepo[changeid]
-            reason, successors = _getobsoletereason(unfilteredrepo, rev.node())
+            reason, successors = obshistory._getobsfateandsuccs(unfilteredrepo, rev.node())
 
             # Be more precise in cqse the revision is superseed
             if reason == 'superseed':
--- a/hgext3rd/evolve/obshistory.py	Fri May 26 10:05:37 2017 +0200
+++ b/hgext3rd/evolve/obshistory.py	Fri May 26 13:18:26 2017 +0200
@@ -490,3 +490,45 @@
         tr.close()
     finally:
         tr.release()
+
+def _getobsfate(successorssets):
+    """ Compute a changeset obsolescence fate based on his successorssets.
+    Successors can be the tipmost ones or the immediate ones.
+    Returns one fate in the following list:
+    - pruned
+    - diverged
+    - superseed
+    - superseed_split
+    """
+
+    if len(successorssets) == 0:
+        # The commit has been pruned
+        return 'pruned'
+    elif len(successorssets) > 1:
+        return 'diverged'
+    else:
+        # No divergence, only one set of successors
+        successors = successorssets[0]
+
+        if len(successors) == 1:
+            return 'superseed'
+        else:
+            return 'superseed_split'
+
+def _getobsfateandsuccs(repo, revnode):
+    """ Return a tuple containing:
+    - the reason a revision is obsolete (diverged, pruned or superseed)
+    - the list of successors short node if the revision is neither pruned
+    or has diverged
+    """
+    successorssets = obsolete.successorssets(repo, revnode)
+
+    fate = _getobsfate(successorssets)
+
+    # Apply node.short if we have no divergence
+    if len(successorssets) == 1:
+        successors = [nodemod.short(node_id) for node_id in successorssets[0]]
+    else:
+        successors = []
+
+    return (fate, successors)