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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
"""Display what revisions are missing in 'other' from 'this' and vice versa."""
19
from __future__ import absolute_import
19
21
from bzrlib import (
21
repository as _mod_repository,
24
25
import bzrlib.revision as _mod_revision
27
def iter_log_revisions(revisions, revision_source, verbose):
28
def iter_log_revisions(revisions, revision_source, verbose, rev_tag_dict=None):
28
29
last_tree = revision_source.revision_tree(_mod_revision.NULL_REVISION)
32
if rev_tag_dict is None:
30
34
for rev in revisions:
31
35
# We need the following for backward compatibilty (hopefully
32
36
# this will be deprecated soon :-/) -- vila 080911
37
41
revno, rev_id, merge_depth = rev
38
42
rev = revision_source.get_revision(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)
44
delta = revision_source.get_revision_delta(rev_id)
52
yield log.LogRevision(rev, revno, merge_depth, delta=delta)
47
yield log.LogRevision(rev, revno, merge_depth, delta=delta,
48
tags=rev_tag_dict.get(rev_id))
55
51
def find_unmerged(local_branch, remote_branch, restrict='all',
56
include_merges=False, backward=False):
52
include_merged=None, backward=False,
53
local_revid_range=None, remote_revid_range=None,
54
include_merges=symbol_versioning.DEPRECATED_PARAMETER):
57
55
"""Find revisions from each side that have not been merged.
59
57
:param local_branch: Compare the history of local_branch
63
61
unique revisions from both sides. If 'local', we will return None
64
62
for the remote revisions, similarly if 'remote' we will return None for
65
63
the local revisions.
66
:param include_merges: Show mainline revisions only if False,
64
:param include_merged: Show mainline revisions only if False,
67
65
all revisions otherwise.
68
66
:param backward: Show oldest versions first when True, newest versions
68
:param local_revid_range: Revision-id range for filtering local_branch
69
revisions (lower bound, upper bound)
70
:param remote_revid_range: Revision-id range for filtering remote_branch
71
revisions (lower bound, upper bound)
72
:param include_merges: Deprecated historical alias for include_merged
71
74
:return: A list of [(revno, revision_id)] for the mainline revisions on
77
if symbol_versioning.deprecated_passed(include_merges):
78
symbol_versioning.warn(
79
'include_merges was deprecated in 2.5.'
80
' Use include_merged instead.',
81
DeprecationWarning, stacklevel=2)
82
if include_merged is None:
83
include_merged = include_merges
84
if include_merged is None:
85
include_merged = False
74
86
local_branch.lock_read()
76
88
remote_branch.lock_read()
78
90
return _find_unmerged(
79
91
local_branch, remote_branch, restrict=restrict,
80
include_merges=include_merges, backward=backward)
92
include_merged=include_merged, backward=backward,
93
local_revid_range=local_revid_range,
94
remote_revid_range=remote_revid_range)
82
96
remote_branch.unlock()
92
106
:param tip_revno: The revision number for the tip revision
93
107
:param tip: The tip of mainline
94
108
:param backward: Show oldest versions first when True, newest versions
96
110
:return: [(revno, revision_id)] for all revisions in ancestry that
97
111
are left-hand parents from tip, or None if ancestry is None.
131
145
:param tip_revno: The revision number for the tip revision
132
146
:param tip: The tip of the ancsetry
133
147
:param backward: Show oldest versions first when True, newest versions
135
149
:return: [(revno, revision_id)] for all revisions in ancestry that
136
150
are parents from tip, or None if ancestry is None.
140
154
if not ancestry: #Empty ancestry, no need to do any work
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,
157
merge_sorted_revisions = branch.iter_merge_sorted_revisions()
164
158
# Now that we got the correct revnos, keep only the relevant
166
160
merge_sorted_revisions = [
167
(s, revid, n, d, e) for s, revid, n, d, e in merge_sorted_revisions
161
# log.reverse_by_depth expects seq_num to be present, but it is
162
# stripped by iter_merge_sorted_revisions()
163
(0, revid, n, d, e) for revid, n, d, e in merge_sorted_revisions
168
164
if revid in ancestry]
170
166
merge_sorted_revisions = log.reverse_by_depth(merge_sorted_revisions)
173
def _filter_revs(graph, revs, revid_range):
174
if revid_range is None or revs is None:
176
return [rev for rev in revs
177
if graph.is_between(rev[1], revid_range[0], revid_range[1])]
177
180
def _find_unmerged(local_branch, remote_branch, restrict,
178
include_merges, backward):
181
include_merged, backward,
182
local_revid_range=None, remote_revid_range=None):
179
183
"""See find_unmerged.
181
185
The branches should already be locked before entering.
200
204
' "remote": %r' % (restrict,))
201
205
local_extra, remote_extra = graph.find_difference(local_revision_id,
202
206
remote_revision_id)
204
208
locals = _enumerate_with_merges(local_branch, local_extra,
205
209
graph, local_revno,
206
210
local_revision_id, backward)
214
218
local_revision_id, backward)
215
219
remotes = _enumerate_mainline(remote_extra, graph, remote_revno,
216
220
remote_revision_id, backward)
217
return locals, remotes
221
return _filter_revs(graph, locals, local_revid_range), _filter_revs(graph,
222
remotes, remote_revid_range)
220
225
def sorted_revisions(revisions, history_map):