##// END OF EJS Templates
parentrevspec: wrap docstrings at 70 characters
Martin Geisler -
r9268:1746da63 default
parent child Browse files
Show More
@@ -1,96 +1,96 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 '''interpret suffixes to refer to ancestor revisions
8 '''interpret suffixes to refer to ancestor revisions
9
9
10 This extension allows you to use git-style suffixes to refer to the ancestors
10 This extension allows you to use git-style suffixes to refer to the
11 of a specific revision.
11 ancestors of a specific revision.
12
12
13 For example, if you can refer to a revision as "foo", then::
13 For example, if you can refer to a revision as "foo", then::
14
14
15 foo^N = Nth parent of foo
15 foo^N = Nth parent of foo
16 foo^0 = foo
16 foo^0 = foo
17 foo^1 = first parent of foo
17 foo^1 = first parent of foo
18 foo^2 = second parent of foo
18 foo^2 = second parent of foo
19 foo^ = foo^1
19 foo^ = foo^1
20
20
21 foo~N = Nth first grandparent of foo
21 foo~N = Nth first grandparent of foo
22 foo~0 = foo
22 foo~0 = foo
23 foo~1 = foo^1 = foo^ = first parent of foo
23 foo~1 = foo^1 = foo^ = first parent of foo
24 foo~2 = foo^1^1 = foo^^ = first parent of first parent of foo
24 foo~2 = foo^1^1 = foo^^ = first parent of first parent of foo
25 '''
25 '''
26 from mercurial import error
26 from mercurial import error
27
27
28 def reposetup(ui, repo):
28 def reposetup(ui, repo):
29 if not repo.local():
29 if not repo.local():
30 return
30 return
31
31
32 class parentrevspecrepo(repo.__class__):
32 class parentrevspecrepo(repo.__class__):
33 def lookup(self, key):
33 def lookup(self, key):
34 try:
34 try:
35 _super = super(parentrevspecrepo, self)
35 _super = super(parentrevspecrepo, self)
36 return _super.lookup(key)
36 return _super.lookup(key)
37 except error.RepoError:
37 except error.RepoError:
38 pass
38 pass
39
39
40 circ = key.find('^')
40 circ = key.find('^')
41 tilde = key.find('~')
41 tilde = key.find('~')
42 if circ < 0 and tilde < 0:
42 if circ < 0 and tilde < 0:
43 raise
43 raise
44 elif circ >= 0 and tilde >= 0:
44 elif circ >= 0 and tilde >= 0:
45 end = min(circ, tilde)
45 end = min(circ, tilde)
46 else:
46 else:
47 end = max(circ, tilde)
47 end = max(circ, tilde)
48
48
49 cl = self.changelog
49 cl = self.changelog
50 base = key[:end]
50 base = key[:end]
51 try:
51 try:
52 node = _super.lookup(base)
52 node = _super.lookup(base)
53 except error.RepoError:
53 except error.RepoError:
54 # eek - reraise the first error
54 # eek - reraise the first error
55 return _super.lookup(key)
55 return _super.lookup(key)
56
56
57 rev = cl.rev(node)
57 rev = cl.rev(node)
58 suffix = key[end:]
58 suffix = key[end:]
59 i = 0
59 i = 0
60 while i < len(suffix):
60 while i < len(suffix):
61 # foo^N => Nth parent of foo
61 # foo^N => Nth parent of foo
62 # foo^0 == foo
62 # foo^0 == foo
63 # foo^1 == foo^ == 1st parent of foo
63 # foo^1 == foo^ == 1st parent of foo
64 # foo^2 == 2nd parent of foo
64 # foo^2 == 2nd parent of foo
65 if suffix[i] == '^':
65 if suffix[i] == '^':
66 j = i + 1
66 j = i + 1
67 p = cl.parentrevs(rev)
67 p = cl.parentrevs(rev)
68 if j < len(suffix) and suffix[j].isdigit():
68 if j < len(suffix) and suffix[j].isdigit():
69 j += 1
69 j += 1
70 n = int(suffix[i+1:j])
70 n = int(suffix[i+1:j])
71 if n > 2 or n == 2 and p[1] == -1:
71 if n > 2 or n == 2 and p[1] == -1:
72 raise
72 raise
73 else:
73 else:
74 n = 1
74 n = 1
75 if n:
75 if n:
76 rev = p[n - 1]
76 rev = p[n - 1]
77 i = j
77 i = j
78 # foo~N => Nth first grandparent of foo
78 # foo~N => Nth first grandparent of foo
79 # foo~0 = foo
79 # foo~0 = foo
80 # foo~1 = foo^1 == foo^ == 1st parent of foo
80 # foo~1 = foo^1 == foo^ == 1st parent of foo
81 # foo~2 = foo^1^1 == foo^^ == 1st parent of 1st parent of foo
81 # foo~2 = foo^1^1 == foo^^ == 1st parent of 1st parent of foo
82 elif suffix[i] == '~':
82 elif suffix[i] == '~':
83 j = i + 1
83 j = i + 1
84 while j < len(suffix) and suffix[j].isdigit():
84 while j < len(suffix) and suffix[j].isdigit():
85 j += 1
85 j += 1
86 if j == i + 1:
86 if j == i + 1:
87 raise
87 raise
88 n = int(suffix[i+1:j])
88 n = int(suffix[i+1:j])
89 for k in xrange(n):
89 for k in xrange(n):
90 rev = cl.parentrevs(rev)[0]
90 rev = cl.parentrevs(rev)[0]
91 i = j
91 i = j
92 else:
92 else:
93 raise
93 raise
94 return cl.node(rev)
94 return cl.node(rev)
95
95
96 repo.__class__ = parentrevspecrepo
96 repo.__class__ = parentrevspecrepo
General Comments 0
You need to be logged in to leave comments. Login now