57
59
from bzrlib.weavefile import read_weave, write_weave
58
60
from bzrlib.progress import ProgressBar
59
61
from bzrlib.atomicfile import AtomicFile
62
from bzrlib.xml4 import serializer_v4
63
from bzrlib.xml5 import serializer_v5
60
64
import bzrlib.trace
65
bzrlib.trace.enable_default_logging()
73
# holds in-memory weaves for all files
76
b = Branch('.', relax_version_check=True)
79
rev_history = b.revision_history()
84
for rev_id in rev_history:
85
pb.update('converting revision', revno, len(rev_history))
87
inv_xml = b.get_inventory_xml(rev_id).readlines()
89
new_idx = inv_weave.add(rev_id, inv_parents, inv_xml)
68
class Convert(object):
71
self.converted_revs = 0
78
bzrlib.trace.enable_default_logging()
79
self.pb = ProgressBar()
80
self.inv_weave = Weave('__inventory')
81
self.anc_weave = Weave('__ancestry')
85
# holds in-memory weaves for all files
88
b = self.branch = Branch('.', relax_version_check=True)
91
rev_history = b.revision_history()
95
# todo is a stack holding the revisions we still need to process;
96
# appending to it adds new highest-priority revisions
99
self.total_revs = len(todo)
102
self._convert_one_rev(todo.pop())
105
print 'upgraded to weaves:'
106
print ' %6d revisions and inventories' % self.converted_revs
107
print ' %6d texts' % self.text_count
109
self._write_all_weaves()
112
def _write_all_weaves(self):
114
return ############################################
115
# TODO: commit them all atomically at the end, not one by one
116
write_atomic_weave(self.inv_weave, 'weaves/inventory.weave')
117
write_atomic_weave(self.anc_weave, 'weaves/ancestry.weave')
118
for file_id, file_weave in text_weaves.items():
119
self.pb.update('writing weave', i, len(text_weaves))
120
write_atomic_weave(file_weave, 'weaves/%s.weave' % file_id)
126
def _convert_one_rev(self, rev_id):
127
self._bump_progress()
129
rev_xml = b.revision_store[rev_id].read()
130
inv_xml = b.inventory_store[rev_id].read()
132
rev = serializer_v4.read_revision_from_string(rev_xml)
133
inv = serializer_v4.read_inventory_from_string(inv_xml)
135
return ##########################################
137
new_idx = self.inv_weave.add(rev_id, inv_parents, inv_xml)
90
138
inv_parents = [new_idx]
92
140
tree = b.revision_tree(rev_id)
130
print '%6d revisions and inventories' % revno
131
print '%6d texts' % text_count
134
# TODO: commit them all atomically at the end, not one by one
135
write_atomic_weave(inv_weave, 'weaves/inventory.weave')
136
for file_id, file_weave in text_weaves.items():
137
pb.update('writing weave', i, len(text_weaves))
138
write_atomic_weave(file_weave, 'weaves/%s.weave' % file_id)
177
def _bump_progress(self):
178
self.converted_revs += 1
179
self.pb.update('converting revisions',
144
184
def write_atomic_weave(weave, filename):