1
# Copyright (C) 2005-2011 Canonical Ltd
1
# Copyright (C) 2005, 2006 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 bugtracker
25
21
from bzrlib import (
29
25
from bzrlib.osutils import contains_whitespace
26
from bzrlib.progress import DummyProgress
31
28
NULL_REVISION="null:"
32
29
CURRENT_REVISION="current:"
48
45
Dictionary of revision properties. These are attached to the
49
revision as extra metadata. The name must be a single
46
revision as extra metadata. The name must be a single
50
47
word; the value can be an arbitrary string.
53
50
def __init__(self, revision_id, properties=None, **args):
54
51
self.revision_id = revision_id
55
if properties is None:
58
self.properties = properties
59
self._check_properties()
52
self.properties = properties or {}
53
self._check_properties()
61
54
self.parent_ids = []
62
55
self.parent_sha1s = []
63
56
"""Not used anymore - legacy from for 4."""
69
62
def __eq__(self, other):
70
63
if not isinstance(other, Revision):
65
# FIXME: rbc 20050930 parent_ids are not being compared
73
67
self.inventory_sha1 == other.inventory_sha1
74
68
and self.revision_id == other.revision_id
76
70
and self.message == other.message
77
71
and self.timezone == other.timezone
78
72
and self.committer == other.committer
79
and self.properties == other.properties
80
and self.parent_ids == other.parent_ids)
73
and self.properties == other.properties)
82
75
def __ne__(self, other):
83
76
return not self.__eq__(other)
88
81
if not isinstance(name, basestring) or contains_whitespace(name):
89
82
raise ValueError("invalid property name %r" % name)
90
83
if not isinstance(value, basestring):
91
raise ValueError("invalid property value %r for %r" %
84
raise ValueError("invalid property value %r for %r" %
94
87
def get_history(self, repository):
95
88
"""Return the canonical line-of-history for this revision.
113
106
def get_summary(self):
114
107
"""Get the first line of the log message for this revision.
116
Return an empty string if message is None.
119
return self.message.lstrip().split('\n', 1)[0]
123
def get_apparent_authors(self):
124
"""Return the apparent authors of this revision.
126
If the revision properties contain the names of the authors,
127
return them. Otherwise return the committer name.
129
The return value will be a list containing at least one element.
131
authors = self.properties.get('authors', None)
133
author = self.properties.get('author', self.committer)
138
return authors.split("\n")
141
"""Iterate over the bugs associated with this revision."""
142
bug_property = self.properties.get('bugs', None)
143
if bug_property is None:
145
for line in bug_property.splitlines():
147
url, status = line.split(None, 2)
149
raise errors.InvalidLineInBugsProperty(line)
150
if status not in bugtracker.ALLOWED_BUG_STATUSES:
151
raise errors.InvalidBugStatus(status)
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)
155
120
def iter_ancestors(revision_id, revision_source, only_present=False):
188
153
if anc_id not in found_ancestors:
189
154
found_ancestors[anc_id] = (anc_order, anc_distance)
190
155
return found_ancestors
193
158
def __get_closest(intersection):
194
159
intersection.sort()
196
161
for entry in intersection:
197
162
if entry[0] == intersection[0][0]:
198
163
matches.append(entry[2])
202
167
def is_reserved_id(revision_id):
203
168
"""Determine whether a revision id is reserved
205
:return: True if the revision is reserved, False otherwise
170
:return: True if the revision is is reserved, False otherwise
207
172
return isinstance(revision_id, basestring) and revision_id.endswith(':')