~bzr-pqm/bzr/bzr.dev

184 by mbp at sourcefrog
pychecker fixups
1
# (C) 2005 Canonical
1 by mbp at sourcefrog
import from baz patch-364
2
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.
7
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.
12
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
16
17
18
8 by mbp at sourcefrog
store committer's timezone in revision and show
19
1 by mbp at sourcefrog
import from baz patch-364
20
from xml import XMLMixin
7 by mbp at sourcefrog
depend only on regular ElementTree installation
21
22
try:
23
    from cElementTree import Element, ElementTree, SubElement
24
except ImportError:
27 by mbp at sourcefrog
- fix up use of ElementTree without cElementTree
25
    from elementtree.ElementTree import Element, ElementTree, SubElement
7 by mbp at sourcefrog
depend only on regular ElementTree installation
26
184 by mbp at sourcefrog
pychecker fixups
27
from errors import BzrError
28
1 by mbp at sourcefrog
import from baz patch-364
29
30
class Revision(XMLMixin):
31
    """Single revision on a branch.
32
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.
36
254 by Martin Pool
- Doc cleanups from Magnus Therning
37
    TODO: Perhaps make predecessor be a child element, not an attribute?
1 by mbp at sourcefrog
import from baz patch-364
38
    """
39
    def __init__(self, **args):
40
        self.inventory_id = None
672 by Martin Pool
- revision records include the hash of their inventory and
41
        self.inventory_sha1 = None
1 by mbp at sourcefrog
import from baz patch-364
42
        self.revision_id = None
43
        self.timestamp = None
44
        self.message = None
8 by mbp at sourcefrog
store committer's timezone in revision and show
45
        self.timezone = None
184 by mbp at sourcefrog
pychecker fixups
46
        self.committer = None
47
        self.precursor = None
672 by Martin Pool
- revision records include the hash of their inventory and
48
        self.precursor_sha1 = None
1 by mbp at sourcefrog
import from baz patch-364
49
        self.__dict__.update(args)
50
51
52
    def __repr__(self):
184 by mbp at sourcefrog
pychecker fixups
53
        return "<Revision id %s>" % self.revision_id
1 by mbp at sourcefrog
import from baz patch-364
54
55
        
56
    def to_element(self):
11 by mbp at sourcefrog
- change revision XML to <revision>
57
        root = Element('revision',
1 by mbp at sourcefrog
import from baz patch-364
58
                       committer = self.committer,
8 by mbp at sourcefrog
store committer's timezone in revision and show
59
                       timestamp = '%.9f' % self.timestamp,
1 by mbp at sourcefrog
import from baz patch-364
60
                       revision_id = self.revision_id,
8 by mbp at sourcefrog
store committer's timezone in revision and show
61
                       inventory_id = self.inventory_id,
672 by Martin Pool
- revision records include the hash of their inventory and
62
                       inventory_sha1 = self.inventory_sha1,
673 by Martin Pool
- cope when writing out revisions with no timezone recorded
63
                       )
64
        if self.timezone:
65
            root.set('timezone', str(self.timezone))
1 by mbp at sourcefrog
import from baz patch-364
66
        if self.precursor:
67
            root.set('precursor', self.precursor)
672 by Martin Pool
- revision records include the hash of their inventory and
68
            if self.precursor_sha1:
69
                root.set('precursor_sha1', self.precursor_sha1)
1 by mbp at sourcefrog
import from baz patch-364
70
        root.text = '\n'
71
        
72
        msg = SubElement(root, 'message')
73
        msg.text = self.message
74
        msg.tail = '\n'
75
76
        return root
77
11 by mbp at sourcefrog
- change revision XML to <revision>
78
79
    def from_element(cls, elt):
80
        # <changeset> is deprecated...
81
        if elt.tag not in ('revision', 'changeset'):
184 by mbp at sourcefrog
pychecker fixups
82
            raise BzrError("unexpected tag in revision file: %r" % elt)
11 by mbp at sourcefrog
- change revision XML to <revision>
83
84
        cs = cls(committer = elt.get('committer'),
85
                 timestamp = float(elt.get('timestamp')),
86
                 precursor = elt.get('precursor'),
672 by Martin Pool
- revision records include the hash of their inventory and
87
                 precursor_sha1 = elt.get('precursor_sha1'),
11 by mbp at sourcefrog
- change revision XML to <revision>
88
                 revision_id = elt.get('revision_id'),
672 by Martin Pool
- revision records include the hash of their inventory and
89
                 inventory_id = elt.get('inventory_id'),
90
                 inventory_sha1 = elt.get('inventory_sha1')
91
                 )
11 by mbp at sourcefrog
- change revision XML to <revision>
92
93
        v = elt.get('timezone')
8 by mbp at sourcefrog
store committer's timezone in revision and show
94
        cs.timezone = v and int(v)
95
11 by mbp at sourcefrog
- change revision XML to <revision>
96
        cs.message = elt.findtext('message') # text of <message>
1 by mbp at sourcefrog
import from baz patch-364
97
        return cs
98
99
    from_element = classmethod(from_element)
100