~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bundle/bundle_data.py

Merge from unique-root

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
                           MalformedHeader, MalformedPatches, NotABundle)
27
27
from bzrlib.inventory import (Inventory, InventoryEntry,
28
28
                              InventoryDirectory, InventoryFile,
29
 
                              InventoryLink, ROOT_ID)
 
29
                              InventoryLink)
30
30
from bzrlib.osutils import sha_file, sha_string, pathjoin
31
31
from bzrlib.revision import Revision, NULL_REVISION
32
32
from bzrlib.testament import StrictTestament
223
223
            if repository.has_revision(revision_id):
224
224
                testament = StrictTestament.from_revision(repository, 
225
225
                                                          revision_id)
226
 
                local_sha1 = testament.as_sha1()
 
226
                local_sha1 = self._testament_sha1_from_revision(repository,
 
227
                                                                revision_id)
227
228
                if sha1 != local_sha1:
228
229
                    raise BzrError('sha1 mismatch. For revision id {%s}' 
229
230
                            'local: %s, bundle: %s' % (revision_id, local_sha1, sha1))
281
282
        rev_info = self.get_revision_info(revision_id)
282
283
        assert rev.revision_id == rev_info.revision_id
283
284
        assert rev.revision_id == revision_id
284
 
        sha1 = StrictTestament(rev, inventory).as_sha1()
 
285
        sha1 = self._testament_sha1(rev, inventory)
285
286
        if sha1 != rev_info.sha1:
286
287
            raise TestamentMismatch(rev.revision_id, rev_info.sha1, sha1)
287
288
        if rev.revision_id in rev_to_sha1:
440
441
        self.revision_id = revision_id
441
442
        self._inventory = None
442
443
 
443
 
    @staticmethod
444
 
    def _true_path(path):
445
 
        if path != '.':
446
 
            return path
447
 
        else:
448
 
            return ''
449
 
 
450
444
    def __str__(self):
451
445
        return pprint.pformat(self.__dict__)
452
446
 
453
447
    def note_rename(self, old_path, new_path):
454
448
        """A file/directory has been renamed from old_path => new_path"""
455
 
        new_path = self._true_path(new_path)
456
 
        old_path = self._true_path(old_path)
457
449
        assert new_path not in self._renamed
458
450
        assert old_path not in self._renamed_r
459
451
        self._renamed[new_path] = old_path
461
453
 
462
454
    def note_id(self, new_id, new_path, kind='file'):
463
455
        """Files that don't exist in base need a new id."""
464
 
        new_path = self._true_path(new_path)
465
456
        self._new_id[new_path] = new_id
466
457
        self._new_id_r[new_id] = new_path
467
458
        self._kinds[new_id] = kind
477
468
 
478
469
    def note_patch(self, new_path, patch):
479
470
        """There is a patch for a given filename."""
480
 
        self.patches[self._true_path(new_path)] = patch
 
471
        self.patches[new_path] = patch
481
472
 
482
473
    def note_target(self, new_path, target):
483
474
        """The symlink at the new path has the given target"""
484
 
        self._targets[self._true_path(new_path)] = target
 
475
        self._targets[new_path] = target
485
476
 
486
477
    def note_deletion(self, old_path):
487
478
        """The file at old_path has been deleted."""
488
 
        self.deleted.append(self._true_path(old_path))
 
479
        self.deleted.append(old_path)
489
480
 
490
481
    def note_executable(self, new_path, executable):
491
 
        self._executable[self._true_path(new_path)] = executable
 
482
        self._executable[new_path] = executable
492
483
 
493
484
    def old_path(self, new_path):
494
485
        """Get the old_path (path in the base_tree) for the file at new_path"""
495
 
        new_path = self._true_path(new_path)
496
486
        assert new_path[:1] not in ('\\', '/')
497
487
        old_path = self._renamed.get(new_path)
498
488
        if old_path is not None:
519
509
        """Get the new_path (path in the target_tree) for the file at old_path
520
510
        in the base tree.
521
511
        """
522
 
        old_path = self._true_path(old_path)
523
512
        assert old_path[:1] not in ('\\', '/')
524
513
        new_path = self._renamed_r.get(old_path)
525
514
        if new_path is not None:
589
578
                then be cached.
590
579
        """
591
580
        base_id = self.old_contents_id(file_id)
592
 
        if base_id is not None:
 
581
        if (base_id is not None and
 
582
            base_id != self.base_tree.inventory.root.file_id):
593
583
            patch_original = self.base_tree.get_file(base_id)
594
584
        else:
595
585
            patch_original = None
658
648
 
659
649
        assert self.base_tree is not None
660
650
        base_inv = self.base_tree.inventory
661
 
        root_id = ROOT_ID
662
 
        if base_inv.root is not None:
663
 
            root_id = base_inv.root.file_id
664
 
        try:
665
 
            root_id = self._new_id['']
666
 
        except KeyError:
667
 
            pass
668
 
        try:
669
 
            # New inventories have a unique root_id
670
 
            inv = Inventory(root_id, self.revision_id)
 
651
        try:
 
652
            inv = Inventory(None, self.revision_id)
671
653
        except TypeError:
672
654
            inv = Inventory(revision_id=self.revision_id)
673
 
        inv.root.revision = self.get_last_changed(root_id)
674
655
 
675
656
        def add_entry(file_id):
676
657
            path = self.id2path(file_id)
677
658
            if path is None:
678
659
                return
679
 
            parent_path = dirname(path)
680
 
            if parent_path == u'':
681
 
                parent_id = root_id
 
660
            if path == '':
 
661
                parent_id = None
682
662
            else:
 
663
                parent_path = dirname(path)
683
664
                parent_id = self.path2id(parent_path)
684
665
 
685
666
            kind = self.get_kind(file_id)
706
687
 
707
688
        sorted_entries = self.sorted_path_id()
708
689
        for path, file_id in sorted_entries:
709
 
            if file_id == inv.root.file_id:
710
 
                continue
711
690
            add_entry(file_id)
712
691
 
713
692
        return inv