~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-11 00:23:23 UTC
  • mfrom: (2070 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2071.
  • Revision ID: john@arbash-meinel.com-20061011002323-82ba88c293d7caff
[merge] bzr.dev 2070

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
 
1
# Copyright (C) 2006 by 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
 
    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)
197
171
        revision = self.get_revision(revision_id)
198
172
        base = self.get_base(revision)
199
173
        assert base != revision_id
200
 
        if not self._validated_revisions_against_repo:
201
 
            self._validate_references_from_repository(repository)
 
174
        self._validate_references_from_repository(repository)
202
175
        revision_info = self.get_revision_info(revision_id)
203
176
        inventory_revision_id = revision_id
204
177
        bundle_tree = BundleTree(repository.revision_tree(base), 
280
253
            warning('Not all revision hashes could be validated.'
281
254
                    ' Unable validate %d hashes' % len(missing))
282
255
        mutter('Verified %d sha hashes for the bundle.' % count)
283
 
        self._validated_revisions_against_repo = True
284
256
 
285
257
    def _validate_inventory(self, inv, revision_id):
286
258
        """At this point we should have generated the BundleTree,
327
299
 
328
300
        def get_rev_id(last_changed, path, kind):
329
301
            if last_changed is not None:
330
 
                # last_changed will be a Unicode string because of how it was
331
 
                # read. Convert it back to utf8.
332
 
                changed_revision_id = osutils.safe_revision_id(last_changed,
333
 
                                                               warn=False)
 
302
                changed_revision_id = last_changed.decode('utf-8')
334
303
            else:
335
304
                changed_revision_id = revision_id
336
305
            bundle_tree.note_last_changed(path, changed_revision_id)
403
372
            if not info[1].startswith('file-id:'):
404
373
                raise BzrError('The file-id should follow the path for an add'
405
374
                        ': %r' % extra)
406
 
            # This will be Unicode because of how the stream is read. Turn it
407
 
            # back into a utf8 file_id
408
 
            file_id = osutils.safe_file_id(info[1][8:], warn=False)
 
375
            file_id = info[1][8:]
409
376
 
410
377
            bundle_tree.note_id(file_id, path, kind)
411
378
            # this will be overridden in extra_info if executable is specified.
456
423
                        ' (unrecognized action): %r' % action_line)
457
424
            valid_actions[action](kind, extra, lines)
458
425
 
459
 
    def install_revisions(self, target_repo, stream_input=True):
460
 
        """Install revisions and return the target revision
461
 
 
462
 
        :param target_repo: The repository to install into
463
 
        :param stream_input: Ignored by this implementation.
464
 
        """
465
 
        apply_bundle.install_bundle(target_repo, self)
466
 
        return self.target
467
 
 
468
 
    def get_merge_request(self, target_repo):
469
 
        """Provide data for performing a merge
470
 
 
471
 
        Returns suggested base, suggested target, and patch verification status
472
 
        """
473
 
        return None, self.target, 'inapplicable'
474
 
 
475
426
 
476
427
class BundleTree(Tree):
477
428
    def __init__(self, base_tree, revision_id):
697
648
 
698
649
        assert self.base_tree is not None
699
650
        base_inv = self.base_tree.inventory
700
 
        inv = Inventory(None, self.revision_id)
 
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)
701
658
 
702
659
        def add_entry(file_id):
703
660
            path = self.id2path(file_id)
704
661
            if path is None:
705
662
                return
706
 
            if path == '':
707
 
                parent_id = None
 
663
            parent_path = dirname(path)
 
664
            if parent_path == u'':
 
665
                parent_id = root_id
708
666
            else:
709
 
                parent_path = dirname(path)
710
667
                parent_id = self.path2id(parent_path)
711
668
 
712
669
            kind = self.get_kind(file_id)
733
690
 
734
691
        sorted_entries = self.sorted_path_id()
735
692
        for path, file_id in sorted_entries:
 
693
            if file_id == inv.root.file_id:
 
694
                continue
736
695
            add_entry(file_id)
737
696
 
738
697
        return inv