~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to tools/history2weaves.py

  • Committer: Martin Pool
  • Date: 2005-09-19 12:15:55 UTC
  • Revision ID: mbp@sourcefrog.net-20050919121555-af4c0c6aeabb6a1d
- produce ancestry when converting versions

Show diffs side-by-side

added added

removed removed

Lines of Context:
92
92
from bzrlib.xml5 import serializer_v5
93
93
from bzrlib.trace import mutter, note, warning, enable_default_logging
94
94
from bzrlib.osutils import sha_strings, sha_string
95
 
 
 
95
from bzrlib.commit import merge_ancestry_lines
96
96
 
97
97
 
98
98
class Convert(object):
102
102
        self.text_count = 0
103
103
        self.revisions = {}
104
104
        self.inventories = {}
105
 
        self.ancestries = {}
106
105
        self.convert()
107
106
        
108
107
 
113
112
        self.pb = ProgressBar()
114
113
        self.inv_weave = Weave('__inventory')
115
114
        self.anc_weave = Weave('__ancestry')
116
 
 
117
 
        last_text_sha = {}
118
 
 
 
115
        self.ancestries = {}
119
116
        # holds in-memory weaves for all files
120
117
        self.text_weaves = {}
121
118
 
122
 
        b = self.branch = Branch('.', relax_version_check=True)
 
119
        self.branch = Branch('.', relax_version_check=True)
123
120
 
124
121
        revno = 1
125
 
        rev_history = b.revision_history()
 
122
        rev_history = self.branch.revision_history()
126
123
        last_idx = None
127
124
        inv_parents = []
128
125
 
151
148
 
152
149
 
153
150
    def _write_all_weaves(self):
 
151
        write_a_weave(self.inv_weave, 'weaves/inventory.weave')
 
152
        write_a_weave(self.anc_weave, 'weaves/ancestry.weave')
154
153
        i = 0
155
 
        write_a_weave(self.inv_weave, 'weaves/inventory.weave')
156
154
        try:
157
155
            for file_id, file_weave in self.text_weaves.items():
158
156
                self.pb.update('writing weave', i, len(self.text_weaves))
160
158
                i += 1
161
159
        finally:
162
160
            self.pb.clear()
163
 
        ## write_atomic_weave(self.anc_weave, 'weaves/ancestry.weave')
164
161
 
165
162
 
166
163
    def _write_all_revs(self):
208
205
        """Convert revision and all referenced objects to new format."""
209
206
        rev = self.revisions[rev_id]
210
207
        inv = self.inventories[rev_id]
 
208
        for parent_id in rev.parent_ids[:]:
 
209
            if parent_id in self.absent_revisions:
 
210
                rev.parent_ids.remove(parent_id)
 
211
                self.pb.clear()
 
212
                note('remove {%s} as parent of {%s}', parent_id, rev_id)
211
213
        self._convert_revision_contents(rev, inv)
212
214
        # the XML is now updated with text versions
213
215
        new_inv_xml = serializer_v5.write_inventory_to_string(inv)
214
 
        inv_parents = [x for x in self.revisions[rev_id].parent_ids
215
 
                       if x not in self.absent_revisions]
216
216
        new_inv_sha1 = sha_string(new_inv_xml)
217
 
        self.inv_weave.add(rev_id, inv_parents,
 
217
        self.inv_weave.add(rev_id, rev.parent_ids,
218
218
                           new_inv_xml.splitlines(True),
219
219
                           new_inv_sha1)
220
220
        # TODO: Upgrade revision XML and write that out
221
221
        rev.inventory_sha1 = new_inv_sha1
 
222
        self._make_rev_ancestry(rev)
222
223
        self.converted_revs.add(rev_id)
223
224
 
224
225
 
 
226
    def _make_rev_ancestry(self, rev):
 
227
        rev_id = rev.revision_id
 
228
        for parent_id in rev.parent_ids:
 
229
            assert parent_id in self.converted_revs
 
230
        parent_ancestries = [self.ancestries[p] for p in rev.parent_ids]
 
231
        new_lines = merge_ancestry_lines(rev_id, parent_ancestries)
 
232
        self.ancestries[rev_id] = new_lines
 
233
        self.anc_weave.add(rev_id, rev.parent_ids, new_lines)
 
234
 
 
235
 
225
236
    def _convert_revision_contents(self, rev, inv):
226
237
        """Convert all the files within a revision.
227
238
 
255
266
        file_parents = []
256
267
        text_changed = False
257
268
        for parent_id in rev.parent_ids:
258
 
            if parent_id in self.absent_revisions:
259
 
                continue
260
 
            assert parent_id in self.converted_revs
 
269
            ##if parent_id in self.absent_revisions:
 
270
            ##    continue
 
271
            assert parent_id in self.converted_revs, \
 
272
                   'parent {%s} not converted' % parent_id
261
273
            parent_inv = self.inventories[parent_id]
262
274
            if parent_inv.has_id(file_id):
263
275
                parent_ie = parent_inv[file_id]