~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revision.py

  • Committer: Aaron Bentley
  • Date: 2005-09-12 13:48:32 UTC
  • mfrom: (1185.3.4)
  • mto: (1185.1.16)
  • mto: This revision was merged to the branch mainline in revision 1390.
  • Revision ID: abentley@panoramicfeedback.com-20050912134832-c23db11dc63170b6
Merged from mpool

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
    def __repr__(self):
71
71
        return "<Revision id %s>" % self.revision_id
72
72
 
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
 
 
 
73
    def __eq__(self, other):
 
74
        if not isinstance(other, Revision):
 
75
            return False
 
76
        return (self.inventory_id == other.inventory_id
 
77
                and self.inventory_sha1 == other.inventory_sha1
 
78
                and self.revision_id == other.revision_id
 
79
                and self.timestamp == other.timestamp
 
80
                and self.message == other.message
 
81
                and self.timezone == other.timezone
 
82
                and self.committer == other.committer)
 
83
 
 
84
    def __ne__(self, other):
 
85
        return not self.__eq__(other)
 
86
 
 
87
        
157
88
 
158
89
REVISION_ID_RE = None
159
90