test-revlog-ancestry.py
88 lines
| 1.9 KiB
| text/x-python
|
PythonLexer
/ tests / test-revlog-ancestry.py
|
r28764 | from __future__ import absolute_import, print_function | ||
|
r6872 | import os | ||
|
r28763 | from mercurial import ( | ||
hg, | ||||
merge, | ||||
|
r28842 | ui as uimod, | ||
|
r28763 | ) | ||
|
r6872 | |||
|
r30559 | u = uimod.ui.load() | ||
|
r6872 | |||
|
r36500 | repo = hg.repository(u, b'test1', create=1) | ||
|
r6872 | os.chdir('test1') | ||
def commit(text, time): | ||||
|
r36500 | repo.commit(text=text, date=b"%d 0" % time) | ||
|
r6872 | |||
def addcommit(name, time): | ||||
|
r36501 | f = open(name, 'wb') | ||
|
r36500 | f.write(b'%s\n' % name) | ||
|
r6872 | f.close() | ||
|
r11303 | repo[None].add([name]) | ||
|
r6872 | commit(name, time) | ||
def update(rev): | ||||
|
r27344 | merge.update(repo, rev, False, True) | ||
|
r6872 | |||
def merge_(rev): | ||||
|
r27344 | merge.update(repo, rev, True, False) | ||
|
r6872 | |||
if __name__ == '__main__': | ||||
|
r36500 | addcommit(b"A", 0) | ||
addcommit(b"B", 1) | ||||
|
r6872 | |||
update(0) | ||||
|
r36500 | addcommit(b"C", 2) | ||
|
r6872 | |||
merge_(1) | ||||
|
r36500 | commit(b"D", 3) | ||
|
r6872 | |||
update(2) | ||||
|
r36500 | addcommit(b"E", 4) | ||
addcommit(b"F", 5) | ||||
|
r6872 | |||
update(3) | ||||
|
r36500 | addcommit(b"G", 6) | ||
|
r6872 | |||
merge_(5) | ||||
|
r36500 | commit(b"H", 7) | ||
|
r6872 | |||
update(5) | ||||
|
r36500 | addcommit(b"I", 8) | ||
|
r6872 | |||
# Ancestors | ||||
|
r28764 | print('Ancestors of 5') | ||
|
r16866 | for r in repo.changelog.ancestors([5]): | ||
|
r28764 | print(r, end=' ') | ||
|
r6872 | |||
|
r28764 | print('\nAncestors of 6 and 5') | ||
|
r16866 | for r in repo.changelog.ancestors([6, 5]): | ||
|
r28764 | print(r, end=' ') | ||
|
r6872 | |||
|
r28764 | print('\nAncestors of 5 and 4') | ||
|
r16866 | for r in repo.changelog.ancestors([5, 4]): | ||
|
r28764 | print(r, end=' ') | ||
|
r6872 | |||
|
r28764 | print('\nAncestors of 7, stop at 6') | ||
|
r16868 | for r in repo.changelog.ancestors([7], 6): | ||
|
r28764 | print(r, end=' ') | ||
|
r16868 | |||
|
r28764 | print('\nAncestors of 7, including revs') | ||
|
r18081 | for r in repo.changelog.ancestors([7], inclusive=True): | ||
|
r28764 | print(r, end=' ') | ||
|
r18081 | |||
|
r28764 | print('\nAncestors of 7, 5 and 3, including revs') | ||
|
r18081 | for r in repo.changelog.ancestors([7, 5, 3], inclusive=True): | ||
|
r28764 | print(r, end=' ') | ||
|
r18081 | |||
|
r6872 | # Descendants | ||
|
r28764 | print('\n\nDescendants of 5') | ||
|
r16867 | for r in repo.changelog.descendants([5]): | ||
|
r28764 | print(r, end=' ') | ||
|
r6872 | |||
|
r28764 | print('\nDescendants of 5 and 3') | ||
|
r16867 | for r in repo.changelog.descendants([5, 3]): | ||
|
r28764 | print(r, end=' ') | ||
|
r6872 | |||
|
r28764 | print('\nDescendants of 5 and 4') | ||
print(*repo.changelog.descendants([5, 4]), sep=' ') | ||||