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
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
# TODO: Some kind of command-line display of revision properties:
17
# TODO: Some kind of command-line display of revision properties:
18
18
# perhaps show them in log -v and allow them as options to the commit command.
21
from bzrlib.lazy_import import lazy_import
22
lazy_import(globals(), """
23
from bzrlib import deprecated_graph
24
from bzrlib import bugtracker
21
26
from bzrlib import (
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
57
self.properties = properties or {}
53
58
self._check_properties()
54
60
self.parent_ids = []
55
61
self.parent_sha1s = []
56
62
"""Not used anymore - legacy from for 4."""
62
68
def __eq__(self, other):
63
69
if not isinstance(other, Revision):
65
# FIXME: rbc 20050930 parent_ids are not being compared
67
72
self.inventory_sha1 == other.inventory_sha1
68
73
and self.revision_id == other.revision_id
70
75
and self.message == other.message
71
76
and self.timezone == other.timezone
72
77
and self.committer == other.committer
73
and self.properties == other.properties)
78
and self.properties == other.properties
79
and self.parent_ids == other.parent_ids)
75
81
def __ne__(self, other):
76
82
return not self.__eq__(other)
81
87
if not isinstance(name, basestring) or contains_whitespace(name):
82
88
raise ValueError("invalid property name %r" % name)
83
89
if not isinstance(value, basestring):
84
raise ValueError("invalid property value %r for %r" %
90
raise ValueError("invalid property value %r for %r" %
87
93
def get_history(self, repository):
88
94
"""Return the canonical line-of-history for this revision.
106
112
def get_summary(self):
107
113
"""Get the first line of the log message for this revision.
115
Return an empty string if message is None.
109
return self.message.lstrip().split('\n', 1)[0]
118
return self.message.lstrip().split('\n', 1)[0]
122
@symbol_versioning.deprecated_method(symbol_versioning.deprecated_in((1, 13, 0)))
111
123
def get_apparent_author(self):
112
124
"""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)
126
This method is deprecated in favour of get_apparent_authors.
128
If the revision properties contain any author names,
129
return the first. Otherwise return the committer name.
131
authors = self.get_apparent_authors()
137
def get_apparent_authors(self):
138
"""Return the apparent authors of this revision.
140
If the revision properties contain the names of the authors,
141
return them. Otherwise return the committer name.
143
The return value will be a list containing at least one element.
145
authors = self.properties.get('authors', None)
147
author = self.properties.get('author', self.committer)
152
return authors.split("\n")
155
"""Iterate over the bugs associated with this revision."""
156
bug_property = self.properties.get('bugs', None)
157
if bug_property is None:
159
for line in bug_property.splitlines():
161
url, status = line.split(None, 2)
163
raise errors.InvalidLineInBugsProperty(line)
164
if status not in bugtracker.ALLOWED_BUG_STATUSES:
165
raise errors.InvalidBugStatus(status)
120
169
def iter_ancestors(revision_id, revision_source, only_present=False):
153
202
if anc_id not in found_ancestors:
154
203
found_ancestors[anc_id] = (anc_order, anc_distance)
155
204
return found_ancestors
158
207
def __get_closest(intersection):
159
208
intersection.sort()
161
210
for entry in intersection:
162
211
if entry[0] == intersection[0][0]:
163
212
matches.append(entry[2])
167
216
def is_reserved_id(revision_id):
168
217
"""Determine whether a revision id is reserved
170
:return: True if the revision is is reserved, False otherwise
219
:return: True if the revision is reserved, False otherwise
172
221
return isinstance(revision_id, basestring) and revision_id.endswith(':')