43
42
yield LogRevision(rev, revno, delta=delta)
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()
50
48
remote_branch.lock_read()
52
# check for special case: both branches are equivalent
53
if (local_branch.last_revision_info() ==
54
remote_branch.last_revision_info()):
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
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)
50
return _find_unmerged(local_branch,
51
remote_branch, restrict=restrict)
82
53
remote_branch.unlock()
84
55
local_branch.unlock()
86
return (local_extra, remote_extra)
89
58
def _enumerate_mainline(ancestry, graph, tip_revno, tip):
101
70
if not ancestry: #Empty ancestry, no need to do any work
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
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)
114
84
break # Ghost, we are done
115
85
mainline.append((cur_revno, cur))
116
cur = parent_map[cur]
118
88
mainline.reverse()
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.
125
95
Both branches should already be locked.
165
135
return local_mainline, remote_mainline
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()
182
def _after(larger_history, smaller_history):
183
return set(larger_history[larger_history.index(smaller_history[-1])+1:])
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
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],
203
138
def sorted_revisions(revisions, history_map):
204
139
revisions = [(history_map[r],r) for r in revisions]