##// END OF EJS Templates
Add ancestors and descendants to revlog...
Stefano Tortarolo -
r6872:c7cc40fd default
parent child Browse files
Show More
@@ -0,0 +1,74 b''
1 import os
2 from mercurial import hg, ui, merge
3 from hgext import graphlog
4
5 u = ui.ui()
6
7 repo = hg.repository(u, 'test1', create=1)
8 os.chdir('test1')
9
10 def commit(text, time):
11 repo.commit(text=text, date="%d 0" % time)
12
13 def addcommit(name, time):
14 f = file(name, 'w')
15 f.write('%s\n' % name)
16 f.close()
17 repo.add([name])
18 commit(name, time)
19
20 def update(rev):
21 merge.update(repo, rev, False, True, False)
22
23 def merge_(rev):
24 merge.update(repo, rev, True, False, False)
25
26 if __name__ == '__main__':
27 addcommit("A", 0)
28 addcommit("B", 1)
29
30 update(0)
31 addcommit("C", 2)
32
33 merge_(1)
34 commit("D", 3)
35
36 update(2)
37 addcommit("E", 4)
38 addcommit("F", 5)
39
40 update(3)
41 addcommit("G", 6)
42
43 merge_(5)
44 commit("H", 7)
45
46 update(5)
47 addcommit("I", 8)
48
49 # Ancestors
50 print 'Ancestors of 5'
51 for r in repo.changelog.ancestors(5):
52 print r,
53
54 print '\nAncestors of 6 and 5'
55 for r in repo.changelog.ancestors(6, 5):
56 print r,
57
58 print '\nAncestors of 5 and 4'
59 for r in repo.changelog.ancestors(5, 4):
60 print r,
61
62 # Descendants
63 print '\n\nDescendants of 5'
64 for r in repo.changelog.descendants(5):
65 print r,
66
67 print '\nDescendants of 5 and 3'
68 for r in repo.changelog.descendants(5, 3):
69 print r,
70
71 print '\nDescendants of 5 and 4'
72 for r in repo.changelog.descendants(5, 4):
73 print r,
74
@@ -0,0 +1,13 b''
1 Ancestors of 5
2 4 2 0
3 Ancestors of 6 and 5
4 3 4 2 1 0
5 Ancestors of 5 and 4
6 4 2 0
7
8 Descendants of 5
9 7 8
10 Descendants of 5 and 3
11 6 7 8
12 Descendants of 5 and 4
13 5 7 8
@@ -596,6 +596,27 b' class revlog(object):'
596 596 visit.append(p)
597 597 return reachable
598 598
599 def ancestors(self, *revs):
600 'Generate the ancestors of revs using a breadth-first visit'
601 visit = list(revs)
602 seen = util.set([nullrev])
603 while visit:
604 for parent in self.parentrevs(visit.pop(0)):
605 if parent not in seen:
606 visit.append(parent)
607 seen.add(parent)
608 yield parent
609
610 def descendants(self, *revs):
611 'Generate the descendants of revs in topological order'
612 seen = util.set(revs)
613 for i in xrange(min(revs) + 1, len(self)):
614 for x in self.parentrevs(i):
615 if x != nullrev and x in seen:
616 seen.add(i)
617 yield i
618 break
619
599 620 def nodesbetween(self, roots=None, heads=None):
600 621 """Return a tuple containing three elements. Elements 1 and 2 contain
601 622 a final list bases and heads after all the unreachable ones have been
General Comments 0
You need to be logged in to leave comments. Login now