# HG changeset patch # User Anton Shestakov # Date 1578907945 -25200 # Node ID 292de4cca11126a5662ea8db7afdea0f369e8123 # Parent ee5ad9739ed1120907eeff85175bd16e3032fba0 obshistory: make patchavailable() handle predecessors too diff -r ee5ad9739ed1 -r 292de4cca111 hgext3rd/evolve/obshistory.py --- a/hgext3rd/evolve/obshistory.py Tue Mar 17 19:37:08 2020 +0700 +++ b/hgext3rd/evolve/obshistory.py Mon Jan 13 16:32:25 2020 +0700 @@ -213,28 +213,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,