~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bundle/bundle_data.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-05-11 15:04:23 UTC
  • mfrom: (5848.1.1 2.4-cython-first)
  • Revision ID: pqm@pqm.ubuntu.com-20110511150423-tpm1ablukqalkvim
(jameinel) Default to using Cython for compiling code,
 rather than Pyrex. (John A Meinel)

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
 
 
21
19
import base64
22
20
from cStringIO import StringIO
23
21
import os
576
574
            return None
577
575
        return new_path
578
576
 
579
 
    def get_root_id(self):
580
 
        return self.path2id('')
581
 
 
582
577
    def path2id(self, path):
583
578
        """Return the id of the file present at path in the target tree."""
584
579
        file_id = self._new_id.get(path)
589
584
            return None
590
585
        if old_path in self.deleted:
591
586
            return None
592
 
        return self.base_tree.path2id(old_path)
 
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)
593
591
 
594
592
    def id2path(self, file_id):
595
593
        """Return the new path in the target tree of the file with id file_id"""
625
623
        """
626
624
        base_id = self.old_contents_id(file_id)
627
625
        if (base_id is not None and
628
 
            base_id != self.base_tree.get_root_id()):
 
626
            base_id != self.base_tree.inventory.root.file_id):
629
627
            patch_original = self.base_tree.get_file(base_id)
630
628
        else:
631
629
            patch_original = None
632
630
        file_patch = self.patches.get(self.id2path(file_id))
633
631
        if file_patch is None:
634
632
            if (patch_original is None and
635
 
                self.kind(file_id) == 'directory'):
 
633
                self.get_kind(file_id) == 'directory'):
636
634
                return StringIO()
637
635
            if patch_original is None:
638
636
                raise AssertionError("None: %s" % file_id)
643
641
                'Malformed patch for %s, %r' % (file_id, file_patch))
644
642
        return patched_file(file_patch, patch_original)
645
643
 
646
 
    def get_symlink_target(self, file_id, path=None):
647
 
        if path is None:
648
 
            path = self.id2path(file_id)
 
644
    def get_symlink_target(self, file_id):
 
645
        new_path = self.id2path(file_id)
649
646
        try:
650
 
            return self._targets[path]
 
647
            return self._targets[new_path]
651
648
        except KeyError:
652
649
            return self.base_tree.get_symlink_target(file_id)
653
650
 
654
 
    def kind(self, file_id):
 
651
    def get_kind(self, file_id):
655
652
        if file_id in self._kinds:
656
653
            return self._kinds[file_id]
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)
 
654
        return self.base_tree.inventory[file_id].kind
665
655
 
666
656
    def is_executable(self, file_id):
667
657
        path = self.id2path(file_id)
668
658
        if path in self._executable:
669
659
            return self._executable[path]
670
660
        else:
671
 
            return self.base_tree.is_executable(file_id)
 
661
            return self.base_tree.inventory[file_id].executable
672
662
 
673
663
    def get_last_changed(self, file_id):
674
664
        path = self.id2path(file_id)
687
677
        if new_path not in self.patches:
688
678
            # If the entry does not have a patch, then the
689
679
            # contents must be the same as in the base_tree
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
 
680
            ie = self.base_tree.inventory[file_id]
 
681
            if ie.text_size is None:
 
682
                return ie.text_size, ie.text_sha1
 
683
            return int(ie.text_size), ie.text_sha1
693
684
        fileobj = self.get_file(file_id)
694
685
        content = fileobj.read()
695
686
        return len(content), sha_string(content)
700
691
        This need to be called before ever accessing self.inventory
701
692
        """
702
693
        from os.path import dirname, basename
 
694
        base_inv = self.base_tree.inventory
703
695
        inv = Inventory(None, self.revision_id)
704
696
 
705
697
        def add_entry(file_id):
712
704
                parent_path = dirname(path)
713
705
                parent_id = self.path2id(parent_path)
714
706
 
715
 
            kind = self.kind(file_id)
 
707
            kind = self.get_kind(file_id)
716
708
            revision_id = self.get_last_changed(file_id)
717
709
 
718
710
            name = basename(path)
723
715
                ie.executable = self.is_executable(file_id)
724
716
            elif kind == 'symlink':
725
717
                ie = InventoryLink(file_id, name, parent_id)
726
 
                ie.symlink_target = self.get_symlink_target(file_id, path)
 
718
                ie.symlink_target = self.get_symlink_target(file_id)
727
719
            ie.revision = revision_id
728
720
 
729
721
            if kind == 'file':
746
738
    # at that instant
747
739
    inventory = property(_get_inventory)
748
740
 
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()])
 
741
    def __iter__(self):
 
742
        for path, entry in self.inventory.iter_entries():
 
743
            yield entry.file_id
754
744
 
755
745
    def list_files(self, include_root=False, from_dir=None, recursive=True):
756
746
        # The only files returned by this are those from the version