/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: 2019-06-03 23:48:08 UTC
  • mfrom: (7316 work)
  • mto: This revision was merged to the branch mainline in revision 7328.
  • Revision ID: jelmer@jelmer.uk-20190603234808-15yk5c7054tj8e2b
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
import os
24
24
import pprint
25
25
 
26
 
from ... import (
 
26
from .. import (
27
27
    cache_utf8,
28
28
    osutils,
29
29
    timestamp,
30
30
    )
31
31
from . import apply_bundle
32
 
from ...errors import (
 
32
from ..errors import (
33
33
    TestamentMismatch,
34
34
    BzrError,
35
 
    NoSuchId,
36
35
    )
37
 
from ..inventory import (
 
36
from ..bzr.inventory import (
38
37
    Inventory,
39
38
    InventoryDirectory,
40
39
    InventoryFile,
41
40
    InventoryLink,
42
41
    )
43
 
from ...osutils import sha_string, sha_strings, pathjoin
44
 
from ...revision import Revision, NULL_REVISION
45
 
from ...sixish import (
 
42
from ..osutils import sha_string, pathjoin
 
43
from ..revision import Revision, NULL_REVISION
 
44
from ..sixish import (
46
45
    viewitems,
47
46
    )
48
 
from ..testament import StrictTestament
49
 
from ...trace import mutter, warning
50
 
from ...tree import (
51
 
    InterTree,
52
 
    Tree,
53
 
    )
54
 
from ..xml5 import serializer_v5
 
47
from ..bzr.testament import StrictTestament
 
48
from ..trace import mutter, warning
 
49
from ..tree import Tree
 
50
from ..bzr.xml5 import serializer_v5
55
51
 
56
52
 
57
53
class RevisionInfo(object):
286
282
        so build up an inventory, and make sure the hashes match.
287
283
        """
288
284
        # Now we should have a complete inventory entry.
289
 
        cs = serializer_v5.write_inventory_to_chunks(inv)
290
 
        sha1 = sha_strings(cs)
 
285
        s = serializer_v5.write_inventory_to_string(inv)
 
286
        sha1 = sha_string(s)
291
287
        # Target revision is the last entry in the real_revisions list
292
288
        rev = self.get_revision(revision_id)
293
289
        if rev.revision_id != revision_id:
294
290
            raise AssertionError()
295
291
        if sha1 != rev.inventory_sha1:
296
292
            with open(',,bogus-inv', 'wb') as f:
297
 
                f.writelines(cs)
 
293
                f.write(s)
298
294
            warning('Inventory sha hash mismatch for revision %s. %s'
299
295
                    ' != %s' % (revision_id, sha1, rev.inventory_sha1))
300
296
 
301
 
    def _testament(self, revision, tree):
302
 
        raise NotImplementedError(self._testament)
303
 
 
304
297
    def _validate_revision(self, tree, revision_id):
305
298
        """Make sure all revision entries match their checksum."""
306
299
 
313
306
            raise AssertionError()
314
307
        if not (rev.revision_id == revision_id):
315
308
            raise AssertionError()
316
 
        testament = self._testament(rev, tree)
317
 
        sha1 = testament.as_sha1()
 
309
        sha1 = self._testament_sha1(rev, tree)
318
310
        if sha1 != rev_info.sha1:
319
311
            raise TestamentMismatch(rev.revision_id, rev_info.sha1, sha1)
320
312
        if rev.revision_id in rev_to_sha1:
490
482
        self.patches = {}
491
483
        self._targets = {}  # new path => new symlink target
492
484
        self.deleted = []
 
485
        self.contents_by_id = True
493
486
        self.revision_id = revision_id
494
487
        self._inventory = None
495
 
        self._base_inter = InterTree.get(self.base_tree, self)
496
488
 
497
489
    def __str__(self):
498
490
        return pprint.pformat(self.__dict__)
587
579
            return None
588
580
        return new_path
589
581
 
 
582
    def get_root_id(self):
 
583
        return self.path2id('')
 
584
 
590
585
    def path2id(self, path):
591
586
        """Return the id of the file present at path in the target tree."""
592
587
        file_id = self._new_id.get(path)
599
594
            return None
600
595
        return self.base_tree.path2id(old_path)
601
596
 
602
 
    def id2path(self, file_id, recurse='down'):
 
597
    def id2path(self, file_id):
603
598
        """Return the new path in the target tree of the file with id file_id"""
604
599
        path = self._new_id_r.get(file_id)
605
600
        if path is not None:
606
601
            return path
607
 
        old_path = self.base_tree.id2path(file_id, recurse)
 
602
        old_path = self.base_tree.id2path(file_id)
608
603
        if old_path is None:
609
 
            raise NoSuchId(file_id, self)
 
604
            return None
610
605
        if old_path in self.deleted:
611
 
            raise NoSuchId(file_id, self)
612
 
        new_path = self.new_path(old_path)
613
 
        if new_path is None:
614
 
            raise NoSuchId(file_id, self)
615
 
        return new_path
 
606
            return None
 
607
        return self.new_path(old_path)
 
608
 
 
609
    def old_contents_id(self, file_id):
 
610
        """Return the id in the base_tree for the given file_id.
 
611
        Return None if the file did not exist in base.
 
612
        """
 
613
        if self.contents_by_id:
 
614
            if self.base_tree.has_id(file_id):
 
615
                return file_id
 
616
            else:
 
617
                return None
 
618
        new_path = self.id2path(file_id)
 
619
        return self.base_tree.path2id(new_path)
616
620
 
617
621
    def get_file(self, path):
618
622
        """Return a file-like object containing the new contents of the
622
626
                in the text-store, so that the file contents would
623
627
                then be cached.
624
628
        """
625
 
        old_path = self._base_inter.find_source_path(path)
626
 
        if old_path is None:
 
629
        file_id = self.path2id(path)
 
630
        base_id = self.old_contents_id(file_id)
 
631
        if (base_id is not None and
 
632
                base_id != self.base_tree.get_root_id()):
 
633
            old_path = self.base_tree.id2path(base_id)
 
634
            patch_original = self.base_tree.get_file(old_path)
 
635
        else:
627
636
            patch_original = None
628
 
        else:
629
 
            patch_original = self.base_tree.get_file(old_path)
630
637
        file_patch = self.patches.get(path)
631
638
        if file_patch is None:
632
639
            if (patch_original is None and
772
779
        for result in viewitems(self._new_id):
773
780
            paths.append(result)
774
781
        for id in self.base_tree.all_file_ids():
775
 
            try:
776
 
                path = self.id2path(id, recurse='none')
777
 
            except NoSuchId:
 
782
            path = self.id2path(id)
 
783
            if path is None:
778
784
                continue
779
785
            paths.append((path, id))
780
786
        paths.sort()