~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revision.py

  • Committer: Vincent Ladeuil
  • Date: 2008-01-03 08:49:38 UTC
  • mfrom: (3111.1.31 175524)
  • mto: This revision was merged to the branch mainline in revision 3158.
  • Revision ID: v.ladeuil+lp@free.fr-20080103084938-7kvurk5uvde2ui54
Fix bug #175524, http test servers are 1.1 compliant

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
# perhaps show them in log -v and allow them as options to the commit command.
19
19
 
20
20
 
21
 
import bzrlib.errors as errors
22
 
from bzrlib.graph import node_distances, select_farthest, all_descendants, Graph
 
21
from bzrlib import (
 
22
    errors,
 
23
    symbol_versioning
 
24
    )
 
25
from bzrlib.deprecated_graph import (
 
26
    all_descendants,
 
27
    Graph,
 
28
    node_distances,
 
29
    select_farthest,
 
30
    )
23
31
from bzrlib.osutils import contains_whitespace
24
32
from bzrlib.progress import DummyProgress
25
33
from bzrlib.symbol_versioning import (deprecated_function,
26
 
        zero_eight,
27
34
        )
28
35
 
29
36
NULL_REVISION="null:"
107
114
    def get_summary(self):
108
115
        """Get the first line of the log message for this revision.
109
116
        """
110
 
        return self.message.split('\n', 1)[0]
111
 
 
112
 
 
 
117
        return self.message.lstrip().split('\n', 1)[0]
 
118
 
 
119
    def get_apparent_author(self):
 
120
        """Return the apparent author of this revision.
 
121
 
 
122
        If the revision properties contain the author name,
 
123
        return it. Otherwise return the committer name.
 
124
        """
 
125
        return self.properties.get('author', self.committer)
 
126
 
 
127
 
 
128
@deprecated_function(symbol_versioning.one_zero)
113
129
def is_ancestor(revision_id, candidate_id, branch):
114
130
    """Return true if candidate_id is an ancestor of revision_id.
115
131
 
118
134
    
119
135
    revisions_source is an object supporting a get_revision operation that
120
136
    behaves like Branch's.
 
137
 
 
138
    This function is deprecated, it is better for callers to directly use
 
139
    Graph.is_ancestor() (just watch out that the parameter order is switched)
121
140
    """
122
 
    return (candidate_id in branch.repository.get_ancestry(revision_id))
 
141
    return branch.repository.get_graph().is_ancestor(candidate_id, revision_id)
123
142
 
124
143
 
125
144
def iter_ancestors(revision_id, revision_source, only_present=False):
253
272
                [revision_a, revision_b])
254
273
            # Shortcut the case where one of the tips is already included in
255
274
            # the other graphs ancestry.
256
 
            ancestry_a = graph.get_ancestry(revision_a)
 
275
            ancestry_a = graph.get_ancestry(revision_a, topo_sorted=False)
257
276
            if revision_b in ancestry_a:
258
277
                return revision_b
259
 
            ancestry_b = graph.get_ancestry(revision_b)
 
278
            ancestry_b = graph.get_ancestry(revision_b, topo_sorted=False)
260
279
            if revision_a in ancestry_b:
261
280
                return revision_a
262
281
            # convert to a NULL_REVISION based graph.
419
438
            source.unlock()
420
439
 
421
440
 
422
 
@deprecated_function(zero_eight)
423
 
def get_intervening_revisions(ancestor_id, rev_id, rev_source,
424
 
                              revision_history=None):
425
 
    """Find the longest line of descent from maybe_ancestor to revision.
426
 
    Revision history is followed where possible.
427
 
 
428
 
    If ancestor_id == rev_id, list will be empty.
429
 
    Otherwise, rev_id will be the last entry.  ancestor_id will never appear.
430
 
    If ancestor_id is not an ancestor, NotAncestor will be thrown
431
 
    """
432
 
    root, ancestors, descendants = revision_graph(rev_id, rev_source)
433
 
    if len(descendants) == 0:
434
 
        raise errors.NoSuchRevision(rev_source, rev_id)
435
 
    if ancestor_id not in descendants:
436
 
        rev_source.get_revision(ancestor_id)
437
 
        raise errors.NotAncestor(rev_id, ancestor_id)
438
 
    root_descendants = all_descendants(descendants, ancestor_id)
439
 
    root_descendants.add(ancestor_id)
440
 
    if rev_id not in root_descendants:
441
 
        raise errors.NotAncestor(rev_id, ancestor_id)
442
 
    distances = node_distances(descendants, ancestors, ancestor_id,
443
 
                               root_descendants=root_descendants)
444
 
 
445
 
    def best_ancestor(rev_id):
446
 
        best = None
447
 
        for anc_id in ancestors[rev_id]:
448
 
            try:
449
 
                distance = distances[anc_id]
450
 
            except KeyError:
451
 
                continue
452
 
            if revision_history is not None and anc_id in revision_history:
453
 
                return anc_id
454
 
            elif best is None or distance > best[1]:
455
 
                best = (anc_id, distance)
456
 
        return best[0]
457
 
 
458
 
    next = rev_id
459
 
    path = []
460
 
    while next != ancestor_id:
461
 
        path.append(next)
462
 
        next = best_ancestor(next)
463
 
    path.reverse()
464
 
    return path
465
 
 
466
 
 
467
441
def is_reserved_id(revision_id):
468
442
    """Determine whether a revision id is reserved
469
443
 
476
450
    """Raise ReservedId if the supplied revision_id is reserved"""
477
451
    if is_reserved_id(revision_id):
478
452
        raise errors.ReservedId(revision_id)
 
453
 
 
454
 
 
455
def ensure_null(revision_id):
 
456
    """Ensure only NULL_REVISION is used to represent the null revision"""
 
457
    if revision_id is None:
 
458
        symbol_versioning.warn('NULL_REVISION should be used for the null'
 
459
            ' revision instead of None, as of bzr 0.91.',
 
460
            DeprecationWarning, stacklevel=2)
 
461
        return NULL_REVISION
 
462
    else:
 
463
        return revision_id
 
464
 
 
465
 
 
466
def is_null(revision_id):
 
467
    if revision_id is None:
 
468
        symbol_versioning.warn('NULL_REVISION should be used for the null'
 
469
            ' revision instead of None, as of bzr 0.90.',
 
470
            DeprecationWarning, stacklevel=2)
 
471
    return revision_id in (None, NULL_REVISION)