~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bundle/bundle_data.py

  • Committer: Robert Collins
  • Date: 2007-07-04 08:08:13 UTC
  • mfrom: (2572 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2587.
  • Revision ID: robertc@robertcollins.net-20070704080813-wzebx0r88fvwj5rq
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 by Canonical Ltd
 
1
# Copyright (C) 2006 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
21
21
import os
22
22
import pprint
23
23
 
 
24
from bzrlib import (
 
25
    osutils,
 
26
    )
24
27
import bzrlib.errors
 
28
from bzrlib.bundle import apply_bundle
25
29
from bzrlib.errors import (TestamentMismatch, BzrError, 
26
30
                           MalformedHeader, MalformedPatches, NotABundle)
27
31
from bzrlib.inventory import (Inventory, InventoryEntry,
72
76
        if self.properties:
73
77
            for property in self.properties:
74
78
                key_end = property.find(': ')
75
 
                assert key_end is not None
76
 
                key = property[:key_end].encode('utf-8')
77
 
                value = property[key_end+2:].encode('utf-8')
 
79
                if key_end == -1:
 
80
                    assert property.endswith(':')
 
81
                    key = str(property[:-1])
 
82
                    value = ''
 
83
                else:
 
84
                    key = str(property[:key_end])
 
85
                    value = property[key_end+2:]
78
86
                rev.properties[key] = value
79
87
 
80
88
        return rev
101
109
        self.timestamp = None
102
110
        self.timezone = None
103
111
 
 
112
        # Have we checked the repository yet?
 
113
        self._validated_revisions_against_repo = False
 
114
 
104
115
    def __str__(self):
105
116
        return pprint.pformat(self.__dict__)
106
117
 
109
120
        split up, based on the assumptions that can be made
110
121
        when information is missing.
111
122
        """
112
 
        from bzrlib.bundle.serializer import unpack_highres_date
 
123
        from bzrlib.timestamp import unpack_highres_date
113
124
        # Put in all of the guessable information.
114
125
        if not self.timestamp and self.date:
115
126
            self.timestamp, self.timezone = unpack_highres_date(self.date)
168
179
        raise KeyError(revision_id)
169
180
 
170
181
    def revision_tree(self, repository, revision_id, base=None):
 
182
        revision_id = osutils.safe_revision_id(revision_id)
171
183
        revision = self.get_revision(revision_id)
172
184
        base = self.get_base(revision)
173
185
        assert base != revision_id
174
 
        self._validate_references_from_repository(repository)
 
186
        if not self._validated_revisions_against_repo:
 
187
            self._validate_references_from_repository(repository)
175
188
        revision_info = self.get_revision_info(revision_id)
176
189
        inventory_revision_id = revision_id
177
190
        bundle_tree = BundleTree(repository.revision_tree(base), 
253
266
            warning('Not all revision hashes could be validated.'
254
267
                    ' Unable validate %d hashes' % len(missing))
255
268
        mutter('Verified %d sha hashes for the bundle.' % count)
 
269
        self._validated_revisions_against_repo = True
256
270
 
257
271
    def _validate_inventory(self, inv, revision_id):
258
272
        """At this point we should have generated the BundleTree,
299
313
 
300
314
        def get_rev_id(last_changed, path, kind):
301
315
            if last_changed is not None:
302
 
                changed_revision_id = last_changed.decode('utf-8')
 
316
                # last_changed will be a Unicode string because of how it was
 
317
                # read. Convert it back to utf8.
 
318
                changed_revision_id = osutils.safe_revision_id(last_changed,
 
319
                                                               warn=False)
303
320
            else:
304
321
                changed_revision_id = revision_id
305
322
            bundle_tree.note_last_changed(path, changed_revision_id)
372
389
            if not info[1].startswith('file-id:'):
373
390
                raise BzrError('The file-id should follow the path for an add'
374
391
                        ': %r' % extra)
375
 
            file_id = info[1][8:]
 
392
            # This will be Unicode because of how the stream is read. Turn it
 
393
            # back into a utf8 file_id
 
394
            file_id = osutils.safe_file_id(info[1][8:], warn=False)
376
395
 
377
396
            bundle_tree.note_id(file_id, path, kind)
378
397
            # this will be overridden in extra_info if executable is specified.
423
442
                        ' (unrecognized action): %r' % action_line)
424
443
            valid_actions[action](kind, extra, lines)
425
444
 
 
445
    def install_revisions(self, target_repo):
 
446
        """Install revisions and return the target revision"""
 
447
        apply_bundle.install_bundle(target_repo, self)
 
448
        return self.target
 
449
 
426
450
 
427
451
class BundleTree(Tree):
428
452
    def __init__(self, base_tree, revision_id):
648
672
 
649
673
        assert self.base_tree is not None
650
674
        base_inv = self.base_tree.inventory
651
 
        root_id = base_inv.root.file_id
652
 
        try:
653
 
            # New inventories have a unique root_id
654
 
            inv = Inventory(root_id, self.revision_id)
655
 
        except TypeError:
656
 
            inv = Inventory(revision_id=self.revision_id)
657
 
        inv.root.revision = self.get_last_changed(root_id)
 
675
        inv = Inventory(None, self.revision_id)
658
676
 
659
677
        def add_entry(file_id):
660
678
            path = self.id2path(file_id)
661
679
            if path is None:
662
680
                return
663
 
            parent_path = dirname(path)
664
 
            if parent_path == u'':
665
 
                parent_id = root_id
 
681
            if path == '':
 
682
                parent_id = None
666
683
            else:
 
684
                parent_path = dirname(path)
667
685
                parent_id = self.path2id(parent_path)
668
686
 
669
687
            kind = self.get_kind(file_id)
690
708
 
691
709
        sorted_entries = self.sorted_path_id()
692
710
        for path, file_id in sorted_entries:
693
 
            if file_id == inv.root.file_id:
694
 
                continue
695
711
            add_entry(file_id)
696
712
 
697
713
        return inv