~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bundle/bundle_data.py

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Read in a bundle stream, and process it into a BundleReader object."""
18
18
 
 
19
from __future__ import absolute_import
 
20
 
19
21
import base64
20
22
from cStringIO import StringIO
21
23
import os
574
576
            return None
575
577
        return new_path
576
578
 
 
579
    def get_root_id(self):
 
580
        return self.path2id('')
 
581
 
577
582
    def path2id(self, path):
578
583
        """Return the id of the file present at path in the target tree."""
579
584
        file_id = self._new_id.get(path)
584
589
            return None
585
590
        if old_path in self.deleted:
586
591
            return None
587
 
        if getattr(self.base_tree, 'path2id', None) is not None:
588
 
            return self.base_tree.path2id(old_path)
589
 
        else:
590
 
            return self.base_tree.inventory.path2id(old_path)
 
592
        return self.base_tree.path2id(old_path)
591
593
 
592
594
    def id2path(self, file_id):
593
595
        """Return the new path in the target tree of the file with id file_id"""
623
625
        """
624
626
        base_id = self.old_contents_id(file_id)
625
627
        if (base_id is not None and
626
 
            base_id != self.base_tree.inventory.root.file_id):
 
628
            base_id != self.base_tree.get_root_id()):
627
629
            patch_original = self.base_tree.get_file(base_id)
628
630
        else:
629
631
            patch_original = None
630
632
        file_patch = self.patches.get(self.id2path(file_id))
631
633
        if file_patch is None:
632
634
            if (patch_original is None and
633
 
                self.get_kind(file_id) == 'directory'):
 
635
                self.kind(file_id) == 'directory'):
634
636
                return StringIO()
635
637
            if patch_original is None:
636
638
                raise AssertionError("None: %s" % file_id)
649
651
        except KeyError:
650
652
            return self.base_tree.get_symlink_target(file_id)
651
653
 
652
 
    def get_kind(self, file_id):
 
654
    def kind(self, file_id):
653
655
        if file_id in self._kinds:
654
656
            return self._kinds[file_id]
655
 
        return self.base_tree.inventory[file_id].kind
 
657
        return self.base_tree.kind(file_id)
 
658
 
 
659
    def get_file_revision(self, file_id):
 
660
        path = self.id2path(file_id)
 
661
        if path in self._last_changed:
 
662
            return self._last_changed[path]
 
663
        else:
 
664
            return self.base_tree.get_file_revision(file_id)
656
665
 
657
666
    def is_executable(self, file_id):
658
667
        path = self.id2path(file_id)
659
668
        if path in self._executable:
660
669
            return self._executable[path]
661
670
        else:
662
 
            return self.base_tree.inventory[file_id].executable
 
671
            return self.base_tree.is_executable(file_id)
663
672
 
664
673
    def get_last_changed(self, file_id):
665
674
        path = self.id2path(file_id)
678
687
        if new_path not in self.patches:
679
688
            # If the entry does not have a patch, then the
680
689
            # contents must be the same as in the base_tree
681
 
            ie = self.base_tree.inventory[file_id]
682
 
            if ie.text_size is None:
683
 
                return ie.text_size, ie.text_sha1
684
 
            return int(ie.text_size), ie.text_sha1
 
690
            text_size = self.base_tree.get_file_size(file_id)
 
691
            text_sha1 = self.base_tree.get_file_sha1(file_id)
 
692
            return text_size, text_sha1
685
693
        fileobj = self.get_file(file_id)
686
694
        content = fileobj.read()
687
695
        return len(content), sha_string(content)
692
700
        This need to be called before ever accessing self.inventory
693
701
        """
694
702
        from os.path import dirname, basename
695
 
        base_inv = self.base_tree.inventory
696
703
        inv = Inventory(None, self.revision_id)
697
704
 
698
705
        def add_entry(file_id):
705
712
                parent_path = dirname(path)
706
713
                parent_id = self.path2id(parent_path)
707
714
 
708
 
            kind = self.get_kind(file_id)
 
715
            kind = self.kind(file_id)
709
716
            revision_id = self.get_last_changed(file_id)
710
717
 
711
718
            name = basename(path)
739
746
    # at that instant
740
747
    inventory = property(_get_inventory)
741
748
 
742
 
    def __iter__(self):
743
 
        for path, entry in self.inventory.iter_entries():
744
 
            yield entry.file_id
 
749
    root_inventory = property(_get_inventory)
 
750
 
 
751
    def all_file_ids(self):
 
752
        return set(
 
753
            [entry.file_id for path, entry in self.inventory.iter_entries()])
745
754
 
746
755
    def list_files(self, include_root=False, from_dir=None, recursive=True):
747
756
        # The only files returned by this are those from the version