113
112
return dict((revisions[revid], c)
114
113
for (revid, c) in self.children_of_id.iteritems())
116
def remove_redundant_parents(self, sorted_revids):
117
children_of_id = self.children_of_id
118
revisions = self.revisions
119
parent_ids_of = self.parent_ids_of
121
# Count the number of children of each revision, so we can release
122
# memory for ancestry data as soon as it's not going to be needed
124
pending_count_of = {}
125
for parent_id, children in children_of_id.iteritems():
126
pending_count_of[parent_id] = len(children)
128
# Build the ancestry dictionnary by examining older revisions first,
129
# and remove revision parents that are ancestors of other parents of
132
for revid in reversed(sorted_revids):
133
revision = revisions[revid]
134
parent_ids = parent_ids_of[revision]
135
# ignore candidate parents which are an ancestor of another parent,
136
# but never ignore the leftmost parent
138
ignorable_parent_ids = parent_ids[1:] # never ignore leftmost
139
for candidate_id in ignorable_parent_ids:
140
for parent_id in list(parent_ids):
141
if candidate_id in ancestor_ids_of[parent_id]:
142
redundant_ids.append(candidate_id)
143
parent_ids.remove(candidate_id)
144
children_of_candidate = children_of_id[candidate_id]
145
children_of_candidate.remove(revision)
147
# save the set of ancestors of that revision
148
ancestor_ids = set(parent_ids)
149
for parent_id in parent_ids:
150
ancestor_ids.update(ancestor_ids_of[parent_id])
151
ancestor_ids_of[revid] = ancestor_ids
152
# discard ancestry data for revisions whose children are already
154
for parent_id in parent_ids + redundant_ids:
155
pending_count = pending_count_of[parent_id] - 1
156
pending_count_of[parent_id] = pending_count
157
if pending_count == 0:
158
ancestor_ids_of[parent_id] = None
160
115
def sort_revisions(self, sorted_revids, maxnum):
161
116
revisions = self.revisions
162
117
parent_ids_of = self.parent_ids_of
282
237
self.colours[revid] = self.last_colour = self.last_colour + 1
285
def distances(branch, start, robust, maxnum):
240
def distances(branch, start, maxnum):
286
241
"""Sort the revisions.
288
243
Traverses the branch revision tree starting at start and produces an