~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revision.py

  • Committer: Robert Collins
  • Date: 2007-07-04 08:08:13 UTC
  • mfrom: (2572 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2587.
  • Revision ID: robertc@robertcollins.net-20070704080813-wzebx0r88fvwj5rq
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
2
2
#
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
19
19
 
20
20
 
21
21
import bzrlib.errors as errors
22
 
from bzrlib.graph import node_distances, select_farthest, all_descendants, Graph
 
22
from bzrlib.deprecated_graph import (
 
23
    all_descendants,
 
24
    Graph,
 
25
    node_distances,
 
26
    select_farthest,
 
27
    )
23
28
from bzrlib.osutils import contains_whitespace
24
29
from bzrlib.progress import DummyProgress
25
30
from bzrlib.symbol_versioning import (deprecated_function,
27
32
        )
28
33
 
29
34
NULL_REVISION="null:"
 
35
CURRENT_REVISION="current:"
30
36
 
31
37
 
32
38
class Revision(object):
118
124
    revisions_source is an object supporting a get_revision operation that
119
125
    behaves like Branch's.
120
126
    """
121
 
    return (candidate_id in branch.repository.get_ancestry(revision_id))
 
127
    return (candidate_id in branch.repository.get_ancestry(revision_id,
 
128
            topo_sorted=False))
122
129
 
123
130
 
124
131
def iter_ancestors(revision_id, revision_source, only_present=False):
250
257
            pb.update('Picking ancestor', 1, 3)
251
258
            graph = revision_source.get_revision_graph_with_ghosts(
252
259
                [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:
 
264
                return revision_b
 
265
            ancestry_b = graph.get_ancestry(revision_b, topo_sorted=False)
 
266
            if revision_a in ancestry_b:
 
267
                return revision_a
253
268
            # convert to a NULL_REVISION based graph.
254
269
            ancestors = graph.get_ancestors()
255
270
            descendants = graph.get_descendants()
256
 
            common = set(graph.get_ancestry(revision_a)).intersection(
257
 
                     set(graph.get_ancestry(revision_b)))
 
271
            common = set(ancestry_a)
 
272
            common.intersection_update(ancestry_b)
258
273
            descendants[NULL_REVISION] = {}
259
274
            ancestors[NULL_REVISION] = []
260
275
            for root in graph.roots:
453
468
        next = best_ancestor(next)
454
469
    path.reverse()
455
470
    return path
 
471
 
 
472
 
 
473
def is_reserved_id(revision_id):
 
474
    """Determine whether a revision id is reserved
 
475
 
 
476
    :return: True if the revision is is reserved, False otherwise
 
477
    """
 
478
    return isinstance(revision_id, basestring) and revision_id.endswith(':')
 
479
 
 
480
 
 
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)
 
485
 
 
486
def ensure_null(revision_id):
 
487
    """Ensure only NULL_REVISION is used to represent the null revisionn"""
 
488
    if revision_id is None:
 
489
        return NULL_REVISION
 
490
    else:
 
491
        return revision_id