3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
from xml import XMLMixin
23
from cElementTree import Element, ElementTree, SubElement
25
from elementtree.ElementTree import Element, ElementTree, SubElement
27
from errors import BzrError
30
class Revision(XMLMixin):
31
"""Single revision on a branch.
33
Revisions may know their revision_hash, but only once they've been
34
written out. This is not stored because you cannot write the hash
35
into the file it describes.
37
TODO: Perhaps make predecessor be a child element, not an attribute?
39
def __init__(self, **args):
40
self.inventory_id = None
41
self.inventory_sha1 = None
42
self.revision_id = None
48
self.precursor_sha1 = None
49
self.__dict__.update(args)
53
return "<Revision id %s>" % self.revision_id
57
root = Element('revision',
58
committer = self.committer,
59
timestamp = '%.9f' % self.timestamp,
60
revision_id = self.revision_id,
61
inventory_id = self.inventory_id,
62
inventory_sha1 = self.inventory_sha1,
65
root.set('timezone', str(self.timezone))
67
root.set('precursor', self.precursor)
68
if self.precursor_sha1:
69
root.set('precursor_sha1', self.precursor_sha1)
72
msg = SubElement(root, 'message')
73
msg.text = self.message
79
def from_element(cls, elt):
80
# <changeset> is deprecated...
81
if elt.tag not in ('revision', 'changeset'):
82
raise BzrError("unexpected tag in revision file: %r" % elt)
84
cs = cls(committer = elt.get('committer'),
85
timestamp = float(elt.get('timestamp')),
86
precursor = elt.get('precursor'),
87
precursor_sha1 = elt.get('precursor_sha1'),
88
revision_id = elt.get('revision_id'),
89
inventory_id = elt.get('inventory_id'),
90
inventory_sha1 = elt.get('inventory_sha1')
93
v = elt.get('timezone')
94
cs.timezone = v and int(v)
96
cs.message = elt.findtext('message') # text of <message>
99
from_element = classmethod(from_element)