~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/missing.py

Removed merge fix with no test case

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
"""\
2
2
A plugin for displaying what revisions are in 'other' but not in local.
3
3
"""
4
 
 
 
4
from bzrlib.ui import ui_factory
5
5
def show_missing(br_local, br_remote, verbose=False, quiet=False):
6
6
    """Show the revisions which exist in br_remote, that 
7
7
    do not exist in br_local.
75
75
        show_one_log(revno, rev, delta, verbose, sys.stdout, 'original')
76
76
    return 1
77
77
 
 
78
 
 
79
def find_unmerged(local_branch, remote_branch):
 
80
    progress = ui_factory.progress_bar()
 
81
    local_branch.lock_read()
 
82
    try:
 
83
        remote_branch.lock_read()
 
84
        try:
 
85
            local_rev_history, local_rev_history_map = \
 
86
                _get_history(local_branch, progress, "local", 0)
 
87
            remote_rev_history, remote_rev_history_map = \
 
88
                _get_history(remote_branch, progress, "remote", 1)
 
89
            result = _shortcut(local_rev_history, remote_rev_history)
 
90
            if result is not None:
 
91
                local_extra, remote_extra = result
 
92
                local_extra = sorted_revisions(local_extra, 
 
93
                                               local_rev_history_map)
 
94
                remote_extra = sorted_revisions(remote_extra, 
 
95
                                                remote_rev_history_map)
 
96
                return local_extra, remote_extra
 
97
 
 
98
            local_ancestry = _get_ancestry(local_branch, progress, "local",
 
99
                                           2, local_rev_history)
 
100
            remote_ancestry = _get_ancestry(remote_branch, progress, "remote",
 
101
                                            3, remote_rev_history)
 
102
            progress.update('pondering', 4, 5)
 
103
            extras = local_ancestry.symmetric_difference(remote_ancestry) 
 
104
            local_extra = extras.intersection(set(local_rev_history))
 
105
            remote_extra = extras.intersection(set(remote_rev_history))
 
106
            local_extra = sorted_revisions(local_extra, local_rev_history_map)
 
107
            remote_extra = sorted_revisions(remote_extra, 
 
108
                                            remote_rev_history_map)
 
109
                    
 
110
        finally:
 
111
            remote_branch.unlock()
 
112
    finally:
 
113
        local_branch.unlock()
 
114
        progress.clear()
 
115
    return (local_extra, remote_extra)
 
116
 
 
117
def _shortcut(local_rev_history, remote_rev_history):
 
118
    local_history = set(local_rev_history)
 
119
    remote_history = set(remote_rev_history)
 
120
    if len(local_rev_history) == 0:
 
121
        return set(), remote_history
 
122
    elif len(remote_rev_history) == 0:
 
123
        return local_history, set()
 
124
    elif local_rev_history[-1] in remote_history:
 
125
        return set(), _after(remote_rev_history, local_rev_history)
 
126
    elif remote_rev_history[-1] in local_history:
 
127
        return _after(local_rev_history, remote_rev_history), set()
 
128
    else:
 
129
        return None
 
130
 
 
131
def _after(larger_history, smaller_history):
 
132
    return set(larger_history[larger_history.index(smaller_history[-1])+1:])
 
133
 
 
134
def _get_history(branch, progress, label, step):
 
135
    progress.update('%s history' % label, step, 5)
 
136
    rev_history = branch.revision_history()
 
137
    rev_history_map = dict(
 
138
        [(rev, rev_history.index(rev) + 1)
 
139
         for rev in rev_history])
 
140
    return rev_history, rev_history_map
 
141
 
 
142
def _get_ancestry(branch, progress, label, step, rev_history):
 
143
    progress.update('%s ancestry' % label, step, 5)
 
144
    if len(rev_history) > 0:
 
145
        ancestry = set(branch.get_ancestry(rev_history[-1]))
 
146
    else:
 
147
        ancestry = set()
 
148
    return ancestry
 
149
    
 
150
 
 
151
def sorted_revisions(revisions, history_map):
 
152
    revisions = [(history_map[r],r) for r in revisions]
 
153
    revisions.sort()
 
154
    return revisions