169
188
direction='reverse',
170
189
start_revision=None,
171
190
end_revision=None,
173
193
"""Worker function for show_log - see show_log."""
174
from bzrlib.osutils import format_date
175
from bzrlib.errors import BzrCheckError
176
from bzrlib.textui import show_status
178
from warnings import warn
180
194
if not isinstance(lf, LogFormatter):
181
195
warn("not a LogFormatter instance: %r" % lf)
183
197
if specific_fileid:
184
mutter('get log for file_id %r', specific_fileid)
186
if search is not None:
188
searchRE = re.compile(search, re.IGNORECASE)
198
trace.mutter('get log for file_id %r', specific_fileid)
199
generate_merge_revisions = getattr(lf, 'supports_merge_revisions', False)
200
allow_single_merge_revision = getattr(lf,
201
'supports_single_merge_revision', False)
202
view_revisions = calculate_view_revisions(branch, start_revision,
203
end_revision, direction,
205
generate_merge_revisions,
206
allow_single_merge_revision)
208
generate_tags = getattr(lf, 'supports_tags', False)
210
if branch.supports_tags():
211
rev_tag_dict = branch.tags.get_reverse_tag_dict()
213
generate_delta = verbose and getattr(lf, 'supports_delta', False)
215
# now we just print all the revisions
217
revision_iterator = make_log_rev_iterator(branch, view_revisions,
218
generate_delta, search)
219
for revs in revision_iterator:
220
for (rev_id, revno, merge_depth), rev, delta in revs:
221
lr = LogRevision(rev, revno, merge_depth, delta,
222
rev_tag_dict.get(rev_id))
226
if log_count >= limit:
230
def calculate_view_revisions(branch, start_revision, end_revision, direction,
231
specific_fileid, generate_merge_revisions,
232
allow_single_merge_revision):
233
if ( not generate_merge_revisions
234
and start_revision is end_revision is None
235
and direction == 'reverse'
236
and specific_fileid is None):
237
return _linear_view_revisions(branch)
239
mainline_revs, rev_nos, start_rev_id, end_rev_id = _get_mainline_revs(
240
branch, start_revision, end_revision)
241
if not mainline_revs:
244
generate_single_revision = False
245
if ((not generate_merge_revisions)
246
and ((start_rev_id and (start_rev_id not in rev_nos))
247
or (end_rev_id and (end_rev_id not in rev_nos)))):
248
generate_single_revision = ((start_rev_id == end_rev_id)
249
and allow_single_merge_revision)
250
if not generate_single_revision:
251
raise errors.BzrCommandError('Selected log formatter only supports'
252
' mainline revisions.')
253
generate_merge_revisions = generate_single_revision
254
include_merges = generate_merge_revisions or specific_fileid
255
view_revs_iter = get_view_revisions(mainline_revs, rev_nos, branch,
256
direction, include_merges=include_merges)
258
if direction == 'reverse':
259
start_rev_id, end_rev_id = end_rev_id, start_rev_id
260
view_revisions = _filter_revision_range(list(view_revs_iter),
263
if view_revisions and generate_single_revision:
264
view_revisions = view_revisions[0:1]
266
view_revisions = _filter_revisions_touching_file_id(branch,
267
specific_fileid, view_revisions,
268
include_merges=generate_merge_revisions)
270
# rebase merge_depth - unless there are no revisions or
271
# either the first or last revision have merge_depth = 0.
272
if view_revisions and view_revisions[0][2] and view_revisions[-1][2]:
273
min_depth = min([d for r,n,d in view_revisions])
275
view_revisions = [(r,n,d-min_depth) for r,n,d in view_revisions]
276
return view_revisions
279
def _linear_view_revisions(branch):
280
start_revno, start_revision_id = branch.last_revision_info()
281
repo = branch.repository
282
revision_ids = repo.iter_reverse_revision_history(start_revision_id)
283
for num, revision_id in enumerate(revision_ids):
284
yield revision_id, str(start_revno - num), 0
287
def make_log_rev_iterator(branch, view_revisions, generate_delta, search):
288
"""Create a revision iterator for log.
290
:param branch: The branch being logged.
291
:param view_revisions: The revisions being viewed.
292
:param generate_delta: Whether to generate a delta for each revision.
293
:param search: A user text search string.
294
:return: An iterator over lists of ((rev_id, revno, merge_depth), rev,
297
# Convert view_revisions into (view, None, None) groups to fit with
298
# the standard interface here.
299
if type(view_revisions) == list:
300
# A single batch conversion is faster than many incremental ones.
301
# As we have all the data, do a batch conversion.
302
nones = [None] * len(view_revisions)
303
log_rev_iterator = iter([zip(view_revisions, nones, nones)])
192
which_revs = _enumerate_history(branch)
306
for view in view_revisions:
307
yield (view, None, None)
308
log_rev_iterator = iter([_convert()])
309
for adapter in log_adapters:
310
log_rev_iterator = adapter(branch, generate_delta, search,
312
return log_rev_iterator
315
def _make_search_filter(branch, generate_delta, search, log_rev_iterator):
316
"""Create a filtered iterator of log_rev_iterator matching on a regex.
318
:param branch: The branch being logged.
319
:param generate_delta: Whether to generate a delta for each revision.
320
:param search: A user text search string.
321
:param log_rev_iterator: An input iterator containing all revisions that
322
could be displayed, in lists.
323
:return: An iterator over lists of ((rev_id, revno, merge_depth), rev,
327
return log_rev_iterator
328
# Compile the search now to get early errors.
329
searchRE = re.compile(search, re.IGNORECASE)
330
return _filter_message_re(searchRE, log_rev_iterator)
333
def _filter_message_re(searchRE, log_rev_iterator):
334
for revs in log_rev_iterator:
336
for (rev_id, revno, merge_depth), rev, delta in revs:
337
if searchRE.search(rev.message):
338
new_revs.append(((rev_id, revno, merge_depth), rev, delta))
342
def _make_delta_filter(branch, generate_delta, search, log_rev_iterator):
343
"""Add revision deltas to a log iterator if needed.
345
:param branch: The branch being logged.
346
:param generate_delta: Whether to generate a delta for each revision.
347
:param search: A user text search string.
348
:param log_rev_iterator: An input iterator containing all revisions that
349
could be displayed, in lists.
350
:return: An iterator over lists of ((rev_id, revno, merge_depth), rev,
353
if not generate_delta:
354
return log_rev_iterator
355
return _generate_deltas(branch.repository, log_rev_iterator)
358
def _generate_deltas(repository, log_rev_iterator):
359
"""Create deltas for each batch of revisions in log_rev_iterator."""
360
for revs in log_rev_iterator:
361
revisions = [rev[1] for rev in revs]
362
deltas = repository.get_deltas_for_revisions(revisions)
363
revs = [(rev[0], rev[1], delta) for rev, delta in izip(revs, deltas)]
367
def _make_revision_objects(branch, generate_delta, search, log_rev_iterator):
368
"""Extract revision objects from the repository
370
:param branch: The branch being logged.
371
:param generate_delta: Whether to generate a delta for each revision.
372
:param search: A user text search string.
373
:param log_rev_iterator: An input iterator containing all revisions that
374
could be displayed, in lists.
375
:return: An iterator over lists of ((rev_id, revno, merge_depth), rev,
378
repository = branch.repository
379
for revs in log_rev_iterator:
380
# r = revision_id, n = revno, d = merge depth
381
revision_ids = [view[0] for view, _, _ in revs]
382
revisions = repository.get_revisions(revision_ids)
383
revs = [(rev[0], revision, rev[2]) for rev, revision in
384
izip(revs, revisions)]
388
def _make_batch_filter(branch, generate_delta, search, log_rev_iterator):
389
"""Group up a single large batch into smaller ones.
391
:param branch: The branch being logged.
392
:param generate_delta: Whether to generate a delta for each revision.
393
:param search: A user text search string.
394
:param log_rev_iterator: An input iterator containing all revisions that
395
could be displayed, in lists.
396
:return: An iterator over lists of ((rev_id, revno, merge_depth), rev,
399
repository = branch.repository
401
for batch in log_rev_iterator:
404
step = [detail for _, detail in zip(range(num), batch)]
408
num = min(int(num * 1.5), 200)
411
def _get_mainline_revs(branch, start_revision, end_revision):
412
"""Get the mainline revisions from the branch.
414
Generates the list of mainline revisions for the branch.
416
:param branch: The branch containing the revisions.
418
:param start_revision: The first revision to be logged.
419
For backwards compatibility this may be a mainline integer revno,
420
but for merge revision support a RevisionInfo is expected.
422
:param end_revision: The last revision to be logged.
423
For backwards compatibility this may be a mainline integer revno,
424
but for merge revision support a RevisionInfo is expected.
426
:return: A (mainline_revs, rev_nos, start_rev_id, end_rev_id) tuple.
428
branch_revno, branch_last_revision = branch.last_revision_info()
429
if branch_revno == 0:
430
return None, None, None, None
432
# For mainline generation, map start_revision and end_revision to
433
# mainline revnos. If the revision is not on the mainline choose the
434
# appropriate extreme of the mainline instead - the extra will be
436
# Also map the revisions to rev_ids, to be used in the later filtering
194
439
if start_revision is None:
197
branch.check_real_revno(start_revision)
442
if isinstance(start_revision, revisionspec.RevisionInfo):
443
start_rev_id = start_revision.rev_id
444
start_revno = start_revision.revno or 1
446
branch.check_real_revno(start_revision)
447
start_revno = start_revision
199
450
if end_revision is None:
200
end_revision = len(which_revs)
202
branch.check_real_revno(end_revision)
204
# list indexes are 0-based; revisions are 1-based
205
cut_revs = which_revs[(start_revision-1):(end_revision)]
451
end_revno = branch_revno
453
if isinstance(end_revision, revisionspec.RevisionInfo):
454
end_rev_id = end_revision.rev_id
455
end_revno = end_revision.revno or branch_revno
457
branch.check_real_revno(end_revision)
458
end_revno = end_revision
460
if ((start_rev_id == _mod_revision.NULL_REVISION)
461
or (end_rev_id == _mod_revision.NULL_REVISION)):
462
raise errors.BzrCommandError('Logging revision 0 is invalid.')
463
if start_revno > end_revno:
464
raise errors.BzrCommandError("Start revision must be older than "
467
if end_revno < start_revno:
468
return None, None, None, None
469
cur_revno = branch_revno
472
for revision_id in branch.repository.iter_reverse_revision_history(
473
branch_last_revision):
474
if cur_revno < start_revno:
475
# We have gone far enough, but we always add 1 more revision
476
rev_nos[revision_id] = cur_revno
477
mainline_revs.append(revision_id)
479
if cur_revno <= end_revno:
480
rev_nos[revision_id] = cur_revno
481
mainline_revs.append(revision_id)
484
# We walked off the edge of all revisions, so we add a 'None' marker
485
mainline_revs.append(None)
487
mainline_revs.reverse()
208
489
# 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]),
490
return mainline_revs, rev_nos, start_rev_id, end_rev_id
493
def _filter_revision_range(view_revisions, start_rev_id, end_rev_id):
494
"""Filter view_revisions based on revision ranges.
496
:param view_revisions: A list of (revision_id, dotted_revno, merge_depth)
497
tuples to be filtered.
499
:param start_rev_id: If not NONE specifies the first revision to be logged.
500
If NONE then all revisions up to the end_rev_id are logged.
502
:param end_rev_id: If not NONE specifies the last revision to be logged.
503
If NONE then all revisions up to the end of the log are logged.
505
:return: The filtered view_revisions.
507
if start_rev_id or end_rev_id:
508
revision_ids = [r for r, n, d in view_revisions]
510
start_index = revision_ids.index(start_rev_id)
513
if start_rev_id == end_rev_id:
514
end_index = start_index
517
end_index = revision_ids.index(end_rev_id)
519
end_index = len(view_revisions) - 1
520
# To include the revisions merged into the last revision,
521
# extend end_rev_id down to, but not including, the next rev
522
# with the same or lesser merge_depth
523
end_merge_depth = view_revisions[end_index][2]
525
for index in xrange(end_index+1, len(view_revisions)+1):
526
if view_revisions[index][2] <= end_merge_depth:
527
end_index = index - 1
530
# if the search falls off the end then log to the end as well
531
end_index = len(view_revisions) - 1
532
view_revisions = view_revisions[start_index:end_index+1]
533
return view_revisions
536
def _filter_revisions_touching_file_id(branch, file_id, view_revisions,
537
include_merges=True):
538
r"""Return the list of revision ids which touch a given file id.
540
The function filters view_revisions and returns a subset.
541
This includes the revisions which directly change the file id,
542
and the revisions which merge these changes. So if the
554
And 'C' changes a file, then both C and D will be returned. F will not be
555
returned even though it brings the changes to C into the branch starting
556
with E. (Note that if we were using F as the tip instead of G, then we
559
This will also be restricted based on a subset of the mainline.
561
:param branch: The branch where we can get text revision information.
563
:param file_id: Filter out revisions that do not touch file_id.
565
:param view_revisions: A list of (revision_id, dotted_revno, merge_depth)
566
tuples. This is the list of revisions which will be filtered. It is
567
assumed that view_revisions is in merge_sort order (i.e. newest
570
:param include_merges: include merge revisions in the result or not
572
:return: A list of (revision_id, dotted_revno, merge_depth) tuples.
574
# Lookup all possible text keys to determine which ones actually modified
576
text_keys = [(file_id, rev_id) for rev_id, revno, depth in view_revisions]
577
# Looking up keys in batches of 1000 can cut the time in half, as well as
578
# memory consumption. GraphIndex *does* like to look for a few keys in
579
# parallel, it just doesn't like looking for *lots* of keys in parallel.
580
# TODO: This code needs to be re-evaluated periodically as we tune the
581
# indexing layer. We might consider passing in hints as to the known
582
# access pattern (sparse/clustered, high success rate/low success
583
# rate). This particular access is clustered with a low success rate.
584
get_parent_map = branch.repository.texts.get_parent_map
585
modified_text_revisions = set()
587
for start in xrange(0, len(text_keys), chunk_size):
588
next_keys = text_keys[start:start + chunk_size]
589
# Only keep the revision_id portion of the key
590
modified_text_revisions.update(
591
[k[1] for k in get_parent_map(next_keys)])
592
del text_keys, next_keys
595
# Track what revisions will merge the current revision, replace entries
596
# with 'None' when they have been added to result
597
current_merge_stack = [None]
598
for info in view_revisions:
599
rev_id, revno, depth = info
600
if depth == len(current_merge_stack):
601
current_merge_stack.append(info)
603
del current_merge_stack[depth + 1:]
604
current_merge_stack[-1] = info
606
if rev_id in modified_text_revisions:
607
# This needs to be logged, along with the extra revisions
608
for idx in xrange(len(current_merge_stack)):
609
node = current_merge_stack[idx]
611
if include_merges or node[2] == 0:
613
current_merge_stack[idx] = None
617
def get_view_revisions(mainline_revs, rev_nos, branch, direction,
618
include_merges=True):
619
"""Produce an iterator of revisions to show
620
:return: an iterator of (revision_id, revno, merge_depth)
621
(if there is no revno for a revision, None is supplied)
623
if not include_merges:
624
revision_ids = mainline_revs[1:]
625
if direction == 'reverse':
626
revision_ids.reverse()
627
for revision_id in revision_ids:
628
yield revision_id, str(rev_nos[revision_id]), 0
630
graph = branch.repository.get_graph()
631
# This asks for all mainline revisions, which means we only have to spider
632
# sideways, rather than depth history. That said, its still size-of-history
633
# and should be addressed.
634
# mainline_revisions always includes an extra revision at the beginning, so
636
parent_map = dict(((key, value) for key, value in
637
graph.iter_ancestry(mainline_revs[1:]) if value is not None))
638
# filter out ghosts; merge_sort errors on ghosts.
639
rev_graph = _mod_repository._strip_NULL_ghosts(parent_map)
640
merge_sorted_revisions = tsort.merge_sort(
217
642
mainline_revs[-1],
220
if direction == 'reverse':
222
elif direction == 'forward':
646
if direction == 'forward':
223
647
# forward means oldest first.
224
merge_sorted_revisions.reverse()
648
merge_sorted_revisions = reverse_by_depth(merge_sorted_revisions)
649
elif direction != 'reverse':
226
650
raise ValueError('invalid direction %r' % direction)
228
revision_history = branch.revision_history()
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:
237
rev = branch.repository.get_revision(rev_id)
240
if not searchRE.search(rev.message):
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)
261
def deltas_for_log_dummy(branch, which_revs):
262
"""Return all the revisions without intermediate deltas.
264
Useful for log commands that won't need the delta information.
267
for revno, revision_id in which_revs:
268
yield revno, branch.get_revision(revision_id), None
271
def deltas_for_log_reverse(branch, which_revs):
272
"""Compute deltas for display in latest-to-earliest order.
278
Sequence of (revno, revision_id) for the subset of history to examine
281
Sequence of (revno, rev, delta)
283
The delta is from the given revision to the next one in the
284
sequence, which makes sense if the log is being displayed from
287
last_revno = last_revision_id = last_tree = None
288
for revno, revision_id in which_revs:
289
this_tree = branch.revision_tree(revision_id)
290
this_revision = branch.get_revision(revision_id)
293
yield last_revno, last_revision, compare_trees(this_tree, last_tree, False)
295
this_tree = EmptyTree(branch.get_root_id())
298
last_revision = this_revision
299
last_tree = this_tree
303
this_tree = EmptyTree(branch.get_root_id())
652
for (sequence, rev_id, merge_depth, revno, end_of_merge
653
) in merge_sorted_revisions:
654
yield rev_id, '.'.join(map(str, revno)), merge_depth
657
def reverse_by_depth(merge_sorted_revisions, _depth=0):
658
"""Reverse revisions by depth.
660
Revisions with a different depth are sorted as a group with the previous
661
revision of that depth. There may be no topological justification for this,
662
but it looks much nicer.
664
# Add a fake revision at start so that we can always attach sub revisions
665
merge_sorted_revisions = [(None, None, _depth)] + merge_sorted_revisions
667
for val in merge_sorted_revisions:
669
# Each revision at the current depth becomes a chunk grouping all
670
# higher depth revisions.
671
zd_revisions.append([val])
305
this_revno = last_revno - 1
306
this_revision_id = branch.revision_history()[this_revno]
307
this_tree = branch.revision_tree(this_revision_id)
308
yield last_revno, last_revision, compare_trees(this_tree, last_tree, False)
311
def deltas_for_log_forward(branch, which_revs):
312
"""Compute deltas for display in forward log.
314
Given a sequence of (revno, revision_id) pairs, return
317
The delta is from the given revision to the next one in the
318
sequence, which makes sense if the log is being displayed from
673
zd_revisions[-1].append(val)
674
for revisions in zd_revisions:
675
if len(revisions) > 1:
676
# We have higher depth revisions, let reverse them locally
677
revisions[1:] = reverse_by_depth(revisions[1:], _depth + 1)
678
zd_revisions.reverse()
680
for chunk in zd_revisions:
683
# Top level call, get rid of the fake revisions that have been added
684
result = [r for r in result if r[0] is not None and r[1] is not None]
688
class LogRevision(object):
689
"""A revision to be logged (by LogFormatter.log_revision).
691
A simple wrapper for the attributes of a revision to be logged.
692
The attributes may or may not be populated, as determined by the
693
logging options and the log formatter capabilities.
321
last_revno = last_revision_id = last_tree = None
322
prev_tree = EmptyTree(branch.get_root_id())
324
for revno, revision_id in which_revs:
325
this_tree = branch.revision_tree(revision_id)
326
this_revision = branch.get_revision(revision_id)
330
last_tree = EmptyTree(branch.get_root_id())
332
last_revno = revno - 1
333
last_revision_id = branch.revision_history()[last_revno]
334
last_tree = branch.revision_tree(last_revision_id)
336
yield revno, this_revision, compare_trees(last_tree, this_tree, False)
339
last_revision = this_revision
340
last_tree = this_tree
696
def __init__(self, rev=None, revno=None, merge_depth=0, delta=None,
700
self.merge_depth = merge_depth
343
705
class LogFormatter(object):
344
"""Abstract class to display log messages."""
346
def __init__(self, to_file, show_ids=False, show_timezone='original'):
706
"""Abstract class to display log messages.
708
At a minimum, a derived class must implement the log_revision method.
710
If the LogFormatter needs to be informed of the beginning or end of
711
a log it should implement the begin_log and/or end_log hook methods.
713
A LogFormatter should define the following supports_XXX flags
714
to indicate which LogRevision attributes it supports:
716
- supports_delta must be True if this log formatter supports delta.
717
Otherwise the delta attribute may not be populated. The 'delta_format'
718
attribute describes whether the 'short_status' format (1) or the long
719
one (2) sould be used.
721
- supports_merge_revisions must be True if this log formatter supports
722
merge revisions. If not, and if supports_single_merge_revisions is
723
also not True, then only mainline revisions will be passed to the
725
- supports_single_merge_revision must be True if this log formatter
726
supports logging only a single merge revision. This flag is
727
only relevant if supports_merge_revisions is not True.
728
- supports_tags must be True if this log formatter supports tags.
729
Otherwise the tags attribute may not be populated.
731
Plugins can register functions to show custom revision properties using
732
the properties_handler_registry. The registered function
733
must respect the following interface description:
734
def my_show_properties(properties_dict):
735
# code that returns a dict {'name':'value'} of the properties
739
def __init__(self, to_file, show_ids=False, show_timezone='original',
347
741
self.to_file = to_file
348
742
self.show_ids = show_ids
349
743
self.show_timezone = show_timezone
744
if delta_format is None:
745
# Ensures backward compatibility
746
delta_format = 2 # long format
747
self.delta_format = delta_format
351
def show(self, revno, rev, delta):
352
raise NotImplementedError('not implemented in abstract base')
749
# TODO: uncomment this block after show() has been removed.
750
# Until then defining log_revision would prevent _show_log calling show()
751
# in legacy formatters.
752
# def log_revision(self, revision):
755
# :param revision: The LogRevision to be logged.
757
# raise NotImplementedError('not implemented in abstract base')
354
759
def short_committer(self, rev):
355
return re.sub('<.*@.*>', '', rev.committer).strip(' ')
760
name, address = config.parse_username(rev.committer)
765
def short_author(self, rev):
766
name, address = config.parse_username(rev.get_apparent_author())
771
def show_properties(self, revision, indent):
772
"""Displays the custom properties returned by each registered handler.
774
If a registered handler raises an error it is propagated.
776
for key, handler in properties_handler_registry.iteritems():
777
for key, value in handler(revision).items():
778
self.to_file.write(indent + key + ': ' + value + '\n')
358
781
class LongLogFormatter(LogFormatter):
359
def show(self, revno, rev, delta):
360
return self._show_helper(revno=revno, rev=rev, delta=delta)
362
def show_merge(self, rev, merge_depth):
363
return self._show_helper(rev=rev, indent=' '*merge_depth, merged=True, delta=None)
365
def _show_helper(self, rev=None, revno=None, indent='', merged=False, delta=None):
366
"""Show a revision, either merged or not."""
367
from bzrlib.osutils import format_date
783
supports_merge_revisions = True
784
supports_delta = True
787
def log_revision(self, revision):
788
"""Log a revision, either merged or not."""
789
indent = ' ' * revision.merge_depth
368
790
to_file = self.to_file
369
print >>to_file, indent+'-' * 60
370
if revno is not None:
371
print >>to_file, 'revno:', revno
373
print >>to_file, indent+'merged:', rev.revision_id
375
print >>to_file, indent+'revision-id:', rev.revision_id
791
to_file.write(indent + '-' * 60 + '\n')
792
if revision.revno is not None:
793
to_file.write(indent + 'revno: %s\n' % (revision.revno,))
795
to_file.write(indent + 'tags: %s\n' % (', '.join(revision.tags)))
376
796
if self.show_ids:
377
for parent_id in rev.parent_ids:
378
print >>to_file, indent+'parent:', parent_id
379
print >>to_file, indent+'committer:', rev.committer
381
print >>to_file, indent+'branch nick: %s' % \
382
rev.properties['branch-nick']
385
date_str = format_date(rev.timestamp,
797
to_file.write(indent + 'revision-id: ' + revision.rev.revision_id)
799
for parent_id in revision.rev.parent_ids:
800
to_file.write(indent + 'parent: %s\n' % (parent_id,))
801
self.show_properties(revision.rev, indent)
803
author = revision.rev.properties.get('author', None)
804
if author is not None:
805
to_file.write(indent + 'author: %s\n' % (author,))
806
to_file.write(indent + 'committer: %s\n' % (revision.rev.committer,))
808
branch_nick = revision.rev.properties.get('branch-nick', None)
809
if branch_nick is not None:
810
to_file.write(indent + 'branch nick: %s\n' % (branch_nick,))
812
date_str = format_date(revision.rev.timestamp,
813
revision.rev.timezone or 0,
387
814
self.show_timezone)
388
print >>to_file, indent+'timestamp: %s' % date_str
815
to_file.write(indent + 'timestamp: %s\n' % (date_str,))
390
print >>to_file, indent+'message:'
392
print >>to_file, indent+' (no message)'
817
to_file.write(indent + 'message:\n')
818
if not revision.rev.message:
819
to_file.write(indent + ' (no message)\n')
394
message = rev.message.rstrip('\r\n')
821
message = revision.rev.message.rstrip('\r\n')
395
822
for l in message.split('\n'):
396
print >>to_file, indent+' ' + l
398
delta.show(to_file, self.show_ids)
823
to_file.write(indent + ' %s\n' % (l,))
824
if revision.delta is not None:
825
# We don't respect delta_format for compatibility
826
revision.delta.show(to_file, self.show_ids, indent=indent,
401
830
class ShortLogFormatter(LogFormatter):
402
def show(self, revno, rev, delta):
403
from bzrlib.osutils import format_date
832
supports_delta = True
833
supports_single_merge_revision = True
835
def log_revision(self, revision):
405
836
to_file = self.to_file
406
date_str = format_date(rev.timestamp, rev.timezone or 0,
408
print >>to_file, "%5d %s\t%s" % (revno, self.short_committer(rev),
409
format_date(rev.timestamp, rev.timezone or 0,
838
if len(revision.rev.parent_ids) > 1:
839
is_merge = ' [merge]'
840
to_file.write("%5s %s\t%s%s\n" % (revision.revno,
841
self.short_author(revision.rev),
842
format_date(revision.rev.timestamp,
843
revision.rev.timezone or 0,
410
844
self.show_timezone, date_fmt="%Y-%m-%d",
412
847
if self.show_ids:
413
print >>to_file, ' revision-id:', rev.revision_id
415
print >>to_file, ' (no message)'
848
to_file.write(' revision-id:%s\n'
849
% (revision.rev.revision_id,))
850
if not revision.rev.message:
851
to_file.write(' (no message)\n')
417
message = rev.message.rstrip('\r\n')
853
message = revision.rev.message.rstrip('\r\n')
418
854
for l in message.split('\n'):
419
print >>to_file, ' ' + l
855
to_file.write(' %s\n' % (l,))
421
# TODO: Why not show the modified files in a shorter form as
422
# well? rewrap them single lines of appropriate length
424
delta.show(to_file, self.show_ids)
857
if revision.delta is not None:
858
revision.delta.show(to_file, self.show_ids,
859
short_status=self.delta_format==1)
428
863
class LineLogFormatter(LogFormatter):
865
supports_single_merge_revision = True
867
def __init__(self, *args, **kwargs):
868
super(LineLogFormatter, self).__init__(*args, **kwargs)
869
self._max_chars = terminal_width() - 1
429
871
def truncate(self, str, max_len):
430
872
if len(str) <= max_len:
432
874
return str[:max_len-3]+'...'
434
876
def date_string(self, rev):
435
from bzrlib.osutils import format_date
436
return format_date(rev.timestamp, rev.timezone or 0,
877
return format_date(rev.timestamp, rev.timezone or 0,
437
878
self.show_timezone, date_fmt="%Y-%m-%d",
438
879
show_offset=False)