/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/missing.py

  • Committer: Robert Collins
  • Date: 2010-05-06 23:41:35 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506234135-yivbzczw1sejxnxc
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
expected to return an object which can be used to unlock them. This reduces
duplicate code when using cleanups. The previous 'tokens's returned by
``Branch.lock_write`` and ``Repository.lock_write`` are now attributes
on the result of the lock_write. ``repository.RepositoryWriteLockResult``
and ``branch.BranchWriteLockResult`` document this. (Robert Collins)

``log._get_info_for_log_files`` now takes an add_cleanup callable.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Display what revisions are missing in 'other' from 'this' and vice versa."""
18
18
 
19
 
from __future__ import absolute_import
20
 
 
21
 
from . import (
22
 
    errors,
 
19
from bzrlib import (
23
20
    log,
24
21
    )
25
 
 
26
 
 
27
 
def iter_log_revisions(revisions, revision_source, verbose, rev_tag_dict=None):
28
 
    if rev_tag_dict is None:
29
 
        rev_tag_dict = {}
30
 
    for revno, rev_id, merge_depth in revisions:
 
22
import bzrlib.revision as _mod_revision
 
23
 
 
24
 
 
25
def iter_log_revisions(revisions, revision_source, verbose):
 
26
    last_tree = revision_source.revision_tree(_mod_revision.NULL_REVISION)
 
27
    last_rev_id = None
 
28
    for rev in revisions:
 
29
        # We need the following for backward compatibilty (hopefully
 
30
        # this will be deprecated soon :-/) -- vila 080911
 
31
        if len(rev) == 2:
 
32
            revno, rev_id = rev
 
33
            merge_depth = 0
 
34
        else:
 
35
            revno, rev_id, merge_depth = rev
31
36
        rev = revision_source.get_revision(rev_id)
32
37
        if verbose:
33
38
            delta = revision_source.get_revision_delta(rev_id)
34
39
        else:
35
40
            delta = None
36
 
        yield log.LogRevision(rev, revno, merge_depth, delta=delta,
37
 
                              tags=rev_tag_dict.get(rev_id))
 
41
        yield log.LogRevision(rev, revno, merge_depth, delta=delta)
38
42
 
39
43
 
40
44
def find_unmerged(local_branch, remote_branch, restrict='all',
41
 
                  include_merged=None, backward=False,
 
45
                  include_merges=False, backward=False,
42
46
                  local_revid_range=None, remote_revid_range=None):
43
47
    """Find revisions from each side that have not been merged.
44
48
 
49
53
        unique revisions from both sides. If 'local', we will return None
50
54
        for the remote revisions, similarly if 'remote' we will return None for
51
55
        the local revisions.
52
 
    :param include_merged: Show mainline revisions only if False,
 
56
    :param include_merges: Show mainline revisions only if False,
53
57
        all revisions otherwise.
54
58
    :param backward: Show oldest versions first when True, newest versions
55
59
        first when False.
61
65
    :return: A list of [(revno, revision_id)] for the mainline revisions on
62
66
        each side.
63
67
    """
64
 
    if include_merged is None:
65
 
        include_merged = False
66
 
    with local_branch.lock_read(), remote_branch.lock_read():
67
 
        return _find_unmerged(
68
 
            local_branch, remote_branch, restrict=restrict,
69
 
            include_merged=include_merged, backward=backward,
70
 
            local_revid_range=local_revid_range,
71
 
            remote_revid_range=remote_revid_range)
 
68
    local_branch.lock_read()
 
69
    try:
 
70
        remote_branch.lock_read()
 
71
        try:
 
72
            return _find_unmerged(
 
73
                local_branch, remote_branch, restrict=restrict,
 
74
                include_merges=include_merges, backward=backward,
 
75
                local_revid_range=local_revid_range,
 
76
                remote_revid_range=remote_revid_range)
 
77
        finally:
 
78
            remote_branch.unlock()
 
79
    finally:
 
80
        local_branch.unlock()
72
81
 
73
82
 
74
83
def _enumerate_mainline(ancestry, graph, tip_revno, tip, backward=True):
80
89
    :param tip: The tip of mainline
81
90
    :param backward: Show oldest versions first when True, newest versions
82
91
        first when False.
83
 
    :return: [(revno, revision_id, 0)] for all revisions in ancestry that
 
92
    :return: [(revno, revision_id)] for all revisions in ancestry that
84
93
        are left-hand parents from tip, or None if ancestry is None.
85
94
    """
