~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/upgrade.py

  • Committer: Robert Collins
  • Date: 2005-10-06 00:52:53 UTC
  • Revision ID: robertc@robertcollins.net-20051006005253-415c38ad22094f13
define some expected behaviour for inventory_entry.snapshot

Show diffs side-by-side

added added

removed removed

Lines of Context:
95
95
from bzrlib.xml5 import serializer_v5
96
96
from bzrlib.trace import mutter, note, warning, enable_default_logging
97
97
from bzrlib.osutils import sha_strings, sha_string
 
98
from bzrlib.commit import merge_ancestry_lines
98
99
 
99
100
 
100
101
class Convert(object):
118
119
        if not os.path.isdir(self.base + '/.bzr/weaves'):
119
120
            os.mkdir(self.base + '/.bzr/weaves')
120
121
        self.inv_weave = Weave('inventory')
 
122
        self.anc_weave = Weave('ancestry')
 
123
        self.ancestries = {}
121
124
        # holds in-memory weaves for all files
122
125
        self.text_weaves = {}
123
126
        os.remove(self.branch.controlfilename('branch-format'))
194
197
 
195
198
    def _write_all_weaves(self):
196
199
        write_a_weave(self.inv_weave, self.base + '/.bzr/inventory.weave')
 
200
        write_a_weave(self.anc_weave, self.base + '/.bzr/ancestry.weave')
197
201
        i = 0
198
202
        try:
199
203
            for file_id, file_weave in self.text_weaves.items():
269
273
                           if p not in self.absent_revisions]
270
274
        self._convert_revision_contents(rev, inv, present_parents)
271
275
        self._store_new_weave(rev, inv, present_parents)
 
276
        self._make_rev_ancestry(rev, present_parents)
272
277
        self.converted_revs.add(rev_id)
273
278
 
274
279
 
290
295
                           new_inv_sha1)
291
296
        rev.inventory_sha1 = new_inv_sha1
292
297
 
 
298
 
 
299
    def _make_rev_ancestry(self, rev, present_parents):
 
300
        rev_id = rev.revision_id
 
301
        for parent_id in present_parents:
 
302
            assert parent_id in self.converted_revs
 
303
        if present_parents:
 
304
            lines = list(self.anc_weave.mash_iter(present_parents))
 
305
        else:
 
306
            lines = []
 
307
        lines.append(rev_id + '\n')
 
308
        if __debug__:
 
309
            parent_ancestries = [self.ancestries[p] for p in present_parents]
 
310
            new_lines = merge_ancestry_lines(rev_id, parent_ancestries)
 
311
            assert set(lines) == set(new_lines)
 
312
            self.ancestries[rev_id] = new_lines
 
313
        self.anc_weave.add(rev_id, present_parents, lines)
 
314
 
 
315
 
293
316
    def _convert_revision_contents(self, rev, inv, present_parents):
294
317
        """Convert all the files within a revision.
295
318
 
317
340
            w = Weave(file_id)
318
341
            self.text_weaves[file_id] = w
319
342
        text_changed = False
320
 
        previous_entries = ie.find_previous_heads(parent_invs, w)
321
 
        for old_revision in previous_entries:
 
343
        previous_revisions = {}
 
344
        for parent_inv in parent_invs:
 
345
            if parent_inv.has_id(file_id):
 
346
                previous_ie = parent_inv[file_id]
 
347
                if previous_ie.revision in previous_revisions:
 
348
                    assert previous_revisions[previous_ie.revision] == previous_ie
 
349
                else:
 
350
                    previous_revisions[previous_ie.revision] = previous_ie
 
351
                old_revision = previous_ie.revision
 
352
        for old_revision in previous_revisions:
322
353
                # if this fails, its a ghost ?
323
354
                assert old_revision in self.converted_revs 
324
 
        self.snapshot_ie(previous_entries, ie, w, rev_id)
 
355
        self.snapshot_ie(previous_revisions, ie, w, rev_id)
325
356
        del ie.text_id
326
357
        assert getattr(ie, 'revision', None) is not None
327
358
 
328
359
    def snapshot_ie(self, previous_revisions, ie, w, rev_id):
329
360
        # TODO: convert this logic, which is ~= snapshot to
330
361
        # a call to:. This needs the path figured out. rather than a work_tree
331
 
        # a v4 revision_tree can be given, or something that looks enough like
332
 
        # one to give the file content to the entry if it needs it.
 
362
        # a v4 revision_tree can be given, or something that can give the
 
363
        # text for the ie if it needs it.
333
364
        # and we need something that looks like a weave store for snapshot to 
334
365
        # save against.
335
366
        #ie.snapshot(rev, PATH, previous_revisions, REVISION_TREE, InMemoryWeaveStore(self.text_weaves))