~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revision.py

- constraints on revprops
- tests for this

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
import bzrlib.errors
19
19
from bzrlib.graph import node_distances, select_farthest, all_descendants
 
20
from bzrlib.osutils import contains_whitespace
20
21
 
21
22
NULL_REVISION="null:"
22
23
 
31
32
 
32
33
    parent_ids
33
34
        List of parent revision_ids
 
35
 
 
36
    properties
 
37
        Dictionary of revision properties.  These are attached to the
 
38
        revision as extra metadata.  The name must be a single 
 
39
        word; the value can be an arbitrary string.
34
40
    """
35
41
    
36
42
    def __init__(self, revision_id, properties=None, **args):
37
43
        self.revision_id = revision_id
38
44
        self.properties = properties or {}
 
45
        self._check_properties()
39
46
        self.__dict__.update(args)
40
47
        self.parent_ids = []
41
48
        self.parent_sha1s = []
59
66
    def __ne__(self, other):
60
67
        return not self.__eq__(other)
61
68
 
 
69
    def _check_properties(self):
 
70
        """Verify that all revision properties are OK.
 
71
        """
 
72
        for name, value in self.properties.iteritems():
 
73
            if not isinstance(name, basestring) or contains_whitespace(name):
 
74
                raise ValueError("invalid property name %r" % name)
 
75
            if not isinstance(value, basestring):
 
76
                raise ValueError("invalid property value %r for %r" % 
 
77
                                 (name, value))
 
78
 
62
79
 
63
80
def is_ancestor(revision_id, candidate_id, branch):
64
81
    """Return true if candidate_id is an ancestor of revision_id.