##// END OF EJS Templates
ancestors: extract candidates function as commonancestorsheads
Mads Kiilerich -
r21101:64911a12 default
parent child Browse files
Show More
@@ -9,21 +9,19 b' import heapq'
9 import util
9 import util
10 from node import nullrev
10 from node import nullrev
11
11
12 def ancestors(pfunc, *orignodes):
12 def commonancestorsheads(pfunc, *nodes):
13 """
13 """Returns a set with the heads of all common ancestors of all nodes,
14 Returns the common ancestors of a and b that are furthest from a
14 heads(::nodes[0] and ::nodes[1] and ...) .
15 root (as measured by longest path).
16
15
17 pfunc must return a list of parent vertices for a given vertex.
16 pfunc must return a list of parent vertices for a given vertex.
18 """
17 """
19 if not isinstance(orignodes, set):
18 if not isinstance(nodes, set):
20 orignodes = set(orignodes)
19 nodes = set(nodes)
21 if nullrev in orignodes:
20 if nullrev in nodes:
22 return set()
21 return set()
23 if len(orignodes) <= 1:
22 if len(nodes) <= 1:
24 return orignodes
23 return nodes
25
24
26 def candidates(nodes):
27 allseen = (1 << len(nodes)) - 1
25 allseen = (1 << len(nodes)) - 1
28 seen = [0] * (max(nodes) + 1)
26 seen = [0] * (max(nodes) + 1)
29 for i, n in enumerate(nodes):
27 for i, n in enumerate(nodes):
@@ -67,6 +65,13 b' def ancestors(pfunc, *orignodes):'
67 seen[p] = sv
65 seen[p] = sv
68 return gca
66 return gca
69
67
68 def ancestors(pfunc, *orignodes):
69 """
70 Returns the common ancestors of a and b that are furthest from a
71 root (as measured by longest path).
72
73 pfunc must return a list of parent vertices for a given vertex.
74 """
70 def deepest(nodes):
75 def deepest(nodes):
71 interesting = {}
76 interesting = {}
72 count = max(nodes) + 1
77 count = max(nodes) + 1
@@ -123,7 +128,7 b' def ancestors(pfunc, *orignodes):'
123 k |= i
128 k |= i
124 return set(n for (i, n) in mapping if k & i)
129 return set(n for (i, n) in mapping if k & i)
125
130
126 gca = candidates(orignodes)
131 gca = commonancestorsheads(pfunc, *orignodes)
127
132
128 if len(gca) <= 1:
133 if len(gca) <= 1:
129 return gca
134 return gca
General Comments 0
You need to be logged in to leave comments. Login now