111
103
reversed_result.reverse()
112
104
return reversed_result
114
def get_summary(self):
115
"""Get the first line of the log message for this revision.
117
Return an empty string if message is None.
120
return self.message.lstrip().split('\n', 1)[0]
124
@symbol_versioning.deprecated_method(symbol_versioning.deprecated_in((1, 13, 0)))
125
def get_apparent_author(self):
126
"""Return the apparent author of this revision.
128
This method is deprecated in favour of get_apparent_authors.
130
If the revision properties contain any author names,
131
return the first. Otherwise return the committer name.
133
authors = self.get_apparent_authors()
139
def get_apparent_authors(self):
140
"""Return the apparent authors of this revision.
142
If the revision properties contain the names of the authors,
143
return them. Otherwise return the committer name.
145
The return value will be a list containing at least one element.
147
authors = self.properties.get('authors', None)
149
author = self.properties.get('author', self.committer)
154
return authors.split("\n")
157
"""Iterate over the bugs associated with this revision."""
158
bug_property = self.properties.get('bugs', None)
159
if bug_property is None:
161
for line in bug_property.splitlines():
163
url, status = line.split(None, 2)
165
raise errors.InvalidLineInBugsProperty(line)
166
if status not in bugtracker.ALLOWED_BUG_STATUSES:
167
raise errors.InvalidBugStatus(status)
107
def is_ancestor(revision_id, candidate_id, branch):
108
"""Return true if candidate_id is an ancestor of revision_id.
110
A false negative will be returned if any intermediate descendent of
111
candidate_id is not present in any of the revision_sources.
113
revisions_source is an object supporting a get_revision operation that
114
behaves like Branch's.
116
return candidate_id in branch.repository.get_ancestry(revision_id)
171
119
def iter_ancestors(revision_id, revision_source, only_present=False):
194
142
"""Return the ancestors of a revision present in a branch.
196
144
It's possible that a branch won't have the complete ancestry of
197
one of its revisions.
145
one of its revisions.
200
148
found_ancestors = {}
201
149
anc_iter = enumerate(iter_ancestors(revision_id, revision_source,
202
150
only_present=True))
203
151
for anc_order, (anc_id, anc_distance) in anc_iter:
204
if anc_id not in found_ancestors:
152
if not found_ancestors.has_key(anc_id):
205
153
found_ancestors[anc_id] = (anc_order, anc_distance)
206
154
return found_ancestors
209
157
def __get_closest(intersection):
210
158
intersection.sort()
212
160
for entry in intersection:
213
161
if entry[0] == intersection[0][0]:
214
162
matches.append(entry[2])
218
def is_reserved_id(revision_id):
219
"""Determine whether a revision id is reserved
221
:return: True if the revision is reserved, False otherwise
166
def revision_graph(revision, revision_source):
167
"""Produce a graph of the ancestry of the specified revision.
169
:return: root, ancestors map, descendants map
223
return isinstance(revision_id, basestring) and revision_id.endswith(':')
226
def check_not_reserved_id(revision_id):
227
"""Raise ReservedId if the supplied revision_id is reserved"""
228
if is_reserved_id(revision_id):
229
raise errors.ReservedId(revision_id)
232
def ensure_null(revision_id):
233
"""Ensure only NULL_REVISION is used to represent the null revision"""
234
if revision_id is None:
235
symbol_versioning.warn('NULL_REVISION should be used for the null'
236
' revision instead of None, as of bzr 0.91.',
237
DeprecationWarning, stacklevel=2)
243
def is_null(revision_id):
244
if revision_id is None:
245
symbol_versioning.warn('NULL_REVISION should be used for the null'
246
' revision instead of None, as of bzr 0.90.',
247
DeprecationWarning, stacklevel=2)
248
return revision_id in (None, NULL_REVISION)
171
revision_source.lock_read()
173
return _revision_graph(revision, revision_source)
175
revision_source.unlock()
178
def _revision_graph(revision, revision_source):
179
"""See revision_graph."""
180
from bzrlib.tsort import topo_sort
181
graph = revision_source.get_revision_graph(revision)
182
# mark all no-parent revisions as being NULL_REVISION parentage.
183
for node, parents in graph.items():
184
if len(parents) == 0:
185
graph[node] = [NULL_REVISION]
186
# add NULL_REVISION to the graph
187
graph[NULL_REVISION] = []
189
# pick a root. If there are multiple roots
190
# this could pick a random one.
191
topo_order = topo_sort(graph.items())
197
# map the descendants of the graph.
198
# and setup our set based return graph.
199
for node in graph.keys():
200
descendants[node] = {}
201
for node, parents in graph.items():
202
for parent in parents:
203
descendants[parent][node] = 1
204
ancestors[node] = set(parents)
206
assert root not in descendants[root]
207
assert root not in ancestors[root]
208
return root, ancestors, descendants
211
def combined_graph(revision_a, revision_b, revision_source):
212
"""Produce a combined ancestry graph.
213
Return graph root, ancestors map, descendants map, set of common nodes"""
214
root, ancestors, descendants = revision_graph(
215
revision_a, revision_source)
216
root_b, ancestors_b, descendants_b = revision_graph(
217
revision_b, revision_source)
219
raise bzrlib.errors.NoCommonRoot(revision_a, revision_b)
221
for node, node_anc in ancestors_b.iteritems():
222
if node in ancestors:
225
ancestors[node] = set()
226
ancestors[node].update(node_anc)
227
for node, node_dec in descendants_b.iteritems():
228
if node not in descendants:
229
descendants[node] = {}
230
descendants[node].update(node_dec)
231
return root, ancestors, descendants, common
234
def common_ancestor(revision_a, revision_b, revision_source,
236
if None in (revision_a, revision_b):
238
# trivial optimisation
239
if revision_a == revision_b:
243
pb.update('Picking ancestor', 1, 3)
244
graph = revision_source.get_revision_graph_with_ghosts(
245
[revision_a, revision_b])
246
# convert to a NULL_REVISION based graph.
247
ancestors = graph.get_ancestors()
248
descendants = graph.get_descendants()
249
common = set(graph.get_ancestry(revision_a)).intersection(
250
set(graph.get_ancestry(revision_b)))
251
descendants[NULL_REVISION] = {}
252
ancestors[NULL_REVISION] = []
253
for root in graph.roots:
254
descendants[NULL_REVISION][root] = 1
255
ancestors[root].append(NULL_REVISION)
256
for ghost in graph.ghosts:
257
# ghosts act as roots for the purpose of finding
258
# the longest paths from the root: any ghost *might*
259
# be directly attached to the root, so we treat them
261
# ghost now descends from NULL
262
descendants[NULL_REVISION][ghost] = 1
263
# that is it has an ancestor of NULL
264
ancestors[ghost] = [NULL_REVISION]
265
# ghost is common if any of ghosts descendants are common:
266
for ghost_descendant in descendants[ghost]:
267
if ghost_descendant in common:
271
common.add(NULL_REVISION)
272
except bzrlib.errors.NoCommonRoot:
273
raise bzrlib.errors.NoCommonAncestor(revision_a, revision_b)
275
pb.update('Picking ancestor', 2, 3)
276
distances = node_distances (descendants, ancestors, root)
277
pb.update('Picking ancestor', 3, 2)
278
farthest = select_farthest(distances, common)
279
if farthest is None or farthest == NULL_REVISION:
280
raise bzrlib.errors.NoCommonAncestor(revision_a, revision_b)
286
class MultipleRevisionSources(object):
287
"""Proxy that looks in multiple branches for revisions."""
288
def __init__(self, *args):
289
object.__init__(self)
290
assert len(args) != 0
291
self._revision_sources = args
293
def revision_parents(self, revision_id):
294
for source in self._revision_sources:
296
return source.revision_parents(revision_id)
297
except (errors.WeaveRevisionNotPresent, errors.NoSuchRevision), e:
301
def get_revision(self, revision_id):
302
for source in self._revision_sources:
304
return source.get_revision(revision_id)
305
except bzrlib.errors.NoSuchRevision, e:
309
def get_revision_graph(self, revision_id):
310
# we could probe incrementally until the pending
311
# ghosts list stop growing, but its cheaper for now
312
# to just ask for the complete graph for each repository.
314
for source in self._revision_sources:
315
ghost_graph = source.get_revision_graph_with_ghosts()
316
graphs.append(ghost_graph)
319
if not revision_id in graph.get_ancestors():
321
if absent == len(graphs):
322
raise errors.NoSuchRevision(self._revision_sources[0], revision_id)
326
pending = set([revision_id])
327
def find_parents(node_id):
328
"""find the parents for node_id."""
330
ancestors = graph.get_ancestors()
332
return ancestors[node_id]
335
raise errors.NoSuchRevision(self._revision_sources[0], node_id)
337
# all the graphs should have identical parent lists
338
node_id = pending.pop()
340
result[node_id] = find_parents(node_id)
341
for parent_node in result[node_id]:
342
if not parent_node in result:
343
pending.add(parent_node)
344
except errors.NoSuchRevision:
349
def get_revision_graph_with_ghosts(self, revision_ids):
350
# query all the sources for their entire graphs
351
# and then build a combined graph for just
354
for source in self._revision_sources:
355
ghost_graph = source.get_revision_graph_with_ghosts()
356
graphs.append(ghost_graph.get_ancestors())
357
for revision_id in revision_ids:
360
if not revision_id in graph:
362
if absent == len(graphs):
363
raise errors.NoSuchRevision(self._revision_sources[0],
368
pending = set(revision_ids)
370
def find_parents(node_id):
371
"""find the parents for node_id."""
374
return graph[node_id]
377
raise errors.NoSuchRevision(self._revision_sources[0], node_id)
379
# all the graphs should have identical parent lists
380
node_id = pending.pop()
382
parents = find_parents(node_id)
383
for parent_node in parents:
385
if (parent_node not in pending and
386
parent_node not in done):
388
pending.add(parent_node)
389
result.add_node(node_id, parents)
391
except errors.NoSuchRevision:
393
result.add_ghost(node_id)
398
for source in self._revision_sources:
402
for source in self._revision_sources: