13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
17
"""Display what revisions are missing in 'other' from 'this' and vice versa."""
19
19
from bzrlib import (
21
repository as _mod_repository,
22
24
import bzrlib.revision as _mod_revision
35
37
revno, rev_id, merge_depth = rev
36
38
rev = revision_source.get_revision(rev_id)
38
delta = revision_source.get_revision_delta(rev_id)
40
remote_tree = revision_source.revision_tree(rev_id)
41
parent_rev_id = rev.parent_ids[0]
42
if last_rev_id == parent_rev_id:
43
parent_tree = last_tree
45
parent_tree = revision_source.revision_tree(parent_rev_id)
46
revision_tree = revision_source.revision_tree(rev_id)
48
last_tree = revision_tree
49
delta = revision_tree.changes_from(parent_tree)
41
52
yield log.LogRevision(rev, revno, merge_depth, delta=delta)
44
55
def find_unmerged(local_branch, remote_branch, restrict='all',
45
include_merges=False, backward=False,
46
local_revid_range=None, remote_revid_range=None):
56
include_merges=False, backward=False):
47
57
"""Find revisions from each side that have not been merged.
49
59
:param local_branch: Compare the history of local_branch
56
66
:param include_merges: Show mainline revisions only if False,
57
67
all revisions otherwise.
58
68
:param backward: Show oldest versions first when True, newest versions
60
:param local_revid_range: Revision-id range for filtering local_branch
61
revisions (lower bound, upper bound)
62
:param remote_revid_range: Revision-id range for filtering remote_branch
63
revisions (lower bound, upper bound)
65
71
:return: A list of [(revno, revision_id)] for the mainline revisions on
72
78
return _find_unmerged(
73
79
local_branch, remote_branch, restrict=restrict,
74
include_merges=include_merges, backward=backward,
75
local_revid_range=local_revid_range,
76
remote_revid_range=remote_revid_range)
80
include_merges=include_merges, backward=backward)
78
82
remote_branch.unlock()
88
92
:param tip_revno: The revision number for the tip revision
89
93
:param tip: The tip of mainline
90
94
:param backward: Show oldest versions first when True, newest versions
92
96
:return: [(revno, revision_id)] for all revisions in ancestry that
93
97
are left-hand parents from tip, or None if ancestry is None.
127
131
:param tip_revno: The revision number for the tip revision
128
132
:param tip: The tip of the ancsetry
129
133
:param backward: Show oldest versions first when True, newest versions
131
135
:return: [(revno, revision_id)] for all revisions in ancestry that
132
136
are parents from tip, or None if ancestry is None.
136
140
if not ancestry: #Empty ancestry, no need to do any work
139
merge_sorted_revisions = branch.iter_merge_sorted_revisions()
143
mainline_revs, rev_nos, start_rev_id, end_rev_id = log._get_mainline_revs(
144
branch, None, tip_revno)
145
if not mainline_revs:
148
# This asks for all mainline revisions, which is size-of-history and
149
# should be addressed (but currently the only way to get correct
152
# mainline_revisions always includes an extra revision at the
153
# beginning, so don't request it.
154
parent_map = dict(((key, value) for key, value
155
in graph.iter_ancestry(mainline_revs[1:])
156
if value is not None))
157
# filter out ghosts; merge_sort errors on ghosts.
158
# XXX: is this needed here ? -- vila080910
159
rev_graph = _mod_repository._strip_NULL_ghosts(parent_map)
160
# XXX: what if rev_graph is empty now ? -- vila080910
161
merge_sorted_revisions = tsort.merge_sort(rev_graph, tip,
140
164
# Now that we got the correct revnos, keep only the relevant
142
166
merge_sorted_revisions = [
143
# log.reverse_by_depth expects seq_num to be present, but it is
144
# stripped by iter_merge_sorted_revisions()
145
(0, revid, n, d, e) for revid, n, d, e in merge_sorted_revisions
167
(s, revid, n, d, e) for s, revid, n, d, e in merge_sorted_revisions
146
168
if revid in ancestry]
148
170
merge_sorted_revisions = log.reverse_by_depth(merge_sorted_revisions)
155
def _filter_revs(graph, revs, revid_range):
156
if revid_range is None or revs is None:
158
return [rev for rev in revs
159
if graph.is_between(rev[1], revid_range[0], revid_range[1])]
162
177
def _find_unmerged(local_branch, remote_branch, restrict,
163
include_merges, backward,
164
local_revid_range=None, remote_revid_range=None):
178
include_merges, backward):
165
179
"""See find_unmerged.
167
181
The branches should already be locked before entering.
200
214
local_revision_id, backward)
201
215
remotes = _enumerate_mainline(remote_extra, graph, remote_revno,
202
216
remote_revision_id, backward)
203
return _filter_revs(graph, locals, local_revid_range), _filter_revs(graph,
204
remotes, remote_revid_range)
217
return locals, remotes
207
220
def sorted_revisions(revisions, history_map):