##// END OF EJS Templates
parentrevspec: remove a trailing colon
Cédric Duval -
r8618:cf6f567e default
parent child Browse files
Show More
@@ -1,97 +1,97 b''
1 # Mercurial extension to make it easy to refer to the parent of a revision
1 # Mercurial extension to make it easy to refer to the parent of a revision
2 #
2 #
3 # Copyright (C) 2007 Alexis S. L. Carvalho <alexis@cecm.usp.br>
3 # Copyright (C) 2007 Alexis S. L. Carvalho <alexis@cecm.usp.br>
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2, incorporated herein by reference.
6 # GNU General Public License version 2, incorporated herein by reference.
7
7
8 '''\
8 '''\
9 use suffixes to refer to ancestor revisions
9 use suffixes to refer to ancestor revisions
10
10
11 This extension allows you to use git-style suffixes to refer to the
11 This extension allows you to use git-style suffixes to refer to the
12 ancestors of a specific revision.
12 ancestors of a specific revision.
13
13
14 For example, if you can refer to a revision as "foo", then:
14 For example, if you can refer to a revision as "foo", then:
15
15
16 - foo^N = Nth parent of foo:
16 - foo^N = Nth parent of foo
17 foo^0 = foo
17 foo^0 = foo
18 foo^1 = first parent of foo
18 foo^1 = first parent of foo
19 foo^2 = second parent of foo
19 foo^2 = second parent of foo
20 foo^ = foo^1
20 foo^ = foo^1
21
21
22 - foo~N = Nth first grandparent of foo
22 - foo~N = Nth first grandparent of foo
23 foo~0 = foo
23 foo~0 = foo
24 foo~1 = foo^1 = foo^ = first parent of foo
24 foo~1 = foo^1 = foo^ = first parent of foo
25 foo~2 = foo^1^1 = foo^^ = first parent of first parent of foo
25 foo~2 = foo^1^1 = foo^^ = first parent of first parent of foo
26 '''
26 '''
27 from mercurial import error
27 from mercurial import error
28
28
29 def reposetup(ui, repo):
29 def reposetup(ui, repo):
30 if not repo.local():
30 if not repo.local():
31 return
31 return
32
32
33 class parentrevspecrepo(repo.__class__):
33 class parentrevspecrepo(repo.__class__):
34 def lookup(self, key):
34 def lookup(self, key):
35 try:
35 try:
36 _super = super(parentrevspecrepo, self)
36 _super = super(parentrevspecrepo, self)
37 return _super.lookup(key)
37 return _super.lookup(key)
38 except error.RepoError:
38 except error.RepoError:
39 pass
39 pass
40
40
41 circ = key.find('^')
41 circ = key.find('^')
42 tilde = key.find('~')
42 tilde = key.find('~')
43 if circ < 0 and tilde < 0:
43 if circ < 0 and tilde < 0:
44 raise
44 raise
45 elif circ >= 0 and tilde >= 0:
45 elif circ >= 0 and tilde >= 0:
46 end = min(circ, tilde)
46 end = min(circ, tilde)
47 else:
47 else:
48 end = max(circ, tilde)
48 end = max(circ, tilde)
49
49
50 cl = self.changelog
50 cl = self.changelog
51 base = key[:end]
51 base = key[:end]
52 try:
52 try:
53 node = _super.lookup(base)
53 node = _super.lookup(base)
54 except error.RepoError:
54 except error.RepoError:
55 # eek - reraise the first error
55 # eek - reraise the first error
56 return _super.lookup(key)
56 return _super.lookup(key)
57
57
58 rev = cl.rev(node)
58 rev = cl.rev(node)
59 suffix = key[end:]
59 suffix = key[end:]
60 i = 0
60 i = 0
61 while i < len(suffix):
61 while i < len(suffix):
62 # foo^N => Nth parent of foo
62 # foo^N => Nth parent of foo
63 # foo^0 == foo
63 # foo^0 == foo
64 # foo^1 == foo^ == 1st parent of foo
64 # foo^1 == foo^ == 1st parent of foo
65 # foo^2 == 2nd parent of foo
65 # foo^2 == 2nd parent of foo
66 if suffix[i] == '^':
66 if suffix[i] == '^':
67 j = i + 1
67 j = i + 1
68 p = cl.parentrevs(rev)
68 p = cl.parentrevs(rev)
69 if j < len(suffix) and suffix[j].isdigit():
69 if j < len(suffix) and suffix[j].isdigit():
70 j += 1
70 j += 1
71 n = int(suffix[i+1:j])
71 n = int(suffix[i+1:j])
72 if n > 2 or n == 2 and p[1] == -1:
72 if n > 2 or n == 2 and p[1] == -1:
73 raise
73 raise
74 else:
74 else:
75 n = 1
75 n = 1
76 if n:
76 if n:
77 rev = p[n - 1]
77 rev = p[n - 1]
78 i = j
78 i = j
79 # foo~N => Nth first grandparent of foo
79 # foo~N => Nth first grandparent of foo
80 # foo~0 = foo
80 # foo~0 = foo
81 # foo~1 = foo^1 == foo^ == 1st parent of foo
81 # foo~1 = foo^1 == foo^ == 1st parent of foo
82 # foo~2 = foo^1^1 == foo^^ == 1st parent of 1st parent of foo
82 # foo~2 = foo^1^1 == foo^^ == 1st parent of 1st parent of foo
83 elif suffix[i] == '~':
83 elif suffix[i] == '~':
84 j = i + 1
84 j = i + 1
85 while j < len(suffix) and suffix[j].isdigit():
85 while j < len(suffix) and suffix[j].isdigit():
86 j += 1
86 j += 1
87 if j == i + 1:
87 if j == i + 1:
88 raise
88 raise
89 n = int(suffix[i+1:j])
89 n = int(suffix[i+1:j])
90 for k in xrange(n):
90 for k in xrange(n):
91 rev = cl.parentrevs(rev)[0]
91 rev = cl.parentrevs(rev)[0]
92 i = j
92 i = j
93 else:
93 else:
94 raise
94 raise
95 return cl.node(rev)
95 return cl.node(rev)
96
96
97 repo.__class__ = parentrevspecrepo
97 repo.__class__ = parentrevspecrepo
General Comments 0
You need to be logged in to leave comments. Login now