~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revision.py

  • Committer: Robert Collins
  • Date: 2005-10-19 10:11:57 UTC
  • mfrom: (1185.16.78)
  • mto: This revision was merged to the branch mainline in revision 1470.
  • Revision ID: robertc@robertcollins.net-20051019101157-17438d311e746b4f
mergeĀ fromĀ upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
 
17
# TODO: Some kind of command-line display of revision properties: 
 
18
# perhaps show them in log -v and allow them as options to the commit command.
17
19
 
18
20
import bzrlib.errors
19
21
from bzrlib.graph import node_distances, select_farthest, all_descendants
 
22
from bzrlib.osutils import contains_whitespace
20
23
 
21
24
NULL_REVISION="null:"
22
25
 
31
34
 
32
35
    parent_ids
33
36
        List of parent revision_ids
 
37
 
 
38
    properties
 
39
        Dictionary of revision properties.  These are attached to the
 
40
        revision as extra metadata.  The name must be a single 
 
41
        word; the value can be an arbitrary string.
34
42
    """
35
43
    
36
 
    def __init__(self, revision_id, **args):
 
44
    def __init__(self, revision_id, properties=None, **args):
37
45
        self.revision_id = revision_id
 
46
        self.properties = properties or {}
 
47
        self._check_properties()
38
48
        self.__dict__.update(args)
39
49
        self.parent_ids = []
40
50
        self.parent_sha1s = []
52
62
                and self.timestamp == other.timestamp
53
63
                and self.message == other.message
54
64
                and self.timezone == other.timezone
55
 
                and self.committer == other.committer)
 
65
                and self.committer == other.committer
 
66
                and self.properties == other.properties)
56
67
 
57
68
    def __ne__(self, other):
58
69
        return not self.__eq__(other)
59
70
 
60
 
        
61
 
REVISION_ID_RE = None
62
 
 
63
 
def validate_revision_id(rid):
64
 
    """Check rid is syntactically valid for a revision id."""
65
 
    global REVISION_ID_RE
66
 
    if not REVISION_ID_RE:
67
 
        import re
68
 
        REVISION_ID_RE = re.compile('[\w:.-]+@[\w%.-]+--?[\w]+--?[0-9a-f]+\Z')
69
 
 
70
 
    if not REVISION_ID_RE.match(rid):
71
 
        raise ValueError("malformed revision-id %r" % rid)
 
71
    def _check_properties(self):
 
72
        """Verify that all revision properties are OK.
 
73
        """
 
74
        for name, value in self.properties.iteritems():
 
75
            if not isinstance(name, basestring) or contains_whitespace(name):
 
76
                raise ValueError("invalid property name %r" % name)
 
77
            if not isinstance(value, basestring):
 
78
                raise ValueError("invalid property value %r for %r" % 
 
79
                                 (name, value))
72
80
 
73
81
 
74
82
def is_ancestor(revision_id, candidate_id, branch):