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