[PATCH] parentrevspec: ability to refer to ancestor of few revisions
Alexander Solovyov
piranha at piranha.org.ua
Sun Oct 25 15:45:17 UTC 2009
# HG changeset patch
# User Alexander Solovyov <piranha at piranha.org.ua>
# Date 1256485455 -7200
# Node ID 26073b3e8ab982fdccb71c595e8cf0dd87a07c99
# Parent 20b91f91f9cadfc2de79e7a2ecc07302b05ebca1
parentrevspec: ability to refer to ancestor of few revisions
diff --git a/hgext/parentrevspec.py b/hgext/parentrevspec.py
--- a/hgext/parentrevspec.py
+++ b/hgext/parentrevspec.py
@@ -22,6 +22,11 @@ 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
+ r1,r2,r3^ = first ancestor of r1, r2 and r3
'''
from mercurial import error
@@ -48,49 +53,61 @@ def reposetup(ui, repo):
cl = self.changelog
base = key[:end]
+ suffix = key[end:]
+
try:
- node = _super.lookup(base)
+ l = _super.lookup
+ if ',' in base:
+ nodes = base.split(',')
+ node = reduce(lambda x, y: cl.ancestor(l(x), l(y)), nodes)
+ 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