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