##// END OF EJS Templates
revlogdag: add linearize function...
Sune Foldager -
r14364:a3b9f1bd default
parent child Browse files
Show More
@@ -205,6 +205,34 b' class revlogdag(revlogbaseddag):'
205 205 assert headrevs
206 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 237 class inverserevlogdag(revlogbaseddag, genericdag):
210 238 '''inverse of an existing revlog dag; see revlogdag.inverse()'''
General Comments 0
You need to be logged in to leave comments. Login now