/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: Jelmer Vernooij
  • Date: 2020-04-05 19:11:34 UTC
  • mto: (7490.7.16 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200405191134-0aebh8ikiwygxma5
Populate the .gitignore file.

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