comparison mercurial/revlog.py @ 45:f2b2d5daec30

Fix recursion depth trouble with ancestor algorithm
author mpm@selenic.com
date Tue, 10 May 2005 00:34:57 -0800
parents df3f46253878
children 93e868fa0db8
comparison
equal deleted inserted replaced
44:e825a68d7227 45:f2b2d5daec30
168 168
169 self.cache = (node, n, text) 169 self.cache = (node, n, text)
170 return node 170 return node
171 171
172 def ancestor(self, a, b): 172 def ancestor(self, a, b):
173 def expand(e1, e2, a1, a2): 173 def expand(list, map):
174 ne = [] 174 a = []
175 for n in e1: 175 while list:
176 (p1, p2) = self.parents(n) 176 n = list.pop(0)
177 if p1 in a2: return p1 177 map[n] = 1
178 if p2 in a2: return p2 178 yield n
179 if p1 != nullid and p1 not in a1: 179 for p in self.parents(n):
180 a1[p1] = 1 180 if p != nullid and p not in map:
181 ne.append(p1) 181 list.append(p)
182 if p2 != nullid and p2 not in a1: 182 yield nullid
183 a1[p2] = 1 183
184 ne.append(p2) 184 amap = {}
185 return expand(e2, ne, a2, a1) 185 bmap = {}
186 return expand([a], [b], {a:1}, {b:1}) 186 ag = expand([a], amap)
187 bg = expand([b], bmap)
188 adone = bdone = 0
189
190 while not adone or not bdone:
191 if not adone:
192 an = ag.next()
193 if an == nullid:
194 adone = 1
195 elif an in bmap:
196 return an
197 if not bdone:
198 bn = bg.next()
199 if bn == nullid:
200 bdone = 1
201 elif bn in amap:
202 return bn
203
204 return nullid
187 205
188 def mergedag(self, other, transaction, linkseq, accumulate = None): 206 def mergedag(self, other, transaction, linkseq, accumulate = None):
189 """combine the nodes from other's DAG into ours""" 207 """combine the nodes from other's DAG into ours"""
190 old = self.tip() 208 old = self.tip()
191 i = self.count() 209 i = self.count()