~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-05-07 16:48:14 UTC
  • mto: This revision was merged to the branch mainline in revision 2485.
  • Revision ID: robertc@robertcollins.net-20070507164814-wpagonutf4b5cf8s
Move HACKING to docs/developers/HACKING and adjust Makefile to accomodate this.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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):