~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bundle/bundle_data.py

  • Committer: John Arbash Meinel
  • Date: 2006-10-24 14:12:53 UTC
  • mto: This revision was merged to the branch mainline in revision 2095.
  • Revision ID: john@arbash-meinel.com-20061024141253-783fba812b197b70
(John Arbash Meinel) Update version information for 0.13 development

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
 
    timestamp,
27
 
    )
28
24
import bzrlib.errors
29
 
from bzrlib.bundle import apply_bundle
30
25
from bzrlib.errors import (TestamentMismatch, BzrError, 
31
26
                           MalformedHeader, MalformedPatches, NotABundle)
32
27
from bzrlib.inventory import (Inventory, InventoryEntry,
77
72
        if self.properties:
78
73
            for property in self.properties:
79
74
                key_end = property.find(': ')
80
 
                if key_end == -1:
81
 
                    assert property.endswith(':')
82
 
                    key = str(property[:-1])
83
 
                    value = ''
84
 
                else:
85
 
                    key = str(property[:key_end])
86
 
                    value = property[key_end+2:]
 
75
                assert key_end is not None
 
76
                key = property[:key_end].encode('utf-8')
 
77
                value = property[key_end+2:].encode('utf-8')
87
78
                rev.properties[key] = value
88
79
 
89
80
        return rev
90
81
 
91
 
    @staticmethod
92
 
    def from_revision(revision):
93
 
        revision_info = RevisionInfo(revision.revision_id)
94
 
        date = timestamp.format_highres_date(revision.timestamp,
95
 
                                             revision.timezone)
96
 
        revision_info.date = date
97
 
        revision_info.timezone = revision.timezone
98
 
        revision_info.timestamp = revision.timestamp
99
 
        revision_info.message = revision.message.split('\n')
100
 
        revision_info.properties = [': '.join(p) for p in
101
 
                                    revision.properties.iteritems()]
102
 
        return revision_info
103
 
 
104
82
 
105
83
class BundleInfo(object):
106
84
    """This contains the meta information. Stuff that allows you to
107
85
    recreate the revision or inventory XML.
108
86
    """
109
 
    def __init__(self, bundle_format=None):
110
 
        self.bundle_format = None
 
87
    def __init__(self):
111
88
        self.committer = None
112
89
        self.date = None
113
90
        self.message = None
124
101
        self.timestamp = None
125
102
        self.timezone = None
126
103
 
127
 
        # Have we checked the repository yet?
128
 
        self._validated_revisions_against_repo = False
129
 
 
130
104
    def __str__(self):
131
105
        return pprint.pformat(self.__dict__)
132
106
 
135
109
        split up, based on the assumptions that can be made
136
110
        when information is missing.
137
111
        """
138
 
        from bzrlib.timestamp import unpack_highres_date
 
112
        from bzrlib.bundle.serializer import unpack_highres_date
139
113
        # Put in all of the guessable information.
140
114
        if not self.timestamp and self.date:
141
115
            self.timestamp, self.timezone = unpack_highres_date(self.date)
194
168
        raise KeyError(revision_id)
195
169
 
196
170
    def revision_tree(self, repository, revision_id, base=None):
197
 
        revision_id = osutils.safe_revision_id(revision_id)
198
171
        revision = self.get_revision(revision_id)
199
172
        base = self.get_base(revision)
200
173
        assert base != revision_id
201
 
        if not self._validated_revisions_against_repo:
202
 
            self._validate_references_from_repository(repository)
 
174
        self._validate_references_from_repository(repository)
203
175
        revision_info = self.get_revision_info(revision_id)
204
176
        inventory_revision_id = revision_id
205
177
        bundle_tree = BundleTree(repository.revision_tree(base), 
281
253
            warning('Not all revision hashes could be validated.'
282
254
                    ' Unable validate %d hashes' % len(missing))
283
255
        mutter('Verified %d sha hashes for the bundle.' % count)
284
 
        self._validated_revisions_against_repo = True
285
256
 
286
257
    def _validate_inventory(self, inv, revision_id):
287
258
        """At this point we should have generated the BundleTree,
328
299
 
329
300
        def get_rev_id(last_changed, path, kind):
330
301
            if last_changed is not None:
331
 
                # last_changed will be a Unicode string because of how it was
332
 
                # read. Convert it back to utf8.
333
 
                changed_revision_id = osutils.safe_revision_id(last_changed,
334
 
                                                               warn=False)
 
302
                changed_revision_id = last_changed.decode('utf-8')
335
303
            else:
336
304
                changed_revision_id = revision_id
337
305
            bundle_tree.note_last_changed(path, changed_revision_id)
404
372
            if not info[1].startswith('file-id:'):
405
373
                raise BzrError('The file-id should follow the path for an add'
406
374
                        ': %r' % extra)
407
 
            # This will be Unicode because of how the stream is read. Turn it
408
 
            # back into a utf8 file_id
409
 
            file_id = osutils.safe_file_id(info[1][8:], warn=False)
 
375
            file_id = info[1][8:]
410
376
 
411
377
            bundle_tree.note_id(file_id, path, kind)
412
378
            # this will be overridden in extra_info if executable is specified.
457
423
                        ' (unrecognized action): %r' % action_line)
458
424
            valid_actions[action](kind, extra, lines)
459
425
 
460
 
    def install_revisions(self, target_repo):
461
 
        """Install revisions and return the target revision"""
462
 
        apply_bundle.install_bundle(target_repo, self)
463
 
        return self.target
464
 
 
465
 
    def get_merge_request(self, target_repo):
466
 
        """Provide data for performing a merge
467
 
 
468
 
        Returns suggested base, suggested target, and patch verification status
469
 
        """
470
 
        return None, self.target, 'inapplicable'
471
 
 
472
426
 
473
427
class BundleTree(Tree):
474
428
    def __init__(self, base_tree, revision_id):