Show More
@@ -0,0 +1,96 b'' | |||
|
1 | # Mercurial extension to make it easy to refer to the parent of a revision | |
|
2 | # | |
|
3 | # Copyright (C) 2007 Alexis S. L. Carvalho <alexis@cecm.usp.br> | |
|
4 | # | |
|
5 | # This software may be used and distributed according to the terms | |
|
6 | # of the GNU General Public License, incorporated herein by reference. | |
|
7 | '''\ | |
|
8 | use suffixes to refer to ancestor revisions | |
|
9 | ||
|
10 | This extension allows you to use git-style suffixes to refer to | |
|
11 | the ancestors of a specific revision. | |
|
12 | ||
|
13 | For example, if you can refer to a revision as "foo", then: | |
|
14 | ||
|
15 | - foo^N = Nth parent of foo: | |
|
16 | foo^0 = foo | |
|
17 | foo^1 = first parent of foo | |
|
18 | foo^2 = second parent of foo | |
|
19 | foo^ = foo^1 | |
|
20 | ||
|
21 | - foo~N = Nth first grandparent of foo | |
|
22 | foo~0 = 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 | |
|
25 | ''' | |
|
26 | import mercurial.repo | |
|
27 | ||
|
28 | def reposetup(ui, repo): | |
|
29 | if not repo.local(): | |
|
30 | return | |
|
31 | ||
|
32 | class parentrevspecrepo(repo.__class__): | |
|
33 | def lookup(self, key): | |
|
34 | try: | |
|
35 | _super = super(parentrevspecrepo, self) | |
|
36 | return _super.lookup(key) | |
|
37 | except mercurial.repo.RepoError: | |
|
38 | pass | |
|
39 | ||
|
40 | circ = key.find('^') | |
|
41 | tilde = key.find('~') | |
|
42 | if circ < 0 and tilde < 0: | |
|
43 | raise | |
|
44 | elif circ >= 0 and tilde >= 0: | |
|
45 | end = min(circ, tilde) | |
|
46 | else: | |
|
47 | end = max(circ, tilde) | |
|
48 | ||
|
49 | cl = self.changelog | |
|
50 | base = key[:end] | |
|
51 | try: | |
|
52 | node = _super.lookup(base) | |
|
53 | except mercurial.repo.RepoError: | |
|
54 | # eek - reraise the first error | |
|
55 | return _super.lookup(key) | |
|
56 | ||
|
57 | rev = cl.rev(node) | |
|
58 | suffix = key[end:] | |
|
59 | i = 0 | |
|
60 | while i < len(suffix): | |
|
61 | # foo^N => Nth parent of foo | |
|
62 | # foo^0 == foo | |
|
63 | # foo^1 == foo^ == 1st parent of foo | |
|
64 | # foo^2 == 2nd parent of foo | |
|
65 | if suffix[i] == '^': | |
|
66 | j = i + 1 | |
|
67 | p = cl.parentrevs(rev) | |
|
68 | if j < len(suffix) and suffix[j].isdigit(): | |
|
69 | j += 1 | |
|
70 | n = int(suffix[i+1:j]) | |
|
71 | if n > 2 or n == 2 and p[1] == -1: | |
|
72 | raise | |
|
73 | else: | |
|
74 | n = 1 | |
|
75 | if n: | |
|
76 | rev = p[n - 1] | |
|
77 | i = j | |
|
78 | # foo~N => Nth first grandparent of foo | |
|
79 | # foo~0 = 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 | |
|
82 | elif suffix[i] == '~': | |
|
83 | j = i + 1 | |
|
84 | while j < len(suffix) and suffix[j].isdigit(): | |
|
85 | j += 1 | |
|
86 | if j == i + 1: | |
|
87 | raise | |
|
88 | n = int(suffix[i+1:j]) | |
|
89 | for k in xrange(n): | |
|
90 | rev = cl.parentrevs(rev)[0] | |
|
91 | i = j | |
|
92 | else: | |
|
93 | raise | |
|
94 | return cl.node(rev) | |
|
95 | ||
|
96 | repo.__class__ = parentrevspecrepo |
@@ -0,0 +1,69 b'' | |||
|
1 | #!/bin/sh | |
|
2 | ||
|
3 | commit() | |
|
4 | { | |
|
5 | msg=$1 | |
|
6 | p1=$2 | |
|
7 | p2=$3 | |
|
8 | ||
|
9 | if [ "$p1" ]; then | |
|
10 | hg up -qC $p1 | |
|
11 | fi | |
|
12 | ||
|
13 | if [ "$p2" ]; then | |
|
14 | HGMERGE=true hg merge -q $p2 | |
|
15 | fi | |
|
16 | ||
|
17 | echo >> foo | |
|
18 | ||
|
19 | hg commit -d '0 0' -qAm "$msg" foo | |
|
20 | } | |
|
21 | ||
|
22 | hg init repo | |
|
23 | cd repo | |
|
24 | ||
|
25 | echo '[extensions]' > .hg/hgrc | |
|
26 | echo 'hgext.parentrevspec =' >> .hg/hgrc | |
|
27 | ||
|
28 | commit '0: add foo' | |
|
29 | commit '1: change foo 1' | |
|
30 | commit '2: change foo 2a' | |
|
31 | commit '3: change foo 3a' | |
|
32 | commit '4: change foo 2b' 1 | |
|
33 | commit '5: merge' 3 4 | |
|
34 | commit '6: change foo again' | |
|
35 | ||
|
36 | hg log --template '#rev#:#node|short# #parents#\n' | |
|
37 | echo | |
|
38 | ||
|
39 | lookup() | |
|
40 | { | |
|
41 | for rev in "$@"; do | |
|
42 | printf "$rev: " | |
|
43 | hg id -nr $rev | |
|
44 | done | |
|
45 | true | |
|
46 | } | |
|
47 | ||
|
48 | tipnode=`hg id -ir tip` | |
|
49 | ||
|
50 | echo 'should work with tag/branch/node/rev' | |
|
51 | for r in tip default $tipnode 6; do | |
|
52 | lookup $r^ | |
|
53 | done | |
|
54 | echo | |
|
55 | ||
|
56 | echo 'some random lookups' | |
|
57 | lookup 6^^ 6^^^ 6^^^^ 6^^^^^ 6^^^^^^ 6^1 6^2 6^^2 6^1^2 6^^3 | |
|
58 | lookup 6~ 6~1 6~2 6~3 6~4 6~5 6~42 6~1^2 6~1^2~2 | |
|
59 | echo | |
|
60 | ||
|
61 | echo 'with a tag "6^" pointing to rev 1' | |
|
62 | hg tag -l -r 1 6^ | |
|
63 | lookup 6^ 6^1 6~1 6^^ | |
|
64 | echo | |
|
65 | ||
|
66 | echo 'with a tag "foo^bar" pointing to rev 2' | |
|
67 | hg tag -l -r 2 foo^bar | |
|
68 | lookup foo^bar foo^bar^ | |
|
69 |
@@ -0,0 +1,44 b'' | |||
|
1 | 6:755d1e0d79e9 | |
|
2 | 5:9ce2ce29723a 3:a3e00c7dbf11 4:bb4475edb621 | |
|
3 | 4:bb4475edb621 1:5d953a1917d1 | |
|
4 | 3:a3e00c7dbf11 | |
|
5 | 2:befc7d89d081 | |
|
6 | 1:5d953a1917d1 | |
|
7 | 0:837088b6e1d9 | |
|
8 | ||
|
9 | should work with tag/branch/node/rev | |
|
10 | tip^: 5 | |
|
11 | default^: 5 | |
|
12 | 755d1e0d79e9^: 5 | |
|
13 | 6^: 5 | |
|
14 | ||
|
15 | some random lookups | |
|
16 | 6^^: 3 | |
|
17 | 6^^^: 2 | |
|
18 | 6^^^^: 1 | |
|
19 | 6^^^^^: 0 | |
|
20 | 6^^^^^^: -1 | |
|
21 | 6^1: 5 | |
|
22 | 6^2: abort: unknown revision '6^2'! | |
|
23 | 6^^2: 4 | |
|
24 | 6^1^2: 4 | |
|
25 | 6^^3: abort: unknown revision '6^^3'! | |
|
26 | 6~: abort: unknown revision '6~'! | |
|
27 | 6~1: 5 | |
|
28 | 6~2: 3 | |
|
29 | 6~3: 2 | |
|
30 | 6~4: 1 | |
|
31 | 6~5: 0 | |
|
32 | 6~42: -1 | |
|
33 | 6~1^2: 4 | |
|
34 | 6~1^2~2: 0 | |
|
35 | ||
|
36 | with a tag "6^" pointing to rev 1 | |
|
37 | 6^: 1 | |
|
38 | 6^1: 5 | |
|
39 | 6~1: 5 | |
|
40 | 6^^: 3 | |
|
41 | ||
|
42 | with a tag "foo^bar" pointing to rev 2 | |
|
43 | foo^bar: 2 | |
|
44 | foo^bar^: abort: unknown revision 'foo^bar^'! |
General Comments 0
You need to be logged in to leave comments.
Login now