/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 breezy/missing.py

  • Committer: Breezy landing bot
  • Author(s): Colin Watson
  • Date: 2020-11-16 21:47:08 UTC
  • mfrom: (7521.1.1 remove-lp-workaround)
  • Revision ID: breezy.the.bot@gmail.com-20201116214708-jos209mgxi41oy15
Remove breezy.git workaround for bazaar.launchpad.net.

Merged from https://code.launchpad.net/~cjwatson/brz/remove-lp-workaround/+merge/393710

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 bzrlib import (
 
19
from . import (
 
20
    errors,
22
21
    log,
23
 
    symbol_versioning,
24
22
    )
25
 
import bzrlib.revision as _mod_revision
26
23
 
27
24
 
28
25
def iter_log_revisions(revisions, revision_source, verbose, rev_tag_dict=None):
29
 
    last_tree = revision_source.revision_tree(_mod_revision.NULL_REVISION)
30
 
    last_rev_id = None
31
 
 
32
26
    if rev_tag_dict is None:
33
27
        rev_tag_dict = {}
34
 
    for rev in revisions:
35
 
        # We need the following for backward compatibilty (hopefully
36
 
        # this will be deprecated soon :-/) -- vila 080911
37
 
        if len(rev) == 2:
38
 
            revno, rev_id = rev
39
 
            merge_depth = 0
40
 
        else:
41
 
            revno, rev_id, merge_depth = rev
 
28
    for revno, rev_id, merge_depth in revisions:
42
29
        rev = revision_source.get_revision(rev_id)
43
30
        if verbose:
44
31
            delta = revision_source.get_revision_delta(rev_id)
50
37
 
51
38
def find_unmerged(local_branch, remote_branch, restrict='all',
52
39
                  include_merged=None, backward=False,
53
 
                  local_revid_range=None, remote_revid_range=None,
54
 
                  include_merges=symbol_versioning.DEPRECATED_PARAMETER):
 
40
                  local_revid_range=None, remote_revid_range=None):
55
41
    """Find revisions from each side that have not been merged.
56
42
 
57
43
    :param local_branch: Compare the history of local_branch
69
55
        revisions (lower bound, upper bound)
70
56
    :param remote_revid_range: Revision-id range for filtering remote_branch
71
57
        revisions (lower bound, upper bound)
72
 
    :param include_merges: Deprecated historical alias for include_merged
73
58
 
74
59
    :return: A list of [(revno, revision_id)] for the mainline revisions on
75
60
        each side.
76
61
    """
77
 
    if symbol_versioning.deprecated_passed(include_merges):
78
 
        symbol_versioning.warn(
79
 
            'include_merges was deprecated in 2.5.'
80
 
            ' Use include_merged instead.',
81
 
            DeprecationWarning, stacklevel=2)
82
 
        if include_merged is None:
83
 
            include_merged = include_merges
84
62
    if include_merged is None:
85
63
        include_merged = False
86
 
    local_branch.lock_read()
87
 
    try:
88
 
        remote_branch.lock_read()
89
 
        try:
90
 
            return _find_unmerged(
91
 
                local_branch, remote_branch, restrict=restrict,
92
 
                include_merged=include_merged, backward=backward,
93
 
                local_revid_range=local_revid_range,
94
 
                remote_revid_range=remote_revid_range)
95
 
        finally:
96
 
            remote_branch.unlock()
97
 
    finally:
98
 
        local_branch.unlock()
 
64
    with local_branch.lock_read(), remote_branch.lock_read():
 
65
        return _find_unmerged(
 
66
            local_branch, remote_branch, restrict=restrict,
 
67
            include_merged=include_merged, backward=backward,
 
68
            local_revid_range=local_revid_range,
 
69
            remote_revid_range=remote_revid_range)
99
70
 
100
71
 
101
72
def _enumerate_mainline(ancestry, graph, tip_revno, tip, backward=True):
107
78
    :param tip: The tip of mainline
