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
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
11
# GNU General Public License for more details.
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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
18
# perhaps show them in log -v and allow them as options to the commit command.
25
from bzrlib.deprecated_graph import (
22
import bzrlib.errors as errors
23
from bzrlib.graph import node_distances, select_farthest, all_descendants, Graph
31
24
from bzrlib.osutils import contains_whitespace
32
25
from bzrlib.progress import DummyProgress
33
from bzrlib.symbol_versioning import (deprecated_function,
37
27
NULL_REVISION="null:"
38
CURRENT_REVISION="current:"
41
29
class Revision(object):
42
30
"""Single revision on a branch.
85
72
return not self.__eq__(other)
87
74
def _check_properties(self):
88
"""Verify that all revision properties are OK."""
75
"""Verify that all revision properties are OK.
89
77
for name, value in self.properties.iteritems():
90
78
if not isinstance(name, basestring) or contains_whitespace(name):
91
79
raise ValueError("invalid property name %r" % name)
166
146
anc_iter = enumerate(iter_ancestors(revision_id, revision_source,
167
147
only_present=True))
168
148
for anc_order, (anc_id, anc_distance) in anc_iter:
169
if anc_id not in found_ancestors:
149
if not found_ancestors.has_key(anc_id):
170
150
found_ancestors[anc_id] = (anc_order, anc_distance)
171
151
return found_ancestors
233
213
root_b, ancestors_b, descendants_b = revision_graph(
234
214
revision_b, revision_source)
235
215
if root != root_b:
236
raise errors.NoCommonRoot(revision_a, revision_b)
216
raise bzrlib.errors.NoCommonRoot(revision_a, revision_b)
238
218
for node, node_anc in ancestors_b.iteritems():
239
219
if node in ancestors:
262
240
pb.update('Picking ancestor', 1, 3)
263
241
graph = revision_source.get_revision_graph_with_ghosts(
264
242
[revision_a, revision_b])
265
# Shortcut the case where one of the tips is already included in
266
# the other graphs ancestry.
267
ancestry_a = graph.get_ancestry(revision_a, topo_sorted=False)
268
if revision_b in ancestry_a:
270
ancestry_b = graph.get_ancestry(revision_b, topo_sorted=False)
271
if revision_a in ancestry_b:
273
243
# convert to a NULL_REVISION based graph.
274
244
ancestors = graph.get_ancestors()
275
245
descendants = graph.get_descendants()
276
common = set(ancestry_a)
277
common.intersection_update(ancestry_b)
246
common = set(graph.get_ancestry(revision_a)).intersection(
247
set(graph.get_ancestry(revision_b)))
278
248
descendants[NULL_REVISION] = {}
279
249
ancestors[NULL_REVISION] = []
280
250
for root in graph.roots:
281
251
descendants[NULL_REVISION][root] = 1
282
252
ancestors[root].append(NULL_REVISION)
283
for ghost in graph.ghosts:
284
# ghosts act as roots for the purpose of finding
285
# the longest paths from the root: any ghost *might*
286
# be directly attached to the root, so we treat them
288
# ghost now descends from NULL
289
descendants[NULL_REVISION][ghost] = 1
290
# that is it has an ancestor of NULL
291
ancestors[ghost] = [NULL_REVISION]
292
# ghost is common if any of ghosts descendants are common:
293
for ghost_descendant in descendants[ghost]:
294
if ghost_descendant in common:
253
if len(graph.roots) == 0:
254
# no reachable roots - not handled yet.
255
raise bzrlib.errors.NoCommonAncestor(revision_a, revision_b)
297
256
root = NULL_REVISION
298
257
common.add(NULL_REVISION)
299
except errors.NoCommonRoot:
300
raise errors.NoCommonAncestor(revision_a, revision_b)
258
except bzrlib.errors.NoCommonRoot:
259
raise bzrlib.errors.NoCommonAncestor(revision_a, revision_b)
302
261
pb.update('Picking ancestor', 2, 3)
303
262
distances = node_distances (descendants, ancestors, root)
304
263
pb.update('Picking ancestor', 3, 2)
305
264
farthest = select_farthest(distances, common)
306
265
if farthest is None or farthest == NULL_REVISION:
307
raise errors.NoCommonAncestor(revision_a, revision_b)
266
raise bzrlib.errors.NoCommonAncestor(revision_a, revision_b)
433
@deprecated_function(zero_eight)
434
def get_intervening_revisions(ancestor_id, rev_id, rev_source,
392
def get_intervening_revisions(ancestor_id, rev_id, rev_source,
435
393
revision_history=None):
436
394
"""Find the longest line of descent from maybe_ancestor to revision.
437
395
Revision history is followed where possible.
443
401
root, ancestors, descendants = revision_graph(rev_id, rev_source)
444
402
if len(descendants) == 0:
445
raise errors.NoSuchRevision(rev_source, rev_id)
403
raise NoSuchRevision(rev_source, rev_id)
446
404
if ancestor_id not in descendants:
447
405
rev_source.get_revision(ancestor_id)
448
raise errors.NotAncestor(rev_id, ancestor_id)
406
raise bzrlib.errors.NotAncestor(rev_id, ancestor_id)
449
407
root_descendants = all_descendants(descendants, ancestor_id)
450
408
root_descendants.add(ancestor_id)
451
409
if rev_id not in root_descendants:
452
raise errors.NotAncestor(rev_id, ancestor_id)
410
raise bzrlib.errors.NotAncestor(rev_id, ancestor_id)
453
411
distances = node_distances(descendants, ancestors, ancestor_id,
454
412
root_descendants=root_descendants)
473
431
next = best_ancestor(next)
478
def is_reserved_id(revision_id):
479
"""Determine whether a revision id is reserved
481
:return: True if the revision is is reserved, False otherwise
483
return isinstance(revision_id, basestring) and revision_id.endswith(':')
486
def check_not_reserved_id(revision_id):
487
"""Raise ReservedId if the supplied revision_id is reserved"""
488
if is_reserved_id(revision_id):
489
raise errors.ReservedId(revision_id)
492
def ensure_null(revision_id):
493
"""Ensure only NULL_REVISION is used to represent the null revisionn"""
494
if revision_id is None:
500
def is_null(revision_id):
501
if revision_id is None:
502
symbol_versioning.warn('NULL_REVISION should be used for the null'
503
' revision instead of None, as of bzr 0.19.',
504
DeprecationWarning, stacklevel=2)
505
return revision_id in (None, NULL_REVISION)