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.
21
22
import bzrlib.errors as errors
22
from bzrlib.deprecated_graph import (
23
from bzrlib.graph import node_distances, select_farthest, all_descendants, Graph
28
24
from bzrlib.osutils import contains_whitespace
29
25
from bzrlib.progress import DummyProgress
30
from bzrlib.symbol_versioning import (deprecated_function,
34
27
NULL_REVISION="null:"
35
CURRENT_REVISION="current:"
38
29
class Revision(object):
39
30
"""Single revision on a branch.
82
72
return not self.__eq__(other)
84
74
def _check_properties(self):
85
"""Verify that all revision properties are OK."""
75
"""Verify that all revision properties are OK.
86
77
for name, value in self.properties.iteritems():
87
78
if not isinstance(name, basestring) or contains_whitespace(name):
88
79
raise ValueError("invalid property name %r" % name)
161
146
anc_iter = enumerate(iter_ancestors(revision_id, revision_source,
162
147
only_present=True))
163
148
for anc_order, (anc_id, anc_distance) in anc_iter:
164
if anc_id not in found_ancestors:
149
if not found_ancestors.has_key(anc_id):
165
150
found_ancestors[anc_id] = (anc_order, anc_distance)
166
151
return found_ancestors
228
213
root_b, ancestors_b, descendants_b = revision_graph(
229
214
revision_b, revision_source)
230
215
if root != root_b:
231
raise errors.NoCommonRoot(revision_a, revision_b)
216
raise bzrlib.errors.NoCommonRoot(revision_a, revision_b)
233
218
for node, node_anc in ancestors_b.iteritems():
234
219
if node in ancestors:
257
240
pb.update('Picking ancestor', 1, 3)
258
241
graph = revision_source.get_revision_graph_with_ghosts(
259
242
[revision_a, revision_b])
260
# Shortcut the case where one of the tips is already included in
261
# the other graphs ancestry.
262
ancestry_a = graph.get_ancestry(revision_a, topo_sorted=False)
263
if revision_b in ancestry_a:
265
ancestry_b = graph.get_ancestry(revision_b, topo_sorted=False)
266
if revision_a in ancestry_b:
268
243
# convert to a NULL_REVISION based graph.
269
244
ancestors = graph.get_ancestors()
270
245
descendants = graph.get_descendants()
271
common = set(ancestry_a)
272
common.intersection_update(ancestry_b)
246
common = set(graph.get_ancestry(revision_a)).intersection(
247
set(graph.get_ancestry(revision_b)))
273
248
descendants[NULL_REVISION] = {}
274
249
ancestors[NULL_REVISION] = []
275
250
for root in graph.roots:
276
251
descendants[NULL_REVISION][root] = 1
277
252
ancestors[root].append(NULL_REVISION)
278
for ghost in graph.ghosts:
279
# ghosts act as roots for the purpose of finding
280
# the longest paths from the root: any ghost *might*
281
# be directly attached to the root, so we treat them
283
# ghost now descends from NULL
284
descendants[NULL_REVISION][ghost] = 1
285
# that is it has an ancestor of NULL
286
ancestors[ghost] = [NULL_REVISION]
287
# ghost is common if any of ghosts descendants are common:
288
for ghost_descendant in descendants[ghost]:
289
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)
292
256
root = NULL_REVISION
293
257
common.add(NULL_REVISION)
294
except errors.NoCommonRoot:
295
raise errors.NoCommonAncestor(revision_a, revision_b)
258
except bzrlib.errors.NoCommonRoot:
259
raise bzrlib.errors.NoCommonAncestor(revision_a, revision_b)
297
261
pb.update('Picking ancestor', 2, 3)
298
262
distances = node_distances (descendants, ancestors, root)
299
263
pb.update('Picking ancestor', 3, 2)
300
264
farthest = select_farthest(distances, common)
301
265
if farthest is None or farthest == NULL_REVISION:
302
raise errors.NoCommonAncestor(revision_a, revision_b)
266
raise bzrlib.errors.NoCommonAncestor(revision_a, revision_b)
428
@deprecated_function(zero_eight)
429
def get_intervening_revisions(ancestor_id, rev_id, rev_source,
392
def get_intervening_revisions(ancestor_id, rev_id, rev_source,
430
393
revision_history=None):
431
394
"""Find the longest line of descent from maybe_ancestor to revision.
432
395
Revision history is followed where possible.
438
401
root, ancestors, descendants = revision_graph(rev_id, rev_source)
439
402
if len(descendants) == 0:
440
raise errors.NoSuchRevision(rev_source, rev_id)
403
raise NoSuchRevision(rev_source, rev_id)
441
404
if ancestor_id not in descendants:
442
405
rev_source.get_revision(ancestor_id)
443
raise errors.NotAncestor(rev_id, ancestor_id)
406
raise bzrlib.errors.NotAncestor(rev_id, ancestor_id)
444
407
root_descendants = all_descendants(descendants, ancestor_id)
445
408
root_descendants.add(ancestor_id)
446
409
if rev_id not in root_descendants:
447
raise errors.NotAncestor(rev_id, ancestor_id)
410
raise bzrlib.errors.NotAncestor(rev_id, ancestor_id)
448
411
distances = node_distances(descendants, ancestors, ancestor_id,
449
412
root_descendants=root_descendants)
468
431
next = best_ancestor(next)
473
def is_reserved_id(revision_id):
474
"""Determine whether a revision id is reserved
476
:return: True if the revision is is reserved, False otherwise
478
return isinstance(revision_id, basestring) and revision_id.endswith(':')
481
def check_not_reserved_id(revision_id):
482
"""Raise ReservedId if the supplied revision_id is reserved"""
483
if is_reserved_id(revision_id):
484
raise errors.ReservedId(revision_id)
486
def ensure_null(revision_id):
487
"""Ensure only NULL_REVISION is used to represent the null revisionn"""
488
if revision_id is None: