~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revision.py

  • Committer: Martin Pool
  • Date: 2005-09-05 09:27:11 UTC
  • Revision ID: mbp@sourcefrog.net-20050905092711-f9f5bded3fd82605
- more disentangling of xml storage format from objects

- remove pack_xml and unpack_xml function in favor of 
  serializer object

- test unpacking canned revision xml

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
        return "<Revision id %s>" % self.revision_id
72
72
 
73
73
        
74
 
    def to_element(self):
75
 
        from bzrlib.xml import Element, SubElement
76
 
        
77
 
        root = Element('revision',
78
 
                       committer = self.committer,
79
 
                       timestamp = '%.9f' % self.timestamp,
80
 
                       revision_id = self.revision_id,
81
 
                       inventory_id = self.inventory_id,
82
 
                       inventory_sha1 = self.inventory_sha1,
83
 
                       )
84
 
        if self.timezone:
85
 
            root.set('timezone', str(self.timezone))
86
 
        root.text = '\n'
87
 
        
88
 
        msg = SubElement(root, 'message')
89
 
        msg.text = self.message
90
 
        msg.tail = '\n'
91
 
 
92
 
        if self.parents:
93
 
            pelts = SubElement(root, 'parents')
94
 
            pelts.tail = pelts.text = '\n'
95
 
            for rr in self.parents:
96
 
                assert isinstance(rr, RevisionReference)
97
 
                p = SubElement(pelts, 'revision_ref')
98
 
                p.tail = '\n'
99
 
                assert rr.revision_id
100
 
                p.set('revision_id', rr.revision_id)
101
 
                if rr.revision_sha1:
102
 
                    p.set('revision_sha1', rr.revision_sha1)
103
 
 
104
 
        return root
105
 
 
106
 
 
107
 
    def from_element(cls, elt):
108
 
        return unpack_revision(elt)
109
 
 
110
 
    from_element = classmethod(from_element)
111
 
 
112
 
 
113
 
 
114
 
def unpack_revision(elt):
115
 
    """Convert XML element into Revision object."""
116
 
    # <changeset> is deprecated...
117
 
    if elt.tag not in ('revision', 'changeset'):
118
 
        raise bzrlib.errors.BzrError("unexpected tag in revision file: %r" % elt)
119
 
 
120
 
    rev = Revision(committer = elt.get('committer'),
121
 
                   timestamp = float(elt.get('timestamp')),
122
 
                   revision_id = elt.get('revision_id'),
123
 
                   inventory_id = elt.get('inventory_id'),
124
 
                   inventory_sha1 = elt.get('inventory_sha1')
125
 
                   )
126
 
 
127
 
    precursor = elt.get('precursor')
128
 
    precursor_sha1 = elt.get('precursor_sha1')
129
 
 
130
 
    pelts = elt.find('parents')
131
 
 
132
 
    if pelts:
133
 
        for p in pelts:
134
 
            assert p.tag == 'revision_ref', \
135
 
                   "bad parent node tag %r" % p.tag
136
 
            rev_ref = RevisionReference(p.get('revision_id'),
137
 
                                        p.get('revision_sha1'))
138
 
            rev.parents.append(rev_ref)
139
 
 
140
 
        if precursor:
141
 
            # must be consistent
142
 
            prec_parent = rev.parents[0].revision_id
143
 
            assert prec_parent == precursor
144
 
    elif precursor:
145
 
        # revisions written prior to 0.0.5 have a single precursor
146
 
        # give as an attribute
147
 
        rev_ref = RevisionReference(precursor, precursor_sha1)
148
 
        rev.parents.append(rev_ref)
149
 
 
150
 
    v = elt.get('timezone')
151
 
    rev.timezone = v and int(v)
152
 
 
153
 
    rev.message = elt.findtext('message') # text of <message>
154
 
    return rev
155
 
 
156
 
 
157
74
 
158
75
REVISION_ID_RE = None
159
76