96
# todo is a stack holding the revisions we still need to process;
98
# to_read is a stack holding the revisions we still need to process;
97
99
# appending to it adds new highest-priority revisions
98
self.todo = rev_history[:]
100
self.total_revs = len(self.todo)
103
self._convert_one_rev(self.todo.pop())
101
self.to_read = [rev_history[-1]]
102
self.total_revs = len(rev_history)
104
rev_id = self.to_read.pop()
105
if (rev_id not in self.revisions
106
and rev_id not in self.absent_revisions):
107
self._load_one_rev(rev_id)
112
# self._convert_one_rev(self.to_read.pop())
106
114
print 'upgraded to weaves:'
107
print ' %6d revisions and inventories' % len(self.converted_revs)
115
print ' %6d revisions and inventories' % len(self.revisions)
108
116
print ' %6d absent revisions removed' % len(self.absent_revisions)
109
117
print ' %6d texts' % self.text_count
136
def _load_one_rev(self, rev_id):
137
"""Load a revision object into memory.
139
Any parents not either loaded or abandoned get queued to be
141
self.pb.update('loading revision',
142
len(self.converted_revs),
144
if rev_id not in self.branch.revision_store:
146
note('revision {%s} not present in branch; '
147
'will not be converted',
149
self.absent_revisions.add(rev_id)
151
rev_xml = self.branch.revision_store[rev_id].read()
152
rev = serializer_v4.read_revision_from_string(rev_xml)
153
for parent_id in [x.revision_id for x in rev.parents]:
155
self.to_read.append(parent_id)
156
self.revisions[rev_id] = rev
159
def _make_order(self):
160
todo = set(self.revisions.keys())
161
done = self.absent_revisions.copy()
163
# scan through looking for a revision whose parents
165
for rev_id in list(todo):
166
rev = self.revisions[rev_id]
167
parent_ids = set([x.revision_id for x in rev.parents])
168
if parent_ids.issubset(done):
169
# can take this one now
176
# Cannot import a revision until all its parents have been
177
# imported. in other words, we can only import revisions whose
178
# parents have all been imported. the first step must be to
179
# import a revision with no parents, of which there must be at
180
# least one. (So perhaps it's useful to store forward pointers
181
# from a list of parents to their children?)
183
# Another (equivalent?) approach is to build up the ordered
184
# ancestry list for the last revision, and walk through that. We
185
# are going to need that.
187
# We don't want to have to recurse all the way back down the list.
189
# Suppose we keep a queue of the revisions able to be processed at
190
# any point. This starts out with all the revisions having no
193
# This seems like a generally useful algorithm...
128
195
def _convert_one_rev(self, rev_id):
129
196
self._bump_progress()
143
210
rev = serializer_v4.read_revision_from_string(rev_xml)
144
211
inv = serializer_v4.read_inventory_from_string(inv_xml)
146
# see if parents need to be done first
147
for parent_id in [x.revision_id for x in rev.parents]:
148
if parent_id not in self.converted_revs:
149
self.todo.append(parent_id)
151
213
self.converted_revs.add(rev_id)
153
215
return ##########################################
195
def _bump_progress(self):
196
self.pb.update('converting revisions',
197
len(self.converted_revs),
201
259
def write_atomic_weave(weave, filename):