86
95
    if ancestry is None:
87
96
        return None
88
 
    if not ancestry:  # Empty ancestry, no need to do any work
 
97
    if not ancestry: #Empty ancestry, no need to do any work
89
98
        return []
90
99
 
91
100
    # Optionally, we could make 1 call to graph.get_parent_map with all
99
108
        parent_map = graph.get_parent_map([cur])
100
109
        parents = parent_map.get(cur)
101
110
        if not parents:
102
 
            break  # Ghost, we are done
103
 
        mainline.append(
104
 
            (str(cur_revno) if cur_revno is not None else None, cur, 0))
 
111
            break # Ghost, we are done
 
112
        mainline.append((str(cur_revno), cur))
105
113
        cur = parents[0]
106
 
        if cur_revno is not None:
107
 
            cur_revno -= 1
 
114
        cur_revno -= 1
108
115
    if not backward:
109
116
        mainline.reverse()
110
117
    return mainline
126
133
    """
127
134
    if ancestry is None:
128
135
        return None
129
 
    if not ancestry:  # Empty ancestry, no need to do any work
 
136
    if not ancestry: #Empty ancestry, no need to do any work
130
137
        return []
131
138
 
132
139
    merge_sorted_revisions = branch.iter_merge_sorted_revisions()
149
156
    if revid_range is None or revs is None:
150
157
        return revs
151
158
    return [rev for rev in revs
152
 
            if graph.is_between(rev[1], revid_range[0], revid_range[1])]
 
159
        if graph.is_between(rev[1], revid_range[0], revid_range[1])]
153
160
 
154
161
 
155
162
def _find_unmerged(local_branch, remote_branch, restrict,
156
 
                   include_merged, backward,
 
163
                   include_merges, backward,
157
164
                   local_revid_range=None, remote_revid_range=None):
158
165
    """See find_unmerged.
159
166
 
160
167
    The branches should already be locked before entering.
161
168
    """
162
 
    try:
163
 
        local_revno, local_revision_id = local_branch.last_revision_info()
164
 
    except (errors.UnsupportedOperation, errors.GhostRevisionsHaveNoRevno):
165
 
        local_revno = None
166
 
        local_revision_id = local_branch.last_revision()
167
 
    try:
168
 
        remote_revno, remote_revision_id = remote_branch.last_revision_info()
169
 
    except (errors.UnsupportedOperation, errors.GhostRevisionsHaveNoRevno):
170
 
        remote_revision_id = remote_branch.last_revision()
171
 
        remote_revno = None
172
 
 
173
 
    if local_revision_id == remote_revision_id:
 
169
    local_revno, local_revision_id = local_branch.last_revision_info()
 
170
    remote_revno, remote_revision_id = remote_branch.last_revision_info()
 
171
    if local_revno == remote_revno and local_revision_id == remote_revision_id:
174
172
        # A simple shortcut when the tips are at the same point
175
173
        return [], []
176
174
    graph = local_branch.repository.get_graph(remote_branch.repository)
188
186
                             ' "remote": %r' % (restrict,))
189
187
        local_extra, remote_extra = graph.find_difference(local_revision_id,
190
188
                                                          remote_revision_id)
191
 
    if include_merged:
 
189
    if include_merges:
192
190
        locals = _enumerate_with_merges(local_branch, local_extra,
193
191
                                        graph, local_revno,
194
192
                                        local_revision_id, backward)
202
200
                                     local_revision_id, backward)
203
201
        remotes = _enumerate_mainline(remote_extra, graph, remote_revno,
204
202
                                      remote_revision_id, backward)
205
 
    return _filter_revs(graph, locals, local_revid_range), _filter_revs(
206
 
        graph, remotes, remote_revid_range)
 
203
    return _filter_revs(graph, locals, local_revid_range), _filter_revs(graph,
 
204
        remotes, remote_revid_range)
207
205
 
208
206
 
209
207
def sorted_revisions(revisions, history_map):
210
 
    revisions = sorted([(history_map[r], r) for r in revisions])
 
208
    revisions = [(history_map[r],r) for r in revisions]
 
209
    revisions.sort()
211
210
    return revisions