/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 Arbash Meinel
  • Date: 2008-05-19 21:35:52 UTC
  • mto: This revision was merged to the branch mainline in revision 3441.
  • Revision ID: john@arbash-meinel.com-20080519213552-8jc1yc4w8rqhgzri
switch find_unmerged to use the new function

The api is very compatible, so we don't really need to expose a new function.
So make it hidden, and leave find_unmerged to take out the write lock and call it.

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 ui
20
19
from bzrlib.log import (
21
20
    LogRevision,
22
21
    )
43
42
        yield LogRevision(rev, revno, delta=delta)
44
43
 
45
44
 
46
 
def find_unmerged(local_branch, remote_branch):
47
 
    progress = ui.ui_factory.nested_progress_bar()
 
45
def find_unmerged(local_branch, remote_branch, restrict='all'):
48
46
    local_branch.lock_read()
49
47
    try:
50
48
        remote_branch.lock_read()
51
49
        try:
52
 
            # check for special case: both branches are equivalent
53
 
            if (local_branch.last_revision_info() ==
54
 
                remote_branch.last_revision_info()):
55
 
                return [], []
56
 
            local_rev_history, local_rev_history_map = \
57
 
                _get_history(local_branch, progress, "local", 0)
58
 
            remote_rev_history, remote_rev_history_map = \
59
 
                _get_history(remote_branch, progress, "remote", 1)
60
 
            result = _shortcut(local_rev_history, remote_rev_history)
61
 
            if result is not None:
62
 
                local_extra, remote_extra = result
63
 
                local_extra = sorted_revisions(local_extra, 
64
 
                                               local_rev_history_map)
65
 
                remote_extra = sorted_revisions(remote_extra, 
66
 
                                                remote_rev_history_map)
67
 
                return local_extra, remote_extra
68
 
 
69
 
            local_ancestry = _get_ancestry(local_branch.repository, progress, 
70
 
                                           "local", 2, local_rev_history)
71
 
            remote_ancestry = _get_ancestry(remote_branch.repository, progress,
72
 
                                            "remote", 3, remote_rev_history)
73
 
            progress.update('pondering', 4, 5)
74
 
            extras = local_ancestry.symmetric_difference(remote_ancestry) 
75
 
            local_extra = extras.intersection(set(local_rev_history))
76
 
            remote_extra = extras.intersection(set(remote_rev_history))
77
 
            local_extra = sorted_revisions(local_extra, local_rev_history_map)
78
 
            remote_extra = sorted_revisions(remote_extra, 
79
 
                                            remote_rev_history_map)
80
 
                    
 
50
            return _find_unmerged(local_branch,
 
51
                remote_branch, restrict=restrict)
81
52
        finally:
82
53
            remote_branch.unlock()
83
54
    finally:
84
55
        local_branch.unlock()
85
 
        progress.finished()
86
 
    return (local_extra, remote_extra)
87
56
 
88
57
 
89
58
def _enumerate_mainline(ancestry, graph, tip_revno, tip):
101
70
    if not ancestry: #Empty ancestry, no need to do any work
102
71
        return []
103
72
 
104
 
    # Optionally we could make 1 call to graph.get_parent_map with all
 
73
    # Optionally, we could make 1 call to graph.get_parent_map with all
105
74
    # ancestors. However that will often check many more parents than we
106
75
    # actually need, and the Graph is likely to already have the parents cached
107
76
    # anyway.
110
79
    cur_revno = tip_revno
111
80
    while cur in ancestry:
112
81
        parent_map = graph.get_parent_map([cur])
113
 
        if cur not in parent_map:
 
82
        parents = parent_map.get(cur)
 
83
        if not parents:
114
84
            break # Ghost, we are done
115
85
        mainline.append((cur_revno, cur))
116
 
        cur = parent_map[cur]
 
86
        cur = parents[0]
117
87
        cur_revno -= 1
118
88
    mainline.reverse()
119
89
    return mainline
120
90
 
121
91
 
122
 
def find_unmerged_mainline_revisions(local_branch, remote_branch, restrict):
 
92
def _find_unmerged(local_branch, remote_branch, restrict):
123
93
    """Find revisions from each side that have not been merged.
124
94
 
125
95
    Both branches should already be locked.
165
135
    return local_mainline, remote_mainline
166
136
 
167
137
 
168
 
def _shortcut(local_rev_history, remote_rev_history):
169
 
    local_history = set(local_rev_history)
170
 
    remote_history = set(remote_rev_history)
171
 
    if len(local_rev_history) == 0:
172
 
        return set(), remote_history
173
 
    elif len(remote_rev_history) == 0:
174
 
        return local_history, set()
175
 
    elif local_rev_history[-1] in remote_history:
176
 
        return set(), _after(remote_rev_history, local_rev_history)
177
 
    elif remote_rev_history[-1] in local_history:
178
 
        return _after(local_rev_history, remote_rev_history), set()
179
 
    else:
180
 
        return None
181
 
 
182
 
def _after(larger_history, smaller_history):
183
 
    return set(larger_history[larger_history.index(smaller_history[-1])+1:])
184
 
 
185
 
def _get_history(branch, progress, label, step):
186
 
    progress.update('%s history' % label, step, 5)
187
 
    rev_history = branch.revision_history()
188
 
    rev_history_map = dict(
189
 
        [(rev, rev_history.index(rev) + 1)
190
 
         for rev in rev_history])
191
 
    return rev_history, rev_history_map
192
 
 
193
 
def _get_ancestry(repository, progress, label, step, rev_history):
194
 
    progress.update('%s ancestry' % label, step, 5)
195
 
    if len(rev_history) > 0:
196
 
        ancestry = set(repository.get_ancestry(rev_history[-1],
197
 
                       topo_sorted=False))
198
 
    else:
199
 
        ancestry = set()
200
 
    return ancestry
201
 
    
202
 
 
203
138
def sorted_revisions(revisions, history_map):
204
139
    revisions = [(history_map[r],r) for r in revisions]
205
140
    revisions.sort()