diff mercurial/revlog.py @ 1351:0e2be889ccd7

Repair ancestor logic, fix up test cases
author Matt Mackall <mpm@selenic.com>
date Mon, 26 Sep 2005 16:52:47 -0700
parents 57220daf40e9
children 67779d34cb52 518da3c3b6ce
line wrap: on
line diff
--- a/mercurial/revlog.py	Mon Sep 26 14:01:18 2005 -0700
+++ b/mercurial/revlog.py	Mon Sep 26 16:52:47 2005 -0700
@@ -439,24 +439,45 @@
                 if n not in seen:
                     seen[n] = 1
                     r = self.rev(n)
-                    yield (-d, r, n)
+                    yield (-d, n)
                     for p in self.parents(n):
                         heapq.heappush(h, (-dist[p], p))
 
-        x = ancestors(a)
-        y = ancestors(b)
-        lx = x.next()
-        ly = y.next()
+        def generations(node):
+            sg, s = None, {}
+            for g,n in ancestors(node):
+                if g != sg:
+                    if sg:
+                        yield sg, s
+                    sg, s = g, {n:1}
+                else:
+                    s[n] = 1
+            yield sg, s
+
+        x = generations(a)
+        y = generations(b)
+        gx = x.next()
+        gy = y.next()
 
         # increment each ancestor list until it is closer to root than
         # the other, or they match
         while 1:
-            if lx == ly:
-                return lx[2]
-            elif lx < ly:
-                ly = y.next()
-            elif lx > ly:
-                lx = x.next()
+            #print "ancestor gen %s %s" % (gx[0], gy[0])
+            if gx[0] == gy[0]:
+                # find the intersection
+                i = [ n for n in gx[1] if n in gy[1] ]
+                if i:
+                    return i[0]
+                else:
+                    #print "next"
+                    gy = y.next()
+                    gx = x.next()
+            elif gx[0] < gy[0]:
+                #print "next y"
+                gy = y.next()
+            else:
+                #print "next x"
+                gx = x.next()
 
     def group(self, linkmap):
         """calculate a delta group