##// END OF EJS Templates
dirstate: use wlock and changing_files context in `test-revlog-ancestry`...
marmoute -
r50934:7b289a70 default
parent child Browse files
Show More
@@ -1,92 +1,94
1 import os
1 import os
2 from mercurial import (
2 from mercurial import (
3 hg,
3 hg,
4 merge,
4 merge,
5 ui as uimod,
5 ui as uimod,
6 )
6 )
7
7
8 u = uimod.ui.load()
8 u = uimod.ui.load()
9
9
10 repo = hg.repository(u, b'test1', create=1)
10 repo = hg.repository(u, b'test1', create=1)
11 os.chdir('test1')
11 os.chdir('test1')
12
12
13
13
14 def commit(text, time):
14 def commit(text, time):
15 repo.commit(text=text, date=b"%d 0" % time)
15 repo.commit(text=text, date=b"%d 0" % time)
16
16
17
17
18 def addcommit(name, time):
18 def addcommit(name, time):
19 f = open(name, 'wb')
19 f = open(name, 'wb')
20 f.write(b'%s\n' % name)
20 f.write(b'%s\n' % name)
21 f.close()
21 f.close()
22 with repo.wlock():
23 with repo.dirstate.changing_files(repo):
22 repo[None].add([name])
24 repo[None].add([name])
23 commit(name, time)
25 commit(name, time)
24
26
25
27
26 def update(rev):
28 def update(rev):
27 merge.clean_update(repo[rev])
29 merge.clean_update(repo[rev])
28
30
29
31
30 def merge_(rev):
32 def merge_(rev):
31 merge.merge(repo[rev])
33 merge.merge(repo[rev])
32
34
33
35
34 if __name__ == '__main__':
36 if __name__ == '__main__':
35 addcommit(b"A", 0)
37 addcommit(b"A", 0)
36 addcommit(b"B", 1)
38 addcommit(b"B", 1)
37
39
38 update(0)
40 update(0)
39 addcommit(b"C", 2)
41 addcommit(b"C", 2)
40
42
41 merge_(1)
43 merge_(1)
42 commit(b"D", 3)
44 commit(b"D", 3)
43
45
44 update(2)
46 update(2)
45 addcommit(b"E", 4)
47 addcommit(b"E", 4)
46 addcommit(b"F", 5)
48 addcommit(b"F", 5)
47
49
48 update(3)
50 update(3)
49 addcommit(b"G", 6)
51 addcommit(b"G", 6)
50
52
51 merge_(5)
53 merge_(5)
52 commit(b"H", 7)
54 commit(b"H", 7)
53
55
54 update(5)
56 update(5)
55 addcommit(b"I", 8)
57 addcommit(b"I", 8)
56
58
57 # Ancestors
59 # Ancestors
58 print('Ancestors of 5')
60 print('Ancestors of 5')
59 for r in repo.changelog.ancestors([5]):
61 for r in repo.changelog.ancestors([5]):
60 print(r, end=' ')
62 print(r, end=' ')
61
63
62 print('\nAncestors of 6 and 5')
64 print('\nAncestors of 6 and 5')
63 for r in repo.changelog.ancestors([6, 5]):
65 for r in repo.changelog.ancestors([6, 5]):
64 print(r, end=' ')
66 print(r, end=' ')
65
67
66 print('\nAncestors of 5 and 4')
68 print('\nAncestors of 5 and 4')
67 for r in repo.changelog.ancestors([5, 4]):
69 for r in repo.changelog.ancestors([5, 4]):
68 print(r, end=' ')
70 print(r, end=' ')
69
71
70 print('\nAncestors of 7, stop at 6')
72 print('\nAncestors of 7, stop at 6')
71 for r in repo.changelog.ancestors([7], 6):
73 for r in repo.changelog.ancestors([7], 6):
72 print(r, end=' ')
74 print(r, end=' ')
73
75
74 print('\nAncestors of 7, including revs')
76 print('\nAncestors of 7, including revs')
75 for r in repo.changelog.ancestors([7], inclusive=True):
77 for r in repo.changelog.ancestors([7], inclusive=True):
76 print(r, end=' ')
78 print(r, end=' ')
77
79
78 print('\nAncestors of 7, 5 and 3, including revs')
80 print('\nAncestors of 7, 5 and 3, including revs')
79 for r in repo.changelog.ancestors([7, 5, 3], inclusive=True):
81 for r in repo.changelog.ancestors([7, 5, 3], inclusive=True):
80 print(r, end=' ')
82 print(r, end=' ')
81
83
82 # Descendants
84 # Descendants
83 print('\n\nDescendants of 5')
85 print('\n\nDescendants of 5')
84 for r in repo.changelog.descendants([5]):
86 for r in repo.changelog.descendants([5]):
85 print(r, end=' ')
87 print(r, end=' ')
86
88
87 print('\nDescendants of 5 and 3')
89 print('\nDescendants of 5 and 3')
88 for r in repo.changelog.descendants([5, 3]):
90 for r in repo.changelog.descendants([5, 3]):
89 print(r, end=' ')
91 print(r, end=' ')
90
92
91 print('\nDescendants of 5 and 4')
93 print('\nDescendants of 5 and 4')
92 print(*repo.changelog.descendants([5, 4]), sep=' ')
94 print(*repo.changelog.descendants([5, 4]), sep=' ')
General Comments 0
You need to be logged in to leave comments. Login now