53
53
# TODO: option to show delta summaries for merged-in revisions
56
from bzrlib.delta import compare_trees
55
57
import bzrlib.errors as errors
58
from bzrlib.trace import mutter
56
59
from bzrlib.tree import EmptyTree
57
from bzrlib.delta import compare_trees
58
from bzrlib.trace import mutter
60
from bzrlib.tsort import merge_sort
62
63
def find_touching_revisions(branch, file_id):
203
204
# list indexes are 0-based; revisions are 1-based
204
205
cut_revs = which_revs[(start_revision-1):(end_revision)]
208
# override the mainline to look like the revision history.
209
mainline_revs = [revision_id for index, revision_id in cut_revs]
210
if cut_revs[0][0] == 1:
211
mainline_revs.insert(0, None)
213
mainline_revs.insert(0, which_revs[start_revision-2][1])
215
merge_sorted_revisions = merge_sort(
216
branch.repository.get_revision_graph(mainline_revs[-1]),
206
220
if direction == 'reverse':
207
221
cut_revs.reverse()
208
222
elif direction == 'forward':
223
# forward means oldest first.
224
merge_sorted_revisions.reverse()
211
226
raise ValueError('invalid direction %r' % direction)
213
228
revision_history = branch.revision_history()
214
for revno, rev_id in cut_revs:
215
if verbose or specific_fileid:
216
delta = _get_revision_delta(branch, revno)
219
if not delta.touches_file_id(specific_fileid):
223
# although we calculated it, throw it away without display
230
# convert the revision history to a dictionary:
232
for index, rev_id in cut_revs:
233
rev_nos[rev_id] = index
235
# now we just print all the revisions
236
for sequence, rev_id, merge_depth, end_of_merge in merge_sorted_revisions:
226
237
rev = branch.repository.get_revision(rev_id)
229
240
if not searchRE.search(rev.message):
232
lf.show(revno, rev, delta)
233
if hasattr(lf, 'show_merge'):
237
# revno is 1 based, so -2 to get back 1 less.
238
repository = branch.repository
239
excludes = repository.get_ancestry(revision_history[revno - 2])
240
excludes = set(excludes)
241
pending = list(rev.parent_ids)
243
rev_id = pending.pop()
244
if rev_id in excludes:
246
# prevent showing merged revs twice if they multi-path.
249
rev = branch.repository.get_revision(rev_id)
250
except errors.NoSuchRevision:
252
pending.extend(rev.parent_ids)
244
# a mainline revision.
245
if verbose or specific_fileid:
246
delta = _get_revision_delta(branch, rev_nos[rev_id])
249
if not delta.touches_file_id(specific_fileid):
253
# although we calculated it, throw it away without display
256
lf.show(rev_nos[rev_id], rev, delta)
257
elif hasattr(lf, 'show_merge'):
258
lf.show_merge(rev, merge_depth)
256
261
def deltas_for_log_dummy(branch, which_revs):
354
359
def show(self, revno, rev, delta):
355
360
return self._show_helper(revno=revno, rev=rev, delta=delta)
357
def show_merge(self, rev):
358
return self._show_helper(rev=rev, indent=' ', merged=True, delta=None)
362
def show_merge(self, rev, merge_depth):
363
return self._show_helper(rev=rev, indent=' '*merge_depth, merged=True, delta=None)
360
365
def _show_helper(self, rev=None, revno=None, indent='', merged=False, delta=None):
361
"""Show a revision, either merged or not."""
366
"""Show a revision, either merged or not."""
362
367
from bzrlib.osutils import format_date
363
368
to_file = self.to_file
364
369
print >>to_file, indent+'-' * 60