# HG changeset patch # User Kevin Bullock <kbull...@ringworld.org> # Date 1525292536 18000 # Wed May 02 15:22:16 2018 -0500 # Node ID 335d45810dd93321242e7c329cf6d603a3aa7516 # Parent 1e166e3e0bd6bd0fed28a8e8b9961ff3e517bef7 land: extract a function to determine accepted ranges
Mostly indentation, diff best viewed with -w. diff --git a/land b/land --- a/land +++ b/land @@ -46,40 +46,46 @@ def _destcontains(node): # Find all accepted revisions all_accepted = [n for n in cq.draft() if cq.accepted(n)] -accepted_revset = ' + '.join(all_accepted) -info = json.load(os.popen("hg log -R %s -r '%s' -Tjson" % ( - conf.source, accepted_revset))) -# dict of node: its parents. -parents = {i['node']: i['parents'] for i in info} -# Identify heads and roots of accepted revision ranges -accepted_roots = {r.strip() for r in os.popen( - "hg log -R %s -r 'roots(%s)' -T'{node}\\n'" % ( - conf.source, accepted_revset))} -accepted_heads = [h.strip() for h in os.popen( - "hg log -R %s -r 'heads(%s)' -T'{node}\\n'" % ( - conf.source, accepted_revset))] -# Condense accepted revisions down into accepted ranges acceptrange = collections.namedtuple('acceptrange', 'roots head') -ranges = [] -for head in accepted_heads: - roots = [] - visit = [head] - while visit: - current = visit.pop(-1) - if _destcontains(current): - roots.append(current) - elif current not in accepted_roots: - visit.extend(parents[current]) - else: - roots.extend(parents[current]) - ranges.append(acceptrange(roots, head)) + +def accepted_ranges(all_accepted): + accepted_revset = ' + '.join(all_accepted) + info = json.load(os.popen("hg log -R %s -r '%s' -Tjson" % ( + conf.source, accepted_revset))) + # dict of node: its parents. + parents = {i['node']: i['parents'] for i in info} -logging.debug('accepted roots: %s', ' '.join(accepted_roots)) -logging.debug('accepted heads: %s', ' '.join(accepted_heads)) + # Identify heads and roots of accepted revision ranges + accepted_roots = {r.strip() for r in os.popen( + "hg log -R %s -r 'roots(%s)' -T'{node}\\n'" % ( + conf.source, accepted_revset))} + accepted_heads = [h.strip() for h in os.popen( + "hg log -R %s -r 'heads(%s)' -T'{node}\\n'" % ( + conf.source, accepted_revset))] + # Condense accepted revisions down into accepted ranges + ranges = [] + for head in accepted_heads: + roots = [] + visit = [head] + while visit: + current = visit.pop(-1) + if _destcontains(current): + roots.append(current) + elif current not in accepted_roots: + visit.extend(parents[current]) + else: + roots.extend(parents[current]) + ranges.append(acceptrange(roots, head)) + + logging.debug('accepted roots: %s', ' '.join(accepted_roots)) + logging.debug('accepted heads: %s', ' '.join(accepted_heads)) + + return ranges + # Figure out what range(s) are descended from the repo take = [] -for r in ranges: +for r in accepted_ranges(all_accepted): if not all(_destcontains(root) for root in r.roots): logging.debug('not all roots of range %r in dest', r) continue diff --git a/tests/test-land.t b/tests/test-land.t --- a/tests/test-land.t +++ b/tests/test-land.t @@ -3,7 +3,9 @@ BUG: Fails with no accepted nodes to lan $ land hg: parse error: empty query Traceback (most recent call last): - File "/Users/kbullock/Source/Projects/hg/accept/tests/../land", line 51, in <module> + File "/Users/kbullock/Source/Projects/hg/accept/tests/../land", line 87, in <module> + for r in accepted_ranges(all_accepted): + File "/Users/kbullock/Source/Projects/hg/accept/tests/../land", line 53, in accepted_ranges conf.source, accepted_revset))) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 290, in load **kw) _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel