Mercurial > hg
comparison mercurial/dagutil.py @ 14364:a3b9f1bddab1
revlogdag: add linearize function
See the docstring for a detailed explanation. The linearizer was originally
written by Benoit Boissinot.
author | Sune Foldager <cryo@cyanite.org> |
---|---|
date | Wed, 18 May 2011 23:11:34 +0200 |
parents | 2bf60f158ecb |
children | 1679d73c9464 |
comparison
equal
deleted
inserted
replaced
14363:82f3b0f3f0a5 | 14364:a3b9f1bddab1 |
---|---|
203 if prev != nullrev: | 203 if prev != nullrev: |
204 headrevs.discard(prev) | 204 headrevs.discard(prev) |
205 assert headrevs | 205 assert headrevs |
206 return headrevs | 206 return headrevs |
207 | 207 |
208 def linearize(self, ixs): | |
209 '''linearize and topologically sort a list of revisions | |
210 | |
211 The linearization process tries to create long runs of revs where | |
212 a child rev comes immediately after its first parent. This is done by | |
213 visiting the heads of the given revs in inverse topological order, | |
214 and for each visited rev, visiting its second parent, then its first | |
215 parent, then adding the rev itself to the output list. | |
216 ''' | |
217 sorted = [] | |
218 visit = list(self.headsetofconnecteds(ixs)) | |
219 visit.sort(reverse=True) | |
220 finished = set() | |
221 | |
222 while visit: | |
223 cur = visit.pop() | |
224 if cur < 0: | |
225 cur = -cur - 1 | |
226 if cur not in finished: | |
227 sorted.append(cur) | |
228 finished.add(cur) | |
229 else: | |
230 visit.append(-cur - 1) | |
231 visit += [p for p in self.parents(cur) | |
232 if p in ixs and p not in finished] | |
233 assert len(sorted) == len(ixs) | |
234 return sorted | |
235 | |
208 | 236 |
209 class inverserevlogdag(revlogbaseddag, genericdag): | 237 class inverserevlogdag(revlogbaseddag, genericdag): |
210 '''inverse of an existing revlog dag; see revlogdag.inverse()''' | 238 '''inverse of an existing revlog dag; see revlogdag.inverse()''' |
211 | 239 |
212 def __init__(self, orig): | 240 def __init__(self, orig): |