108
79
    :param backward: Show oldest versions first when True, newest versions
109
80
        first when False.
110
 
    :return: [(revno, revision_id)] for all revisions in ancestry that
 
81
    :return: [(revno, revision_id, 0)] for all revisions in ancestry that
111
82
        are left-hand parents from tip, or None if ancestry is None.
112
83
    """
113
84
    if ancestry is None:
114
85
        return None
115
 
    if not ancestry: #Empty ancestry, no need to do any work
 
86
    if not ancestry:  # Empty ancestry, no need to do any work
116
87
        return []
117
88
 
118
89
    # Optionally, we could make 1 call to graph.get_parent_map with all
126
97
        parent_map = graph.get_parent_map([cur])
127
98
        parents = parent_map.get(cur)
128
99
        if not parents:
129
 
            break # Ghost, we are done
130
 
        mainline.append((str(cur_revno), cur))
 
100
            break  # Ghost, we are done
 
101
        mainline.append(
 
102
            (str(cur_revno) if cur_revno is not None else None, cur, 0))
131
103
        cur = parents[0]
132
 
        cur_revno -= 1
 
104
        if cur_revno is not None:
 
105
            cur_revno -= 1
133
106
    if not backward:
134
107
        mainline.reverse()
135
108
    return mainline
151
124
    """
152
125
    if ancestry is None:
153
126
        return None
154
 
    if not ancestry: #Empty ancestry, no need to do any work
 
127
    if not ancestry:  # Empty ancestry, no need to do any work
155
128
        return []
156
129
 
157
130
    merge_sorted_revisions = branch.iter_merge_sorted_revisions()
174
147
    if revid_range is None or revs is None:
175
148
        return revs
176
149
    return [rev for rev in revs
177
 
        if graph.is_between(rev[1], revid_range[0], revid_range[1])]
 
150
            if graph.is_between(rev[1], revid_range[0], revid_range[1])]
178
151
 
179
152
 
180
153
def _find_unmerged(local_branch, remote_branch, restrict,
184
157
 
185
158
    The branches should already be locked before entering.
186
159
    """
187
 
    local_revno, local_revision_id = local_branch.last_revision_info()
188
 
    remote_revno, remote_revision_id = remote_branch.last_revision_info()
189
 
    if local_revno == remote_revno and local_revision_id == remote_revision_id:
 
160
    try:
 
161
        local_revno, local_revision_id = local_branch.last_revision_info()
 
162
    except (errors.UnsupportedOperation, errors.GhostRevisionsHaveNoRevno):
 
163
        local_revno = None
 
164
        local_revision_id = local_branch.last_revision()
 
165
    try:
 
166
        remote_revno, remote_revision_id = remote_branch.last_revision_info()
 
167
    except (errors.UnsupportedOperation, errors.GhostRevisionsHaveNoRevno):
 
168
        remote_revision_id = remote_branch.last_revision()
 
169
        remote_revno = None
 
170
 
 
171
    if local_revision_id == remote_revision_id:
190
172
        # A simple shortcut when the tips are at the same point
191
173
        return [], []
192
174
    graph = local_branch.repository.get_graph(remote_branch.repository)
218
200
                                     local_revision_id, backward)
219
201
        remotes = _enumerate_mainline(remote_extra, graph, remote_revno,
220
202
                                      remote_revision_id, backward)
221
 
    return _filter_revs(graph, locals, local_revid_range), _filter_revs(graph,
222
 
        remotes, remote_revid_range)
 
203
    return _filter_revs(graph, locals, local_revid_range), _filter_revs(
 
204
        graph, remotes, remote_revid_range)
223
205
 
224
206
 
225
207
def sorted_revisions(revisions, history_map):
226
 
    revisions = [(history_map[r],r) for r in revisions]
227
 
    revisions.sort()
 
208
    revisions = sorted([(history_map[r], r) for r in revisions])
228
209
    return revisions