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
21
from bzrlib.lazy_import import lazy_import
22
22
lazy_import(globals(), """
23
23
from bzrlib import deprecated_graph
24
from bzrlib import bugtracker
26
25
from bzrlib import (
50
49
Dictionary of revision properties. These are attached to the
51
revision as extra metadata. The name must be a single
50
revision as extra metadata. The name must be a single
52
51
word; the value can be an arbitrary string.
55
54
def __init__(self, revision_id, properties=None, **args):
56
55
self.revision_id = revision_id
57
if properties is None:
60
self.properties = properties
61
self._check_properties()
56
self.properties = properties or {}
57
self._check_properties()
63
58
self.parent_ids = []
64
59
self.parent_sha1s = []
65
60
"""Not used anymore - legacy from for 4."""
71
66
def __eq__(self, other):
72
67
if not isinstance(other, Revision):
69
# FIXME: rbc 20050930 parent_ids are not being compared
75
71
self.inventory_sha1 == other.inventory_sha1
76
72
and self.revision_id == other.revision_id
78
74
and self.message == other.message
79
75
and self.timezone == other.timezone
80
76
and self.committer == other.committer
81
and self.properties == other.properties
82
and self.parent_ids == other.parent_ids)
77
and self.properties == other.properties)
84
79
def __ne__(self, other):
85
80
return not self.__eq__(other)
90
85
if not isinstance(name, basestring) or contains_whitespace(name):
91
86
raise ValueError("invalid property name %r" % name)
92
87
if not isinstance(value, basestring):
93
raise ValueError("invalid property value %r for %r" %
88
raise ValueError("invalid property value %r for %r" %
96
91
def get_history(self, repository):
97
92
"""Return the canonical line-of-history for this revision.
115
110
def get_summary(self):
116
111
"""Get the first line of the log message for this revision.
118
Return an empty string if message is None.
121
return self.message.lstrip().split('\n', 1)[0]
113
return self.message.lstrip().split('\n', 1)[0]
125
@symbol_versioning.deprecated_method(symbol_versioning.deprecated_in((1, 13, 0)))
126
115
def get_apparent_author(self):
127
116
"""Return the apparent author of this revision.
129
This method is deprecated in favour of get_apparent_authors.
131
If the revision properties contain any author names,
132
return the first. Otherwise return the committer name.
134
authors = self.get_apparent_authors()
140
def get_apparent_authors(self):
141
"""Return the apparent authors of this revision.
143
If the revision properties contain the names of the authors,
144
return them. Otherwise return the committer name.
146
The return value will be a list containing at least one element.
148
authors = self.properties.get('authors', None)
150
author = self.properties.get('author', self.committer)
155
return authors.split("\n")
158
"""Iterate over the bugs associated with this revision."""
159
bug_property = self.properties.get('bugs', None)
160
if bug_property is None:
162
for line in bug_property.splitlines():
164
url, status = line.split(None, 2)
166
raise errors.InvalidLineInBugsProperty(line)
167
if status not in bugtracker.ALLOWED_BUG_STATUSES:
168
raise errors.InvalidBugStatus(status)
118
If the revision properties contain the author name,
119
return it. Otherwise return the committer name.
121
return self.properties.get('author', self.committer)
172
124
def iter_ancestors(revision_id, revision_source, only_present=False):
205
157
if anc_id not in found_ancestors:
206
158
found_ancestors[anc_id] = (anc_order, anc_distance)
207
159
return found_ancestors
210
162
def __get_closest(intersection):
211
163
intersection.sort()
213
165
for entry in intersection:
214
166
if entry[0] == intersection[0][0]:
215
167
matches.append(entry[2])
219
171
def is_reserved_id(revision_id):
220
172
"""Determine whether a revision id is reserved
222
:return: True if the revision is reserved, False otherwise
174
:return: True if the revision is is reserved, False otherwise
224
176
return isinstance(revision_id, basestring) and revision_id.endswith(':')