comparison mercurial/ancestor.py @ 23342:f710644e1ce9

ancestor: add a way to remove ancestors of bases from a given set This and missingancestors can share state, which will turn out to be perfect for set discovery.
author Siddharth Agarwal <sid0@fb.com>
date Fri, 14 Nov 2014 19:40:30 -0800
parents bcc3012f8477
children 0ca8410ea345
comparison
equal deleted inserted replaced
23341:bcc3012f8477 23342:f710644e1ce9
152 152
153 def addbases(self, newbases): 153 def addbases(self, newbases):
154 '''grow the ancestor set by adding new bases''' 154 '''grow the ancestor set by adding new bases'''
155 self.bases.update(newbases) 155 self.bases.update(newbases)
156 156
157 def removeancestorsfrom(self, revs):
158 '''remove all ancestors of bases from the set revs (in place)'''
159 bases = self.bases
160 pfunc = self.pfunc
161 revs.difference_update(bases)
162 # nullrev is always an ancestor
163 revs.discard(nullrev)
164 if not revs:
165 return
166 # anything in revs > start is definitely not an ancestor of bases
167 # revs <= start needs to be investigated
168 start = max(bases)
169 keepcount = sum(1 for r in revs if r > start)
170 if len(revs) == keepcount:
171 # no revs to consider
172 return
173
174 for curr in xrange(start, min(revs) - 1, -1):
175 if curr not in bases:
176 continue
177 revs.discard(curr)
178 bases.update(pfunc(curr))
179 if len(revs) == keepcount:
180 # no more potential revs to discard
181 break
182
157 def missingancestors(self, revs): 183 def missingancestors(self, revs):
158 '''return all the ancestors of revs that are not ancestors of self.bases 184 '''return all the ancestors of revs that are not ancestors of self.bases
159 185
160 This may include elements from revs. 186 This may include elements from revs.
161 187