/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: John Ferlito
  • Date: 2009-09-02 04:31:45 UTC
  • mto: (4665.7.1 serve-init)
  • mto: This revision was merged to the branch mainline in revision 4913.
  • Revision ID: johnf@inodes.org-20090902043145-gxdsfw03ilcwbyn5
Add a debian init script for bzr --serve

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