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