1
# Copyright (C) 2005, 2006 Canonical Ltd
1
# Copyright (C) 2005-2011 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
13
13
# You should have received a copy of the GNU General Public License
14
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
17
# TODO: Some kind of command-line display of revision properties:
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
from __future__ import absolute_import
19
# TODO: Some kind of command-line display of revision properties:
18
20
# perhaps show them in log -v and allow them as options to the commit command.
23
from bzrlib.lazy_import import lazy_import
24
lazy_import(globals(), """
25
from bzrlib import bugtracker
21
27
from bzrlib import (
25
31
from bzrlib.osutils import contains_whitespace
26
from bzrlib.progress import DummyProgress
28
33
NULL_REVISION="null:"
29
34
CURRENT_REVISION="current:"
45
50
Dictionary of revision properties. These are attached to the
46
revision as extra metadata. The name must be a single
51
revision as extra metadata. The name must be a single
47
52
word; the value can be an arbitrary string.
50
55
def __init__(self, revision_id, properties=None, **args):
51
56
self.revision_id = revision_id
52
self.properties = properties or {}
53
self._check_properties()
57
if properties is None:
60
self.properties = properties
61
self._check_properties()
54
63
self.parent_ids = []
55
64
self.parent_sha1s = []
56
65
"""Not used anymore - legacy from for 4."""
62
71
def __eq__(self, other):
63
72
if not isinstance(other, Revision):
65
# FIXME: rbc 20050930 parent_ids are not being compared
67
75
self.inventory_sha1 == other.inventory_sha1
68
76
and self.revision_id == other.revision_id
70
78
and self.message == other.message
71
79
and self.timezone == other.timezone
72
80
and self.committer == other.committer
73
and self.properties == other.properties)
81
and self.properties == other.properties
82
and self.parent_ids == other.parent_ids)
75
84
def __ne__(self, other):
76
85
return not self.__eq__(other)
81
90
if not isinstance(name, basestring) or contains_whitespace(name):
82
91
raise ValueError("invalid property name %r" % name)
83
92
if not isinstance(value, basestring):
84
raise ValueError("invalid property value %r for %r" %
93
raise ValueError("invalid property value %r for %r" %
87
96
def get_history(self, repository):
88
97
"""Return the canonical line-of-history for this revision.
106
115
def get_summary(self):
107
116
"""Get the first line of the log message for this revision.
109
return self.message.lstrip().split('\n', 1)[0]
111
def get_apparent_author(self):
112
"""Return the apparent author of this revision.
114
If the revision properties contain the author name,
115
return it. Otherwise return the committer name.
117
return self.properties.get('author', self.committer)
118
Return an empty string if message is None.
121
return self.message.lstrip().split('\n', 1)[0]
125
def get_apparent_authors(self):
126
"""Return the apparent authors of this revision.
128
If the revision properties contain the names of the authors,
129
return them. Otherwise return the committer name.
131
The return value will be a list containing at least one element.
133
authors = self.properties.get('authors', None)
135
author = self.properties.get('author', self.committer)
140
return authors.split("\n")
143
"""Iterate over the bugs associated with this revision."""
144
bug_property = self.properties.get('bugs', None)
145
if bug_property is None:
147
for line in bug_property.splitlines():
149
url, status = line.split(None, 2)
151
raise errors.InvalidLineInBugsProperty(line)
152
if status not in bugtracker.ALLOWED_BUG_STATUSES:
153
raise errors.InvalidBugStatus(status)
120
157
def iter_ancestors(revision_id, revision_source, only_present=False):
153
190
if anc_id not in found_ancestors:
154
191
found_ancestors[anc_id] = (anc_order, anc_distance)
155
192
return found_ancestors
158
195
def __get_closest(intersection):
159
196
intersection.sort()
161
198
for entry in intersection:
162
199
if entry[0] == intersection[0][0]:
163
200
matches.append(entry[2])
167
204
def is_reserved_id(revision_id):
168
205
"""Determine whether a revision id is reserved
170
:return: True if the revision is is reserved, False otherwise
207
:return: True if the revision is reserved, False otherwise
172
209
return isinstance(revision_id, basestring) and revision_id.endswith(':')