174
183
:param show_diff: If True, output a diff after each revision.
178
if getattr(lf, 'begin_log', None):
181
_show_log(branch, lf, specific_fileid, verbose, direction,
182
start_revision, end_revision, search, limit, show_diff)
184
if getattr(lf, 'end_log', None):
190
def _show_log(branch,
192
specific_fileid=None,
200
"""Worker function for show_log - see show_log."""
201
if not isinstance(lf, LogFormatter):
202
warn("not a LogFormatter instance: %r" % lf)
204
trace.mutter('get log for file_id %r', specific_fileid)
206
# Consult the LogFormatter about what it needs and can handle
207
levels_to_display = lf.get_levels()
208
generate_merge_revisions = levels_to_display != 1
209
allow_single_merge_revision = True
210
if not getattr(lf, 'supports_merge_revisions', False):
211
allow_single_merge_revision = getattr(lf,
212
'supports_single_merge_revision', False)
213
generate_tags = getattr(lf, 'supports_tags', False)
214
if generate_tags and branch.supports_tags():
215
rev_tag_dict = branch.tags.get_reverse_tag_dict()
218
generate_delta = verbose and getattr(lf, 'supports_delta', False)
219
generate_diff = show_diff and getattr(lf, 'supports_diff', False)
221
# Find and print the interesting revisions
222
repo = branch.repository
224
revision_iterator = _create_log_revision_iterator(branch,
225
start_revision, end_revision, direction, specific_fileid, search,
226
generate_merge_revisions, allow_single_merge_revision,
227
generate_delta, limited_output=limit > 0)
228
for revs in revision_iterator:
229
for (rev_id, revno, merge_depth), rev, delta in revs:
230
# Note: 0 levels means show everything; merge_depth counts from 0
231
if levels_to_display != 0 and merge_depth >= levels_to_display:
234
diff = _format_diff(repo, rev, rev_id, specific_fileid)
237
lr = LogRevision(rev, revno, merge_depth, delta,
238
rev_tag_dict.get(rev_id), diff)
185
# Convert old-style parameters to new-style parameters
186
if specific_fileid is not None:
187
file_ids = [specific_fileid]
192
delta_type = 'partial'
199
diff_type = 'partial'
205
# Build the request and execute it
206
rqst = make_log_request_dict(direction=direction, specific_fileids=file_ids,
207
start_revision=start_revision, end_revision=end_revision,
208
limit=limit, message_search=search,
209
delta_type=delta_type, diff_type=diff_type)
210
Logger(branch, rqst).show(lf)
213
# Note: This needs to be kept this in sync with the defaults in
214
# make_log_request_dict() below
215
_DEFAULT_REQUEST_PARAMS = {
216
'direction': 'reverse',
218
'generate_tags': True,
219
'_match_using_deltas': True,
223
def make_log_request_dict(direction='reverse', specific_fileids=None,
224
start_revision=None, end_revision=None, limit=None,
225
message_search=None, levels=1, generate_tags=True, delta_type=None,
226
diff_type=None, _match_using_deltas=True):
227
"""Convenience function for making a logging request dictionary.
229
Using this function may make code slightly safer by ensuring
230
parameters have the correct names. It also provides a reference
231
point for documenting the supported parameters.
233
:param direction: 'reverse' (default) is latest to earliest;
234
'forward' is earliest to latest.
236
:param specific_fileids: If not None, only include revisions
237
affecting the specified files, rather than all revisions.
239
:param start_revision: If not None, only generate
240
revisions >= start_revision
242
:param end_revision: If not None, only generate
243
revisions <= end_revision
245
:param limit: If set, generate only 'limit' revisions, all revisions
246
are shown if None or 0.
248
:param message_search: If not None, only include revisions with
249
matching commit messages
251
:param levels: the number of levels of revisions to
252
generate; 1 for just the mainline; 0 for all levels.
254
:param generate_tags: If True, include tags for matched revisions.
256
:param delta_type: Either 'full', 'partial' or None.
257
'full' means generate the complete delta - adds/deletes/modifies/etc;
258
'partial' means filter the delta using specific_fileids;
259
None means do not generate any delta.
261
:param diff_type: Either 'full', 'partial' or None.
262
'full' means generate the complete diff - adds/deletes/modifies/etc;
263
'partial' means filter the diff using specific_fileids;
264
None means do not generate any diff.
266
:param _match_using_deltas: a private parameter controlling the
267
algorithm used for matching specific_fileids. This parameter
268
may be removed in the future so bzrlib client code should NOT
272
'direction': direction,
273
'specific_fileids': specific_fileids,
274
'start_revision': start_revision,
275
'end_revision': end_revision,
277
'message_search': message_search,
279
'generate_tags': generate_tags,
280
'delta_type': delta_type,
281
'diff_type': diff_type,
282
# Add 'private' attributes for features that may be deprecated
283
'_match_using_deltas': _match_using_deltas,
287
def _apply_log_request_defaults(rqst):
288
"""Apply default values to a request dictionary."""
289
result = _DEFAULT_REQUEST_PARAMS
295
class LogGenerator(object):
296
"""A generator of log revisions."""
298
def iter_log_revisions(self):
299
"""Iterate over LogRevision objects.
301
:return: An iterator yielding LogRevision objects.
303
raise NotImplementedError(self.iter_log_revisions)
306
class Logger(object):
307
"""An object the generates, formats and displays a log."""
309
def __init__(self, branch, rqst):
312
:param branch: the branch to log
313
:param rqst: A dictionary specifying the query parameters.
314
See make_log_request_dict() for supported values.
317
self.rqst = _apply_log_request_defaults(rqst)
322
:param lf: The LogFormatter object to send the output to.
324
if not isinstance(lf, LogFormatter):
325
warn("not a LogFormatter instance: %r" % lf)
327
self.branch.lock_read()
329
if getattr(lf, 'begin_log', None):
332
if getattr(lf, 'end_log', None):
337
def _show_body(self, lf):
338
"""Show the main log output.
340
Subclasses may wish to override this.
342
# Tweak the LogRequest based on what the LogFormatter can handle.
343
# (There's no point generating stuff if the formatter can't display it.)
345
rqst['levels'] = lf.get_levels()
346
if not getattr(lf, 'supports_tags', False):
347
rqst['generate_tags'] = False
348
if not getattr(lf, 'supports_delta', False):
349
rqst['delta_type'] = None
350
if not getattr(lf, 'supports_diff', False):
351
rqst['diff_type'] = None
353
# Find and print the interesting revisions
354
generator = self._generator_factory(self.branch, rqst)
355
for lr in generator.iter_log_revisions():
239
356
lf.log_revision(lr)
242
if log_count >= limit:
246
def _format_diff(repo, rev, rev_id, specific_fileid):
247
if len(rev.parent_ids) == 0:
248
ancestor_id = _mod_revision.NULL_REVISION
250
ancestor_id = rev.parent_ids[0]
251
tree_1 = repo.revision_tree(ancestor_id)
252
tree_2 = repo.revision_tree(rev_id)
254
specific_files = [tree_2.id2path(specific_fileid)]
256
specific_files = None
258
diff.show_diff_trees(tree_1, tree_2, s, specific_files, old_label='',
359
def _generator_factory(self, branch, rqst):
360
"""Make the LogGenerator object to use.
362
Subclasses may wish to override this.
364
return _DefaultLogGenerator(branch, rqst)
263
367
class _StartNotLinearAncestor(Exception):
264
368
"""Raised when a start revision is not found walking left-hand history."""
267
def _create_log_revision_iterator(branch, start_revision, end_revision,
268
direction, specific_fileid, search, generate_merge_revisions,
269
allow_single_merge_revision, generate_delta, limited_output=False):
270
"""Create a revision iterator for log.
272
:param branch: The branch being logged.
273
:param start_revision: If not None, only show revisions >= start_revision
274
:param end_revision: If not None, only show revisions <= end_revision
275
:param direction: 'reverse' (default) is latest to earliest; 'forward' is
277
:param specific_fileid: If not None, list only the commits affecting the
279
:param search: If not None, only show revisions with matching commit
281
:param generate_merge_revisions: If False, show only mainline revisions.
282
:param allow_single_merge_revision: If True, logging of a single
283
revision off the mainline is to be allowed
284
:param generate_delta: Whether to generate a delta for each revision.
285
:param limited_output: if True, the user only wants a limited result
287
:return: An iterator over lists of ((rev_id, revno, merge_depth), rev,
290
start_rev_id, end_rev_id = _get_revision_limits(branch, start_revision,
293
# Decide how file-ids are matched: delta-filtering vs per-file graph.
294
# Delta filtering allows revisions to be displayed incrementally
295
# though the total time is much slower for huge repositories: log -v
296
# is the *lower* performance bound. At least until the split
297
# inventory format arrives, per-file-graph needs to remain the
298
# default except in verbose mode. Delta filtering should give more
299
# accurate results (e.g. inclusion of FILE deletions) so arguably
300
# it should always be used in the future.
301
use_deltas_for_matching = specific_fileid and generate_delta
302
delayed_graph_generation = not specific_fileid and (
303
start_rev_id or end_rev_id or limited_output)
304
generate_merges = generate_merge_revisions or (specific_fileid and
305
not use_deltas_for_matching)
306
view_revisions = _calc_view_revisions(branch, start_rev_id, end_rev_id,
307
direction, generate_merges, allow_single_merge_revision,
308
delayed_graph_generation=delayed_graph_generation)
309
search_deltas_for_fileids = None
310
if use_deltas_for_matching:
311
search_deltas_for_fileids = set([specific_fileid])
312
elif specific_fileid:
371
class _DefaultLogGenerator(LogGenerator):
372
"""The default generator of log revisions."""
374
def __init__(self, branch, rqst):
377
if rqst.get('generate_tags') and branch.supports_tags():
378
self.rev_tag_dict = branch.tags.get_reverse_tag_dict()
380
self.rev_tag_dict = {}
382
def iter_log_revisions(self):
383
"""Iterate over LogRevision objects.
385
:return: An iterator yielding LogRevision objects.
388
levels = rqst.get('levels')
389
limit = rqst.get('limit')
390
diff_type = rqst.get('diff_type')
392
revision_iterator = self._create_log_revision_iterator()
393
for revs in revision_iterator:
394
for (rev_id, revno, merge_depth), rev, delta in revs:
395
# 0 levels means show everything; merge_depth counts from 0
396
if levels != 0 and merge_depth >= levels:
398
if diff_type is None:
401
diff = self._format_diff(rev, rev_id, diff_type)
402
yield LogRevision(rev, revno, merge_depth, delta,
403
self.rev_tag_dict.get(rev_id), diff)
406
if log_count >= limit:
409
def _format_diff(self, rev, rev_id, diff_type):
410
repo = self.branch.repository
411
if len(rev.parent_ids) == 0:
412
ancestor_id = _mod_revision.NULL_REVISION
414
ancestor_id = rev.parent_ids[0]
415
tree_1 = repo.revision_tree(ancestor_id)
416
tree_2 = repo.revision_tree(rev_id)
417
file_ids = self.rqst.get('specific_fileids')
418
if diff_type == 'partial' and file_ids is not None:
419
specific_files = [tree_2.id2path(id) for id in file_ids]
421
specific_files = None
423
diff.show_diff_trees(tree_1, tree_2, s, specific_files, old_label='',
427
def _create_log_revision_iterator(self):
428
"""Create a revision iterator for log.
430
:return: An iterator over lists of ((rev_id, revno, merge_depth), rev,
433
self.start_rev_id, self.end_rev_id = _get_revision_limits(
434
self.branch, self.rqst.get('start_revision'),
435
self.rqst.get('end_revision'))
436
if self.rqst.get('_match_using_deltas'):
437
return self._log_revision_iterator_using_delta_matching()
439
# We're using the per-file-graph algorithm. This scales really
440
# well but only makes sense if there is a single file and it's
442
file_count = len(self.rqst.get('specific_fileids'))
444
raise BzrError("illegal LogRequest: must match-using-deltas "
445
"when logging %d files" % file_count)
446
return self._log_revision_iterator_using_per_file_graph()
448
def _log_revision_iterator_using_delta_matching(self):
449
# Get the base revisions, filtering by the revision range
451
generate_merge_revisions = rqst.get('levels') != 1
452
delayed_graph_generation = not rqst.get('specific_fileids') and (
453
rqst.get('limit') or self.start_rev_id or self.end_rev_id)
454
view_revisions = _calc_view_revisions(self.branch, self.start_rev_id,
455
self.end_rev_id, rqst.get('direction'), generate_merge_revisions,
456
delayed_graph_generation=delayed_graph_generation)
458
# Apply the other filters
459
return make_log_rev_iterator(self.branch, view_revisions,
460
rqst.get('delta_type'), rqst.get('message_search'),
461
file_ids=rqst.get('specific_fileids'),
462
direction=rqst.get('direction'))
464
def _log_revision_iterator_using_per_file_graph(self):
465
# Get the base revisions, filtering by the revision range.
466
# Note that we always generate the merge revisions because
467
# filter_revisions_touching_file_id() requires them ...
469
view_revisions = _calc_view_revisions(self.branch, self.start_rev_id,
470
self.end_rev_id, rqst.get('direction'), True)
313
471
if not isinstance(view_revisions, list):
314
472
view_revisions = list(view_revisions)
315
view_revisions = _filter_revisions_touching_file_id(branch,
316
specific_fileid, view_revisions,
317
include_merges=generate_merge_revisions)
318
return make_log_rev_iterator(branch, view_revisions, generate_delta,
319
search, file_ids=search_deltas_for_fileids, direction=direction)
473
view_revisions = _filter_revisions_touching_file_id(self.branch,
474
rqst.get('specific_fileids')[0], view_revisions,
475
include_merges=rqst.get('levels') != 1)
476
return make_log_rev_iterator(self.branch, view_revisions,
477
rqst.get('delta_type'), rqst.get('message_search'))
322
480
def _calc_view_revisions(branch, start_rev_id, end_rev_id, direction,
323
generate_merge_revisions, allow_single_merge_revision,
324
delayed_graph_generation=False):
481
generate_merge_revisions, delayed_graph_generation=False):
325
482
"""Calculate the revisions to view.
327
484
:return: An iterator of (revision_id, dotted_revno, merge_depth) tuples OR
335
492
generate_single_revision = (end_rev_id and start_rev_id == end_rev_id and
336
493
(not generate_merge_revisions or not _has_merges(branch, end_rev_id)))
337
494
if generate_single_revision:
338
if end_rev_id == br_rev_id:
340
return [(br_rev_id, br_revno, 0)]
342
revno = branch.revision_id_to_dotted_revno(end_rev_id)
343
if len(revno) > 1 and not allow_single_merge_revision:
344
# It's a merge revision and the log formatter is
345
# completely brain dead. This "feature" of allowing
346
# log formatters incapable of displaying dotted revnos
347
# ought to be deprecated IMNSHO. IGC 20091022
348
raise errors.BzrCommandError('Selected log formatter only'
349
' supports mainline revisions.')
350
revno_str = '.'.join(str(n) for n in revno)
351
return [(end_rev_id, revno_str, 0)]
495
return _generate_one_revision(branch, end_rev_id, br_rev_id, br_revno)
353
497
# If we only want to see linear revisions, we can iterate ...
354
498
if not generate_merge_revisions:
355
result = _linear_view_revisions(branch, start_rev_id, end_rev_id)
356
# If a start limit was given and it's not obviously an
357
# ancestor of the end limit, check it before outputting anything
358
if direction == 'forward' or (start_rev_id
359
and not _is_obvious_ancestor(branch, start_rev_id, end_rev_id)):
361
result = list(result)
362
except _StartNotLinearAncestor:
363
raise errors.BzrCommandError('Start revision not found in'
364
' left-hand history of end revision.')
365
if direction == 'forward':
366
result = reversed(list(result))
499
return _generate_flat_revisions(branch, start_rev_id, end_rev_id,
502
return _generate_all_revisions(branch, start_rev_id, end_rev_id,
503
direction, delayed_graph_generation)
506
def _generate_one_revision(branch, rev_id, br_rev_id, br_revno):
507
if rev_id == br_rev_id:
509
return [(br_rev_id, br_revno, 0)]
511
revno = branch.revision_id_to_dotted_revno(rev_id)
512
revno_str = '.'.join(str(n) for n in revno)
513
return [(rev_id, revno_str, 0)]
516
def _generate_flat_revisions(branch, start_rev_id, end_rev_id, direction):
517
result = _linear_view_revisions(branch, start_rev_id, end_rev_id)
518
# If a start limit was given and it's not obviously an
519
# ancestor of the end limit, check it before outputting anything
520
if direction == 'forward' or (start_rev_id
521
and not _is_obvious_ancestor(branch, start_rev_id, end_rev_id)):
523
result = list(result)
524
except _StartNotLinearAncestor:
525
raise errors.BzrCommandError('Start revision not found in'
526
' left-hand history of end revision.')
527
if direction == 'forward':
528
result = reversed(result)
532
def _generate_all_revisions(branch, start_rev_id, end_rev_id, direction,
533
delayed_graph_generation):
369
534
# On large trees, generating the merge graph can take 30-60 seconds
370
535
# so we delay doing it until a merge is detected, incrementally
371
536
# returning initial (non-merge) revisions while we can.
1176
1367
def short_author(self, rev):
1177
name, address = config.parse_username(rev.get_apparent_author())
1368
name, address = config.parse_username(rev.get_apparent_authors()[0])
1373
def merge_marker(self, revision):
1374
"""Get the merge marker to include in the output or '' if none."""
1375
if len(revision.rev.parent_ids) > 1:
1376
self._merge_count += 1
1182
1381
def show_properties(self, revision, indent):
1183
1382
"""Displays the custom properties returned by each registered handler.
1185
If a registered handler raises an error it is propagated.
1384
If a registered handler raises an error it is propagated.
1386
for line in self.custom_properties(revision):
1387
self.to_file.write("%s%s\n" % (indent, line))
1389
def custom_properties(self, revision):
1390
"""Format the custom properties returned by each registered handler.
1392
If a registered handler raises an error it is propagated.
1394
:return: a list of formatted lines (excluding trailing newlines)
1396
lines = self._foreign_info_properties(revision)
1187
1397
for key, handler in properties_handler_registry.iteritems():
1188
for key, value in handler(revision).items():
1189
self.to_file.write(indent + key + ': ' + value + '\n')
1398
lines.extend(self._format_properties(handler(revision)))
1401
def _foreign_info_properties(self, rev):
1402
"""Custom log displayer for foreign revision identifiers.
1404
:param rev: Revision object.
1406
# Revision comes directly from a foreign repository
1407
if isinstance(rev, foreign.ForeignRevision):
1408
return rev.mapping.vcs.show_foreign_revid(rev.foreign_revid)
1410
# Imported foreign revision revision ids always contain :
1411
if not ":" in rev.revision_id:
1414
# Revision was once imported from a foreign repository
1416
foreign_revid, mapping = \
1417
foreign.foreign_vcs_registry.parse_revision_id(rev.revision_id)
1418
except errors.InvalidRevisionId:
1421
return self._format_properties(
1422
mapping.vcs.show_foreign_revid(foreign_revid))
1424
def _format_properties(self, properties):
1426
for key, value in properties.items():
1427
lines.append(key + ': ' + value)
1191
1430
def show_diff(self, to_file, diff, indent):
1192
1431
for l in diff.rstrip().split('\n'):
1193
1432
to_file.write(indent + '%s\n' % (l,))
1435
# Separator between revisions in long format
1436
_LONG_SEP = '-' * 60
1196
1439
class LongLogFormatter(LogFormatter):
1198
1441
supports_merge_revisions = True
1442
preferred_levels = 1
1199
1443
supports_delta = True
1200
1444
supports_tags = True
1201
1445
supports_diff = True
1447
def __init__(self, *args, **kwargs):
1448
super(LongLogFormatter, self).__init__(*args, **kwargs)
1449
if self.show_timezone == 'original':
1450
self.date_string = self._date_string_original_timezone
1452
self.date_string = self._date_string_with_timezone
1454
def _date_string_with_timezone(self, rev):
1455
return format_date(rev.timestamp, rev.timezone or 0,
1458
def _date_string_original_timezone(self, rev):
1459
return format_date_with_offset_in_original_timezone(rev.timestamp,
1203
1462
def log_revision(self, revision):
1204
1463
"""Log a revision, either merged or not."""
1205
1464
indent = ' ' * revision.merge_depth
1206
to_file = self.to_file
1207
to_file.write(indent + '-' * 60 + '\n')
1208
1466
if revision.revno is not None:
1209
to_file.write(indent + 'revno: %s\n' % (revision.revno,))
1467
lines.append('revno: %s%s' % (revision.revno,
1468
self.merge_marker(revision)))
1210
1469
if revision.tags:
1211
to_file.write(indent + 'tags: %s\n' % (', '.join(revision.tags)))
1470
lines.append('tags: %s' % (', '.join(revision.tags)))
1212
1471
if self.show_ids:
1213
to_file.write(indent + 'revision-id: ' + revision.rev.revision_id)
1472
lines.append('revision-id: %s' % (revision.rev.revision_id,))
1215
1473
for parent_id in revision.rev.parent_ids:
1216
to_file.write(indent + 'parent: %s\n' % (parent_id,))
1217
self.show_properties(revision.rev, indent)
1474
lines.append('parent: %s' % (parent_id,))
1475
lines.extend(self.custom_properties(revision.rev))
1219
author = revision.rev.properties.get('author', None)
1220
if author is not None:
1221
to_file.write(indent + 'author: %s\n' % (author,))
1222
to_file.write(indent + 'committer: %s\n' % (revision.rev.committer,))
1477
committer = revision.rev.committer
1478
authors = revision.rev.get_apparent_authors()
1479
if authors != [committer]:
1480
lines.append('author: %s' % (", ".join(authors),))
1481
lines.append('committer: %s' % (committer,))
1224
1483
branch_nick = revision.rev.properties.get('branch-nick', None)
1225
1484
if branch_nick is not None:
1226
to_file.write(indent + 'branch nick: %s\n' % (branch_nick,))
1228
date_str = format_date(revision.rev.timestamp,
1229
revision.rev.timezone or 0,
1231
to_file.write(indent + 'timestamp: %s\n' % (date_str,))
1233
to_file.write(indent + 'message:\n')
1485
lines.append('branch nick: %s' % (branch_nick,))
1487
lines.append('timestamp: %s' % (self.date_string(revision.rev),))
1489
lines.append('message:')
1234
1490
if not revision.rev.message:
1235
to_file.write(indent + ' (no message)\n')
1491
lines.append(' (no message)')
1237
1493
message = revision.rev.message.rstrip('\r\n')
1238
1494
for l in message.split('\n'):
1239
to_file.write(indent + ' %s\n' % (l,))
1495
lines.append(' %s' % (l,))
1497
# Dump the output, appending the delta and diff if requested
1498
to_file = self.to_file
1499
to_file.write("%s%s\n" % (indent, ('\n' + indent).join(lines)))
1240
1500
if revision.delta is not None:
1241
1501
# We don't respect delta_format for compatibility
1242
1502
revision.delta.show(to_file, self.show_ids, indent=indent,
1243
1503
short_status=False)
1244
1504
if revision.diff is not None:
1245
1505
to_file.write(indent + 'diff:\n')
1246
1507
# Note: we explicitly don't indent the diff (relative to the
1247
1508
# revision information) so that the output can be fed to patch -p0
1248
self.show_diff(to_file, revision.diff, indent)
1509
self.show_diff(self.to_exact_file, revision.diff, indent)
1510
self.to_exact_file.flush()
1512
def get_advice_separator(self):
1513
"""Get the text separating the log from the closing advice."""
1514
return '-' * 60 + '\n'
1251
1517
class ShortLogFormatter(LogFormatter):
1573
1878
lf.log_revision(lr)
1576
def _get_fileid_to_log(revision, tree, b, fp):
1577
"""Find the file-id to log for a file path in a revision range.
1579
:param revision: the revision range as parsed on the command line
1580
:param tree: the working tree, if any
1581
:param b: the branch
1582
:param fp: file path
1881
def _get_info_for_log_files(revisionspec_list, file_list):
1882
"""Find file-ids and kinds given a list of files and a revision range.
1884
We search for files at the end of the range. If not found there,
1885
we try the start of the range.
1887
:param revisionspec_list: revision range as parsed on the command line
1888
:param file_list: the list of paths given on the command line;
1889
the first of these can be a branch location or a file path,
1890
the remainder must be file paths
1891
:return: (branch, info_list, start_rev_info, end_rev_info) where
1892
info_list is a list of (relative_path, file_id, kind) tuples where
1893
kind is one of values 'directory', 'file', 'symlink', 'tree-reference'.
1894
branch will be read-locked.
1584
if revision is None:
1896
from builtins import _get_revision_range, safe_relpath_files
1897
tree, b, path = bzrdir.BzrDir.open_containing_tree_or_branch(file_list[0])
1899
# XXX: It's damn messy converting a list of paths to relative paths when
1900
# those paths might be deleted ones, they might be on a case-insensitive
1901
# filesystem and/or they might be in silly locations (like another branch).
1902
# For example, what should "log bzr://branch/dir/file1 file2" do? (Is
1903
# file2 implicitly in the same dir as file1 or should its directory be
1904
# taken from the current tree somehow?) For now, this solves the common
1905
# case of running log in a nested directory, assuming paths beyond the
1906
# first one haven't been deleted ...
1908
relpaths = [path] + safe_relpath_files(tree, file_list[1:])
1910
relpaths = [path] + file_list[1:]
1912
start_rev_info, end_rev_info = _get_revision_range(revisionspec_list, b,
1914
if relpaths in ([], [u'']):
1915
return b, [], start_rev_info, end_rev_info
1916
if start_rev_info is None and end_rev_info is None:
1585
1917
if tree is None:
1586
1918
tree = b.basis_tree()
1587
file_id = tree.path2id(fp)
1589
# go back to when time began
1591
rev1 = b.get_rev_id(1)
1592
except errors.NoSuchRevision:
1596
tree = b.repository.revision_tree(rev1)
1597
file_id = tree.path2id(fp)
1921
file_id = tree.path2id(fp)
1922
kind = _get_kind_for_file_id(tree, file_id)
1924
# go back to when time began
1927
rev1 = b.get_rev_id(1)
1928
except errors.NoSuchRevision:
1933
tree1 = b.repository.revision_tree(rev1)
1935
file_id = tree1.path2id(fp)
1936
kind = _get_kind_for_file_id(tree1, file_id)
1937
info_list.append((fp, file_id, kind))
1599
elif len(revision) == 1:
1939
elif start_rev_info == end_rev_info:
1600
1940
# One revision given - file must exist in it
1601
tree = revision[0].as_tree(b)
1602
file_id = tree.path2id(fp)
1941
tree = b.repository.revision_tree(end_rev_info.rev_id)
1943
file_id = tree.path2id(fp)
1944
kind = _get_kind_for_file_id(tree, file_id)
1945
info_list.append((fp, file_id, kind))
1604
elif len(revision) == 2:
1605
1948
# Revision range given. Get the file-id from the end tree.
1606
1949
# If that fails, try the start tree.
1607
rev_id = revision[1].as_revision_id(b)
1950
rev_id = end_rev_info.rev_id
1608
1951
if rev_id is None:
1609
1952
tree = b.basis_tree()
1611
tree = revision[1].as_tree(b)
1612
file_id = tree.path2id(fp)
1614
rev_id = revision[0].as_revision_id(b)
1616
rev1 = b.get_rev_id(1)
1617
tree = b.repository.revision_tree(rev1)
1619
tree = revision[0].as_tree(b)
1954
tree = b.repository.revision_tree(rev_id)
1620
1957
file_id = tree.path2id(fp)
1958
kind = _get_kind_for_file_id(tree, file_id)
1961
rev_id = start_rev_info.rev_id
1963
rev1 = b.get_rev_id(1)
1964
tree1 = b.repository.revision_tree(rev1)
1966
tree1 = b.repository.revision_tree(rev_id)
1967
file_id = tree1.path2id(fp)
1968
kind = _get_kind_for_file_id(tree1, file_id)
1969
info_list.append((fp, file_id, kind))
1970
return b, info_list, start_rev_info, end_rev_info
1973
def _get_kind_for_file_id(tree, file_id):
1974
"""Return the kind of a file-id or None if it doesn't exist."""
1975
if file_id is not None:
1976
return tree.kind(file_id)
1622
raise errors.BzrCommandError(
1623
'bzr log --revision takes one or two values.')
1627
1981
properties_handler_registry = registry.Registry()
1628
properties_handler_registry.register_lazy("foreign",
1630
"show_foreign_properties")
1983
# Use the properties handlers to print out bug information if available
1984
def _bugs_properties_handler(revision):
1985
if revision.properties.has_key('bugs'):
1986
bug_lines = revision.properties['bugs'].split('\n')
1987
bug_rows = [line.split(' ', 1) for line in bug_lines]
1988
fixed_bug_urls = [row[0] for row in bug_rows if
1989
len(row) > 1 and row[1] == 'fixed']
1992
return {'fixes bug(s)': ' '.join(fixed_bug_urls)}
1995
properties_handler_registry.register('bugs_properties_handler',
1996
_bugs_properties_handler)
1633
1999
# adapters which revision ids to log are filtered. When log is called, the