obshistory: make patchavailable() handle predecessors too draft
authorAnton Shestakov <av6@dwimlabs.net>
Mon, 13 Jan 2020 16:32:25 +0700
changeset 5256 0eba17d734ca
parent 5255 939ff6ea1e7d
child 5257 3e27cac81df6
obshistory: make patchavailable() handle predecessors too
hgext3rd/evolve/obshistory.py
--- a/hgext3rd/evolve/obshistory.py	Wed Jan 15 16:28:35 2020 +0700
+++ b/hgext3rd/evolve/obshistory.py	Mon Jan 13 16:32:25 2020 +0700
@@ -217,28 +217,40 @@
         '''
         pass
 
-def patchavailable(node, repo, successors):
+def patchavailable(node, repo, candidates, successive=True):
     if node not in repo:
         return False, b"context is not local"
 
-    if len(successors) == 0:
-        return False, b"no successors"
-    elif len(successors) > 1:
-        return False, b"too many successors (%d)" % len(successors)
-
-    succ = successors[0]
+    if len(candidates) == 0:
+        if successive:
+            msg = b"no successors"
+        else:
+            msg = b"no predecessors"
+        return False, msg
+    elif len(candidates) > 1:
+        if successive:
+            msg = b"too many successors (%d)"
+        else:
+            msg = b"too many predecessors (%d)"
+        return False, msg % len(candidates)
 
-    if succ not in repo:
-        return False, b"successor is unknown locally"
+    cand = candidates[0]
 
-    # Check that both node and succ have the same parents
+    if cand not in repo:
+        if successive:
+            msg = b"successor is unknown locally"
+        else:
+            msg = b"predecessor is unknown locally"
+        return False, msg
+
+    # Check that both node and cand have the same parents
     nodep1, nodep2 = repo[node].p1(), repo[node].p2()
-    succp1, succp2 = repo[succ].p1(), repo[succ].p2()
+    candp1, candp2 = repo[cand].p1(), repo[cand].p2()
 
-    if nodep1 != succp1 or nodep2 != succp2:
+    if nodep1 != candp1 or nodep2 != candp2:
         return False, b"changesets rebased"
 
-    return True, succ
+    return True, cand
 
 def getmarkerdescriptionpatch(repo, basedesc, succdesc):
     # description are stored without final new line,