[PATCH] parentrevspec: ability to refer to ancestor of two revisions

Alexander Solovyov piranha at piranha.org.ua
Sun Oct 25 10:24:33 UTC 2009


# HG changeset patch
# User Alexander Solovyov <piranha at piranha.org.ua>
# Date 1256466270 -7200
# Node ID 06909bb8206c63e7d5795988ca39dcc194d0b008
# Parent  7d17794f08a9a63652aa51f614735568a675d764
parentrevspec: ability to refer to ancestor of two revisions

diff --git a/hgext/parentrevspec.py b/hgext/parentrevspec.py
--- a/hgext/parentrevspec.py
+++ b/hgext/parentrevspec.py
@@ -22,6 +22,10 @@ For example, if you can refer to a revis
   foo~0 = foo
   foo~1 = foo^1 = foo^ = first parent of foo
   foo~2 = foo^1^1 = foo^^ = first parent of first parent of foo
+
+  foo,bar^N = Nth ancestor of foo and bar
+  foo,bar^0 = first ancestor of foo and bar
+  foo,bar^  = foo,bar^0
 '''
 from mercurial import error
 
@@ -48,49 +52,60 @@ def reposetup(ui, repo):
 
             cl = self.changelog
             base = key[:end]
+            suffix = key[end:]
+
             try:
-                node = _super.lookup(base)
+                if ',' in base:
+                    n1, n2 = base.split(',', 1)
+                    node = cl.ancestor(_super.lookup(n1), _super.lookup(n2))
+                    if suffix == '^':
+                        suffix += '0'
+                else:
+                    node = _super.lookup(base)
             except error.RepoError:
                 # eek - reraise the first error
                 return _super.lookup(key)
 
-            rev = cl.rev(node)
-            suffix = key[end:]
-            i = 0
-            while i < len(suffix):
-                # foo^N => Nth parent of foo
-                # foo^0 == foo
-                # foo^1 == foo^ == 1st parent of foo
-                # foo^2 == 2nd parent of foo
-                if suffix[i] == '^':
-                    j = i + 1
-                    p = cl.parentrevs(rev)
-                    if j < len(suffix) and suffix[j].isdigit():
-                        j += 1
-                        n = int(suffix[i+1:j])
-                        if n > 2 or n == 2 and p[1] == -1:
-                            raise
-                    else:
-                        n = 1
-                    if n:
-                        rev = p[n - 1]
-                    i = j
-                # foo~N => Nth first grandparent of foo
-                # foo~0 = foo
-                # foo~1 = foo^1 == foo^ == 1st parent of foo
-                # foo~2 = foo^1^1 == foo^^ == 1st parent of 1st parent of foo
-                elif suffix[i] == '~':
-                    j = i + 1
-                    while j < len(suffix) and suffix[j].isdigit():
-                        j += 1
-                    if j == i + 1:
-                        raise
-                    n = int(suffix[i+1:j])
-                    for k in xrange(n):
-                        rev = cl.parentrevs(rev)[0]
-                    i = j
-                else:
-                    raise
-            return cl.node(rev)
+            return parse(cl, node, suffix)
 
     repo.__class__ = parentrevspecrepo
+
+
+def parse(cl, node, suffix):
+    rev = cl.rev(node)
+    i = 0
+    while i < len(suffix):
+        # foo^N => Nth parent of foo
+        # foo^0 == foo
+        # foo^1 == foo^ == 1st parent of foo
+        # foo^2 == 2nd parent of foo
+        if suffix[i] == '^':
+            j = i + 1
+            p = cl.parentrevs(rev)
+            if j < len(suffix) and suffix[j].isdigit():
+                j += 1
+                n = int(suffix[i+1:j])
+                if n > 2 or n == 2 and p[1] == -1:
+                    raise
+            else:
+                n = 1
+            if n:
+                rev = p[n - 1]
+            i = j
+        # foo~N => Nth first grandparent of foo
+        # foo~0 = foo
+        # foo~1 = foo^1 == foo^ == 1st parent of foo
+        # foo~2 = foo^1^1 == foo^^ == 1st parent of 1st parent of foo
+        elif suffix[i] == '~':
+            j = i + 1
+            while j < len(suffix) and suffix[j].isdigit():
+                j += 1
+            if j == i + 1:
+                raise
+            n = int(suffix[i+1:j])
+            for k in xrange(n):
+                rev = cl.parentrevs(rev)[0]
+            i = j
+        else:
+            raise
+    return cl.node(rev)



More information about the Mercurial-devel mailing list