/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/bundle/bundle_data.py

  • Committer: Jelmer Vernooij
  • Date: 2018-11-06 01:18:08 UTC
  • mfrom: (7143 work)
  • mto: This revision was merged to the branch mainline in revision 7151.
  • Revision ID: jelmer@jelmer.uk-20181106011808-y870f4vq0ork3ahu
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
from __future__ import absolute_import
20
20
 
21
21
import base64
 
22
from io import BytesIO
22
23
import os
23
24
import pprint
24
25
 
41
42
from ..osutils import sha_string, pathjoin
42
43
from ..revision import Revision, NULL_REVISION
43
44
from ..sixish import (
44
 
    BytesIO,
45
45
    viewitems,
46
46
    )
47
47
from ..testament import StrictTestament
53
53
class RevisionInfo(object):
54
54
    """Gets filled out for each revision object that is read.
55
55
    """
 
56
 
56
57
    def __init__(self, revision_id):
57
58
        self.revision_id = revision_id
58
59
        self.sha1 = None
349
350
 
350
351
        def do_patch(path, lines, encoding):
351
352
            if encoding == 'base64':
352
 
                patch = base64.decodestring(''.join(lines))
 
353
                patch = base64.b64decode(b''.join(lines))
353
354
            elif encoding is None:
354
 
                patch =  ''.join(lines)
 
355
                patch =  b''.join(lines)
355
356
            else:
356
357
                raise ValueError(encoding)
357
358
            bundle_tree.note_patch(path, patch)
628
629
        base_id = self.old_contents_id(file_id)
629
630
        if (base_id is not None and
630
631
            base_id != self.base_tree.get_root_id()):
 
632
            old_path = self.old_path(path)
631
633
            patch_original = self.base_tree.get_file(
632
 
                    self.base_tree.id2path(base_id), base_id)
 
634
                    old_path, base_id)
633
635
        else:
634
636
            patch_original = None
635
637
        file_patch = self.patches.get(path)
641
643
                raise AssertionError("None: %s" % file_id)
642
644
            return patch_original
643
645
 
644
 
        if file_patch.startswith('\\'):
 
646
        if file_patch.startswith(b'\\'):
645
647
            raise ValueError(
646
648
                'Malformed patch for %s, %r' % (file_id, file_patch))
647
649
        return patched_file(file_patch, patch_original)
650
652
        try:
651
653
            return self._targets[path]
652
654
        except KeyError:
653
 
            return self.base_tree.get_symlink_target(path, file_id)
 
655
            old_path = self.old_path(path)
 
656
            return self.base_tree.get_symlink_target(old_path, file_id)
654
657
 
655
658
    def kind(self, path, file_id=None):
656
659
        try:
657
660
            return self._kinds[path]
658
661
        except KeyError:
659
 
            return self.base_tree.kind(path, file_id)
 
662
            old_path = self.old_path(path)
 
663
            return self.base_tree.kind(old_path, file_id)
660
664
 
661
665
    def get_file_revision(self, path, file_id=None):
662
666
        if path in self._last_changed:
663
667
            return self._last_changed[path]
664
668
        else:
665
 
            return self.base_tree.get_file_revision(path, file_id)
 
669
            old_path = self.old_path(path)
 
670
            return self.base_tree.get_file_revision(old_path, file_id)
666
671
 
667
672
    def is_executable(self, path, file_id=None):
668
673
        if path in self._executable:
669
674
            return self._executable[path]
670
675
        else:
671
 
            return self.base_tree.is_executable(path, file_id)
 
676
            old_path = self.old_path(path)
 
677
            return self.base_tree.is_executable(old_path, file_id)
672
678
 
673
679
    def get_last_changed(self, path, file_id=None):
674
680
        if path in self._last_changed:
675
681
            return self._last_changed[path]
676
 
        return self.base_tree.get_file_revision(path, file_id)
 
682
        old_path = self.old_path(path)
 
683
        return self.base_tree.get_file_revision(old_path, file_id)
677
684
 
678
685
    def get_size_and_sha1(self, new_path, file_id=None):
679
686
        """Return the size and sha1 hash of the given file id.
685
692
        if new_path not in self.patches:
686
693
            # If the entry does not have a patch, then the
687
694
            # contents must be the same as in the base_tree
688
 
            base_path = self.base_tree.id2path(file_id)
 
695
            base_path = self.old_path(new_path)
689
696
            text_size = self.base_tree.get_file_size(base_path, file_id)
690
697
            text_sha1 = self.base_tree.get_file_sha1(base_path, file_id)
691
698
            return text_size, text_sha1
785
792
    """Produce a file-like object with the patched version of a text"""
786
793
    from breezy.patches import iter_patched
787
794
    from breezy.iterablefile import IterableFile
788
 
    if file_patch == "":
 
795
    if file_patch == b"":
789
796
        return IterableFile(())
790
797
    # string.splitlines(True) also splits on '\r', but the iter_patched code
791
798
    # only expects to iterate over '\n' style lines