~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revision.py

  • Committer: Martin Pool
  • Date: 2005-06-13 12:14:52 UTC
  • Revision ID: mbp@sourcefrog.net-20050613121452-c50982a6affa3782
- draft 'meta' command by john

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /usr/bin/env python
2
 
# -*- coding: UTF-8 -*-
 
1
# (C) 2005 Canonical
3
2
 
4
3
# This program is free software; you can redistribute it and/or modify
5
4
# it under the terms of the GNU General Public License as published by
25
24
except ImportError:
26
25
    from elementtree.ElementTree import Element, ElementTree, SubElement
27
26
 
 
27
from errors import BzrError
 
28
 
28
29
 
29
30
class Revision(XMLMixin):
30
31
    """Single revision on a branch.
33
34
    written out.  This is not stored because you cannot write the hash
34
35
    into the file it describes.
35
36
 
36
 
    :todo: Perhaps make predecessor be a child element, not an attribute?
 
37
    TODO: Perhaps make predecessor be a child element, not an attribute?
37
38
    """
38
39
    def __init__(self, **args):
39
40
        self.inventory_id = None
 
41
        self.inventory_sha1 = None
40
42
        self.revision_id = None
41
43
        self.timestamp = None
42
44
        self.message = None
43
45
        self.timezone = None
 
46
        self.committer = None
 
47
        self.precursor = None
 
48
        self.precursor_sha1 = None
44
49
        self.__dict__.update(args)
45
50
 
46
51
 
47
52
    def __repr__(self):
48
 
        if self.revision_id:
49
 
            return "<Revision id %s>" % self.revision_id
 
53
        return "<Revision id %s>" % self.revision_id
50
54
 
51
55
        
52
56
    def to_element(self):
55
59
                       timestamp = '%.9f' % self.timestamp,
56
60
                       revision_id = self.revision_id,
57
61
                       inventory_id = self.inventory_id,
58
 
                       timezone = str(self.timezone))
 
62
                       inventory_sha1 = self.inventory_sha1,
 
63
                       )
 
64
        if self.timezone:
 
65
            root.set('timezone', str(self.timezone))
59
66
        if self.precursor:
60
67
            root.set('precursor', self.precursor)
 
68
            if self.precursor_sha1:
 
69
                root.set('precursor_sha1', self.precursor_sha1)
61
70
        root.text = '\n'
62
71
        
63
72
        msg = SubElement(root, 'message')
70
79
    def from_element(cls, elt):
71
80
        # <changeset> is deprecated...
72
81
        if elt.tag not in ('revision', 'changeset'):
73
 
            bailout("unexpected tag in revision file: %r" % elt)
 
82
            raise BzrError("unexpected tag in revision file: %r" % elt)
74
83
 
75
84
        cs = cls(committer = elt.get('committer'),
76
85
                 timestamp = float(elt.get('timestamp')),
77
86
                 precursor = elt.get('precursor'),
 
87
                 precursor_sha1 = elt.get('precursor_sha1'),
78
88
                 revision_id = elt.get('revision_id'),
79
 
                 inventory_id = elt.get('inventory_id'))
 
89
                 inventory_id = elt.get('inventory_id'),
 
90
                 inventory_sha1 = elt.get('inventory_sha1')
 
91
                 )
80
92
 
81
93
        v = elt.get('timezone')
82
94
        cs.timezone = v and int(v)