/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/revision.py

Fix formatting, remove catch-all for exceptions when opening local repositories.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# (C) 2005 Canonical
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
 
 
19
 
 
20
 
from xml import XMLMixin
21
 
 
22
 
try:
23
 
    from cElementTree import Element, ElementTree, SubElement
24
 
except ImportError:
25
 
    from elementtree.ElementTree import Element, ElementTree, SubElement
26
 
 
27
 
from errors import BzrError
28
 
 
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
 
 
37
 
    TODO: Perhaps make predecessor be a child element, not an attribute?
38
 
    """
39
 
    def __init__(self, **args):
40
 
        self.inventory_id = None
41
 
        self.inventory_sha1 = None
42
 
        self.revision_id = None
43
 
        self.timestamp = None
44
 
        self.message = None
45
 
        self.timezone = None
46
 
        self.committer = None
47
 
        self.precursor = None
48
 
        self.precursor_sha1 = None
49
 
        self.__dict__.update(args)
50
 
 
51
 
 
52
 
    def __repr__(self):
53
 
        return "<Revision id %s>" % self.revision_id
54
 
 
55
 
        
56
 
    def to_element(self):
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,
63
 
                       )
64
 
        if self.timezone:
65
 
            root.set('timezone', str(self.timezone))
66
 
        if self.precursor:
67
 
            root.set('precursor', self.precursor)
68
 
            if self.precursor_sha1:
69
 
                root.set('precursor_sha1', self.precursor_sha1)
70
 
        root.text = '\n'
71
 
        
72
 
        msg = SubElement(root, 'message')
73
 
        msg.text = self.message
74
 
        msg.tail = '\n'
75
 
 
76
 
        return root
77
 
 
78
 
 
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)
83
 
 
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')
91
 
                 )
92
 
 
93
 
        v = elt.get('timezone')
94
 
        cs.timezone = v and int(v)
95
 
 
96
 
        cs.message = elt.findtext('message') # text of <message>
97
 
        return cs
98
 
 
99
 
    from_element = classmethod(from_element)
100