83
83
remote_branch.lock_read()
85
local_rev_history, local_rev_history_map, local_ancestry = \
86
_get_data(local_branch, progress, "local", 0)
87
remote_rev_history, remote_rev_history_map, remote_ancestry = \
88
_get_data(remote_branch, progress, "remote", 2)
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
98
local_ancestry = _get_ancestry(local_branch, progress, "local",
100
remote_ancestry = _get_ancestry(remote_branch, progress, "remote",
101
3, remote_rev_history)
89
102
progress.update('pondering', 4, 5)
90
103
extras = local_ancestry.symmetric_difference(remote_ancestry)
91
104
local_extra = extras.intersection(set(local_rev_history))
102
115
return (local_extra, remote_extra)
105
def _get_data(branch, progress, label, offset):
106
progress.update('%s history' % label, 0+offset, 5)
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(), set(remote_rev_history[remote_rev_history.index(local_rev_history[-1])+1:])
126
elif remote_rev_history[-1] in local_history:
127
return set(local_rev_history[local_rev_history.index(remote_rev_history[-1])+1:]), set()
132
def _get_history(branch, progress, label, step):
133
progress.update('%s history' % label, step, 5)
107
134
rev_history = branch.revision_history()
108
135
rev_history_map = dict(
109
[(rev, rev_history.index(rev))
136
[(rev, rev_history.index(rev) + 1)
110
137
for rev in rev_history])
111
progress.update('%s ancestry' % label, 1+offset, 5)
138
return rev_history, rev_history_map
140
def _get_ancestry(branch, progress, label, step, rev_history):
141
progress.update('%s ancestry' % label, step, 5)
112
142
if len(rev_history) > 0:
113
143
ancestry = set(branch.get_ancestry(rev_history[-1]))
116
return rev_history, rev_history_map, ancestry
119
149
def sorted_revisions(revisions, history_map):