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