47
49
all the changes since the previous revision that touched hello.c.
50
from __future__ import absolute_import
53
from cStringIO import StringIO
54
from itertools import (
56
60
from warnings import (
60
from .lazy_import import lazy_import
64
from bzrlib.lazy_import import lazy_import
61
65
lazy_import(globals(), """
74
repository as _mod_repository,
69
75
revision as _mod_revision,
71
from breezy.i18n import gettext, ngettext
80
from .osutils import (
85
from bzrlib.osutils import (
82
87
format_date_with_offset_in_original_timezone,
83
get_diff_header_encoding,
84
88
get_terminal_encoding,
91
from bzrlib.symbol_versioning import (
92
from .tree import InterTree
95
def find_touching_revisions(repository, last_revision, last_tree, last_path):
97
def find_touching_revisions(branch, file_id):
96
98
"""Yield a description of revisions which affect the file_id.
98
100
Each returned element is (revno, revision_id, description)
103
105
TODO: Perhaps some way to limit this to only particular revisions,
104
106
or to traverse a non-mainline set of revisions?
106
last_verifier = last_tree.get_file_verifier(last_path)
107
graph = repository.get_graph()
108
history = list(graph.iter_lefthand_ancestry(last_revision, []))
110
for revision_id in history:
111
this_tree = repository.revision_tree(revision_id)
112
this_intertree = InterTree.get(this_tree, last_tree)
113
this_path = this_intertree.find_source_path(last_path)
111
for revision_id in branch.revision_history():
112
this_inv = branch.repository.get_inventory(revision_id)
113
if file_id in this_inv:
114
this_ie = this_inv[file_id]
115
this_path = this_inv.id2path(file_id)
117
this_ie = this_path = None
115
119
# now we know how it was last time, and how it is in this revision.
116
120
# are those two states effectively the same or not?
117
if this_path is not None and last_path is None:
118
yield revno, revision_id, "deleted " + this_path
119
this_verifier = this_tree.get_file_verifier(this_path)
120
elif this_path is None and last_path is not None:
121
yield revno, revision_id, "added " + last_path
122
if not this_ie and not last_ie:
123
# not present in either
125
elif this_ie and not last_ie:
126
yield revno, revision_id, "added " + this_path
127
elif not this_ie and last_ie:
129
yield revno, revision_id, "deleted " + last_path
122
130
elif this_path != last_path:
123
yield revno, revision_id, ("renamed %s => %s" % (this_path, last_path))
124
this_verifier = this_tree.get_file_verifier(this_path)
126
this_verifier = this_tree.get_file_verifier(this_path)
127
if (this_verifier != last_verifier):
128
yield revno, revision_id, "modified " + this_path
131
yield revno, revision_id, ("renamed %s => %s" % (last_path, this_path))
132
elif (this_ie.text_size != last_ie.text_size
133
or this_ie.text_sha1 != last_ie.text_sha1):
134
yield revno, revision_id, "modified " + this_path
130
last_verifier = this_verifier
131
137
last_path = this_path
132
last_tree = this_tree
133
if last_path is None:
141
def _enumerate_history(branch):
144
for rev_id in branch.revision_history():
145
rh.append((revno, rev_id))
138
150
def show_log(branch,
152
specific_fileid=None,
141
154
direction='reverse',
142
155
start_revision=None,
143
156
end_revision=None,
148
160
"""Write out human-readable log of commits to this branch.
150
162
This function is being retained for backwards compatibility but
172
187
:param show_diff: If True, output a diff after each revision.
174
:param match: Dictionary of search lists to use when matching revision
189
# Convert old-style parameters to new-style parameters
190
if specific_fileid is not None:
191
file_ids = [specific_fileid]
196
delta_type = 'partial'
180
200
delta_type = None
203
diff_type = 'partial'
186
if isinstance(start_revision, int):
188
start_revision = revisionspec.RevisionInfo(branch, start_revision)
189
except (errors.NoSuchRevision, errors.RevnoOutOfBounds):
190
raise errors.InvalidRevisionNumber(start_revision)
192
if isinstance(end_revision, int):
194
end_revision = revisionspec.RevisionInfo(branch, end_revision)
195
except (errors.NoSuchRevision, errors.RevnoOutOfBounds):
196
raise errors.InvalidRevisionNumber(end_revision)
198
if end_revision is not None and end_revision.revno == 0:
199
raise errors.InvalidRevisionNumber(end_revision.revno)
201
209
# Build the request and execute it
202
rqst = make_log_request_dict(
210
rqst = make_log_request_dict(direction=direction, specific_fileids=file_ids,
204
211
start_revision=start_revision, end_revision=end_revision,
205
212
limit=limit, message_search=search,
206
213
delta_type=delta_type, diff_type=diff_type)
207
214
Logger(branch, rqst).show(lf)
210
# Note: This needs to be kept in sync with the defaults in
217
# Note: This needs to be kept this in sync with the defaults in
211
218
# make_log_request_dict() below
212
219
_DEFAULT_REQUEST_PARAMS = {
213
220
'direction': 'reverse',
215
222
'generate_tags': True,
216
223
'exclude_common_ancestry': False,
217
224
'_match_using_deltas': True,
221
228
def make_log_request_dict(direction='reverse', specific_fileids=None,
222
229
start_revision=None, end_revision=None, limit=None,
223
message_search=None, levels=None, generate_tags=True,
230
message_search=None, levels=1, generate_tags=True,
225
232
diff_type=None, _match_using_deltas=True,
226
exclude_common_ancestry=False, match=None,
227
signature=False, omit_merges=False,
233
exclude_common_ancestry=False,
229
235
"""Convenience function for making a logging request dictionary.
269
274
:param _match_using_deltas: a private parameter controlling the
270
275
algorithm used for matching specific_fileids. This parameter
271
may be removed in the future so breezy client code should NOT
276
may be removed in the future so bzrlib client code should NOT
274
279
:param exclude_common_ancestry: Whether -rX..Y should be interpreted as a
275
280
range operator or as a graph difference.
277
:param signature: show digital signature information
279
:param match: Dictionary of list of search strings to use when filtering
280
revisions. Keys can be 'message', 'author', 'committer', 'bugs' or
281
the empty string to match any of the preceding properties.
283
:param omit_merges: If True, commits with more than one parent are
287
# Take care of old style message_search parameter
290
if 'message' in match:
291
match['message'].append(message_search)
293
match['message'] = [message_search]
295
match = {'message': [message_search]}
297
283
'direction': direction,
298
284
'specific_fileids': specific_fileids,
299
285
'start_revision': start_revision,
300
286
'end_revision': end_revision,
288
'message_search': message_search,
302
289
'levels': levels,
303
290
'generate_tags': generate_tags,
304
291
'delta_type': delta_type,
305
292
'diff_type': diff_type,
306
293
'exclude_common_ancestry': exclude_common_ancestry,
307
'signature': signature,
309
'omit_merges': omit_merges,
310
294
# Add 'private' attributes for features that may be deprecated
311
295
'_match_using_deltas': _match_using_deltas,
315
299
def _apply_log_request_defaults(rqst):
316
300
"""Apply default values to a request dictionary."""
317
result = _DEFAULT_REQUEST_PARAMS.copy()
301
result = _DEFAULT_REQUEST_PARAMS
319
303
result.update(rqst)
323
def format_signature_validity(rev_id, branch):
324
"""get the signature validity
326
:param rev_id: revision id to validate
327
:param branch: branch of revision
328
:return: human readable string to print to log
330
from breezy import gpg
332
gpg_strategy = gpg.GPGStrategy(branch.get_config_stack())
333
result = branch.repository.verify_revision_signature(rev_id, gpg_strategy)
334
if result[0] == gpg.SIGNATURE_VALID:
335
return u"valid signature from {0}".format(result[1])
336
if result[0] == gpg.SIGNATURE_KEY_MISSING:
337
return "unknown key {0}".format(result[1])
338
if result[0] == gpg.SIGNATURE_NOT_VALID:
339
return "invalid signature!"
340
if result[0] == gpg.SIGNATURE_NOT_SIGNED:
341
return "no signature"
344
307
class LogGenerator(object):
345
308
"""A generator of log revisions."""
388
354
# Tweak the LogRequest based on what the LogFormatter can handle.
389
355
# (There's no point generating stuff if the formatter can't display it.)
391
if rqst['levels'] is None or lf.get_levels() > rqst['levels']:
392
# user didn't specify levels, use whatever the LF can handle:
393
rqst['levels'] = lf.get_levels()
357
rqst['levels'] = lf.get_levels()
395
358
if not getattr(lf, 'supports_tags', False):
396
359
rqst['generate_tags'] = False
397
360
if not getattr(lf, 'supports_delta', False):
398
361
rqst['delta_type'] = None
399
362
if not getattr(lf, 'supports_diff', False):
400
363
rqst['diff_type'] = None
401
if not getattr(lf, 'supports_signatures', False):
402
rqst['signature'] = False
404
365
# Find and print the interesting revisions
405
366
generator = self._generator_factory(self.branch, rqst)
407
for lr in generator.iter_log_revisions():
409
except errors.GhostRevisionUnusableHere:
410
raise errors.BzrCommandError(
411
gettext('Further revision history missing.'))
367
for lr in generator.iter_log_revisions():
414
371
def _generator_factory(self, branch, rqst):
415
372
"""Make the LogGenerator object to use.
417
374
Subclasses may wish to override this.
419
376
return _DefaultLogGenerator(branch, rqst)
443
400
levels = rqst.get('levels')
444
401
limit = rqst.get('limit')
445
402
diff_type = rqst.get('diff_type')
446
show_signature = rqst.get('signature')
447
omit_merges = rqst.get('omit_merges')
449
404
revision_iterator = self._create_log_revision_iterator()
450
405
for revs in revision_iterator:
451
406
for (rev_id, revno, merge_depth), rev, delta in revs:
452
407
# 0 levels means show everything; merge_depth counts from 0
453
if (levels != 0 and merge_depth is not None and
454
merge_depth >= levels):
456
if omit_merges and len(rev.parent_ids) > 1:
459
raise errors.GhostRevisionUnusableHere(rev_id)
408
if levels != 0 and merge_depth >= levels:
460
410
if diff_type is None:
463
413
diff = self._format_diff(rev, rev_id, diff_type)
465
signature = format_signature_validity(rev_id, self.branch)
469
rev, revno, merge_depth, delta,
470
self.rev_tag_dict.get(rev_id), diff, signature)
414
yield LogRevision(rev, revno, merge_depth, delta,
415
self.rev_tag_dict.get(rev_id), diff)
473
418
if log_count >= limit:
530
474
# Apply the other filters
531
475
return make_log_rev_iterator(self.branch, view_revisions,
532
rqst.get('delta_type'), rqst.get('match'),
533
file_ids=rqst.get('specific_fileids'),
534
direction=rqst.get('direction'))
476
rqst.get('delta_type'), rqst.get('message_search'),
477
file_ids=rqst.get('specific_fileids'),
478
direction=rqst.get('direction'))
536
480
def _log_revision_iterator_using_per_file_graph(self):
537
481
# Get the base revisions, filtering by the revision range.
545
489
if not isinstance(view_revisions, list):
546
490
view_revisions = list(view_revisions)
547
491
view_revisions = _filter_revisions_touching_file_id(self.branch,
548
rqst.get('specific_fileids')[
550
include_merges=rqst.get('levels') != 1)
492
rqst.get('specific_fileids')[0], view_revisions,
493
include_merges=rqst.get('levels') != 1)
551
494
return make_log_rev_iterator(self.branch, view_revisions,
552
rqst.get('delta_type'), rqst.get('match'))
495
rqst.get('delta_type'), rqst.get('message_search'))
555
498
def _calc_view_revisions(branch, start_rev_id, end_rev_id, direction,
563
506
a list of the same tuples.
565
508
if (exclude_common_ancestry and start_rev_id == end_rev_id):
566
raise errors.BzrCommandError(gettext(
567
'--exclude-common-ancestry requires two different revisions'))
509
raise errors.BzrCommandError(
510
'--exclude-common-ancestry requires two different revisions')
568
511
if direction not in ('reverse', 'forward'):
569
raise ValueError(gettext('invalid direction %r') % direction)
570
br_rev_id = branch.last_revision()
571
if br_rev_id == _mod_revision.NULL_REVISION:
512
raise ValueError('invalid direction %r' % direction)
513
br_revno, br_rev_id = branch.last_revision_info()
574
517
if (end_rev_id and start_rev_id == end_rev_id
575
518
and (not generate_merge_revisions
576
519
or not _has_merges(branch, end_rev_id))):
577
520
# If a single revision is requested, check we can handle it
578
return _generate_one_revision(branch, end_rev_id, br_rev_id,
580
if not generate_merge_revisions:
582
# If we only want to see linear revisions, we can iterate ...
583
iter_revs = _linear_view_revisions(
584
branch, start_rev_id, end_rev_id,
585
exclude_common_ancestry=exclude_common_ancestry)
586
# If a start limit was given and it's not obviously an
587
# ancestor of the end limit, check it before outputting anything
588
if (direction == 'forward'
589
or (start_rev_id and not _is_obvious_ancestor(
590
branch, start_rev_id, end_rev_id))):
591
iter_revs = list(iter_revs)
592
if direction == 'forward':
593
iter_revs = reversed(iter_revs)
595
except _StartNotLinearAncestor:
596
# Switch to the slower implementation that may be able to find a
597
# non-obvious ancestor out of the left-hand history.
599
iter_revs = _generate_all_revisions(branch, start_rev_id, end_rev_id,
600
direction, delayed_graph_generation,
601
exclude_common_ancestry)
602
if direction == 'forward':
603
iter_revs = _rebase_merge_depth(reverse_by_depth(list(iter_revs)))
521
iter_revs = _generate_one_revision(branch, end_rev_id, br_rev_id,
523
elif not generate_merge_revisions:
524
# If we only want to see linear revisions, we can iterate ...
525
iter_revs = _generate_flat_revisions(branch, start_rev_id, end_rev_id,
526
direction, exclude_common_ancestry)
527
if direction == 'forward':
528
iter_revs = reversed(iter_revs)
530
iter_revs = _generate_all_revisions(branch, start_rev_id, end_rev_id,
531
direction, delayed_graph_generation,
532
exclude_common_ancestry)
533
if direction == 'forward':
534
iter_revs = _rebase_merge_depth(reverse_by_depth(list(iter_revs)))
610
541
return [(br_rev_id, br_revno, 0)]
612
revno_str = _compute_revno_str(branch, rev_id)
543
revno = branch.revision_id_to_dotted_revno(rev_id)
544
revno_str = '.'.join(str(n) for n in revno)
613
545
return [(rev_id, revno_str, 0)]
548
def _generate_flat_revisions(branch, start_rev_id, end_rev_id, direction,
549
exclude_common_ancestry=False):
550
result = _linear_view_revisions(
551
branch, start_rev_id, end_rev_id,
552
exclude_common_ancestry=exclude_common_ancestry)
553
# If a start limit was given and it's not obviously an
554
# ancestor of the end limit, check it before outputting anything
555
if direction == 'forward' or (start_rev_id
556
and not _is_obvious_ancestor(branch, start_rev_id, end_rev_id)):
558
result = list(result)
559
except _StartNotLinearAncestor:
560
raise errors.BzrCommandError('Start revision not found in'
561
' left-hand history of end revision.')
616
565
def _generate_all_revisions(branch, start_rev_id, end_rev_id, direction,
617
566
delayed_graph_generation,
618
567
exclude_common_ancestry=False):
626
575
initial_revisions = []
627
576
if delayed_graph_generation:
629
for rev_id, revno, depth in _linear_view_revisions(
630
branch, start_rev_id, end_rev_id, exclude_common_ancestry):
578
for rev_id, revno, depth in _linear_view_revisions(
579
branch, start_rev_id, end_rev_id, exclude_common_ancestry):
631
580
if _has_merges(branch, rev_id):
632
581
# The end_rev_id can be nested down somewhere. We need an
633
582
# explicit ancestry check. There is an ambiguity here as we
665
614
# shown naturally, i.e. just like it is for linear logging. We can easily
666
615
# make forward the exact opposite display, but showing the merge revisions
667
616
# indented at the end seems slightly nicer in that case.
668
view_revisions = itertools.chain(iter(initial_revisions),
669
_graph_view_revisions(branch, start_rev_id, end_rev_id,
670
rebase_initial_depths=(
671
direction == 'reverse'),
672
exclude_common_ancestry=exclude_common_ancestry))
617
view_revisions = chain(iter(initial_revisions),
618
_graph_view_revisions(branch, start_rev_id, end_rev_id,
619
rebase_initial_depths=(direction == 'reverse'),
620
exclude_common_ancestry=exclude_common_ancestry))
673
621
return view_revisions
679
627
return len(parents) > 1
682
def _compute_revno_str(branch, rev_id):
683
"""Compute the revno string from a rev_id.
685
:return: The revno string, or None if the revision is not in the supplied
689
revno = branch.revision_id_to_dotted_revno(rev_id)
690
except errors.NoSuchRevision:
691
# The revision must be outside of this branch
694
return '.'.join(str(n) for n in revno)
697
630
def _is_obvious_ancestor(branch, start_rev_id, end_rev_id):
698
631
"""Is start_rev_id an obvious ancestor of end_rev_id?"""
699
632
if start_rev_id and end_rev_id:
701
start_dotted = branch.revision_id_to_dotted_revno(start_rev_id)
702
end_dotted = branch.revision_id_to_dotted_revno(end_rev_id)
703
except errors.NoSuchRevision:
704
# one or both is not in the branch; not obvious
633
start_dotted = branch.revision_id_to_dotted_revno(start_rev_id)
634
end_dotted = branch.revision_id_to_dotted_revno(end_rev_id)
706
635
if len(start_dotted) == 1 and len(end_dotted) == 1:
707
636
# both on mainline
708
637
return start_dotted[0] <= end_dotted[0]
709
638
elif (len(start_dotted) == 3 and len(end_dotted) == 3 and
710
start_dotted[0:1] == end_dotted[0:1]):
639
start_dotted[0:1] == end_dotted[0:1]):
711
640
# both on same development line
712
641
return start_dotted[2] <= end_dotted[2]
727
656
:param exclude_common_ancestry: Whether the start_rev_id should be part of
728
657
the iterated revisions.
729
658
:return: An iterator of (revision_id, dotted_revno, merge_depth) tuples.
730
dotted_revno will be None for ghosts
731
659
:raises _StartNotLinearAncestor: if a start_rev_id is specified but
732
660
is not found walking the left-hand history
662
br_revno, br_rev_id = branch.last_revision_info()
734
663
repo = branch.repository
735
graph = repo.get_graph()
736
664
if start_rev_id is None and end_rev_id is None:
737
if branch._format.stores_revno() or \
738
config.GlobalStack().get('calculate_revnos'):
740
br_revno, br_rev_id = branch.last_revision_info()
741
except errors.GhostRevisionsHaveNoRevno:
742
br_rev_id = branch.last_revision()
747
br_rev_id = branch.last_revision()
750
graph_iter = graph.iter_lefthand_ancestry(br_rev_id,
751
(_mod_revision.NULL_REVISION,))
754
revision_id = next(graph_iter)
755
except errors.RevisionNotPresent as e:
757
yield e.revision_id, None, None
759
except StopIteration:
762
yield revision_id, str(cur_revno) if cur_revno is not None else None, 0
763
if cur_revno is not None:
666
for revision_id in repo.iter_reverse_revision_history(br_rev_id):
667
yield revision_id, str(cur_revno), 0
766
br_rev_id = branch.last_revision()
767
670
if end_rev_id is None:
768
671
end_rev_id = br_rev_id
769
672
found_start = start_rev_id is None
770
graph_iter = graph.iter_lefthand_ancestry(end_rev_id,
771
(_mod_revision.NULL_REVISION,))
774
revision_id = next(graph_iter)
775
except StopIteration:
777
except errors.RevisionNotPresent as e:
779
yield e.revision_id, None, None
782
revno_str = _compute_revno_str(branch, revision_id)
783
if not found_start and revision_id == start_rev_id:
784
if not exclude_common_ancestry:
785
yield revision_id, revno_str, 0
673
for revision_id in repo.iter_reverse_revision_history(end_rev_id):
674
revno = branch.revision_id_to_dotted_revno(revision_id)
675
revno_str = '.'.join(str(n) for n in revno)
676
if not found_start and revision_id == start_rev_id:
677
if not exclude_common_ancestry:
789
678
yield revision_id, revno_str, 0
791
raise _StartNotLinearAncestor()
682
yield revision_id, revno_str, 0
685
raise _StartNotLinearAncestor()
794
688
def _graph_view_revisions(branch, start_rev_id, end_rev_id,
835
729
yield rev_id, '.'.join(map(str, revno)), merge_depth
732
@deprecated_function(deprecated_in((2, 2, 0)))
733
def calculate_view_revisions(branch, start_revision, end_revision, direction,
734
specific_fileid, generate_merge_revisions):
735
"""Calculate the revisions to view.
737
:return: An iterator of (revision_id, dotted_revno, merge_depth) tuples OR
738
a list of the same tuples.
740
start_rev_id, end_rev_id = _get_revision_limits(branch, start_revision,
742
view_revisions = list(_calc_view_revisions(branch, start_rev_id, end_rev_id,
743
direction, generate_merge_revisions or specific_fileid))
745
view_revisions = _filter_revisions_touching_file_id(branch,
746
specific_fileid, view_revisions,
747
include_merges=generate_merge_revisions)
748
return _rebase_merge_depth(view_revisions)
838
751
def _rebase_merge_depth(view_revisions):
839
752
"""Adjust depths upwards so the top level is 0."""
840
753
# If either the first or last revision have a merge_depth of 0, we're done
841
754
if view_revisions and view_revisions[0][2] and view_revisions[-1][2]:
842
min_depth = min([d for r, n, d in view_revisions])
755
min_depth = min([d for r,n,d in view_revisions])
843
756
if min_depth != 0:
844
view_revisions = [(r, n, d - min_depth)
845
for r, n, d in view_revisions]
757
view_revisions = [(r,n,d-min_depth) for r,n,d in view_revisions]
846
758
return view_revisions
849
761
def make_log_rev_iterator(branch, view_revisions, generate_delta, search,
850
file_ids=None, direction='reverse'):
762
file_ids=None, direction='reverse'):
851
763
"""Create a revision iterator for log.
853
765
:param branch: The branch being logged.
864
776
# Convert view_revisions into (view, None, None) groups to fit with
865
777
# the standard interface here.
866
if isinstance(view_revisions, list):
778
if type(view_revisions) == list:
867
779
# A single batch conversion is faster than many incremental ones.
868
780
# As we have all the data, do a batch conversion.
869
781
nones = [None] * len(view_revisions)
870
log_rev_iterator = iter([list(zip(view_revisions, nones, nones))])
782
log_rev_iterator = iter([zip(view_revisions, nones, nones)])
873
785
for view in view_revisions:
877
789
# It would be nicer if log adapters were first class objects
878
790
# with custom parameters. This will do for now. IGC 20090127
879
791
if adapter == _make_delta_filter:
880
log_rev_iterator = adapter(
881
branch, generate_delta, search, log_rev_iterator, file_ids,
792
log_rev_iterator = adapter(branch, generate_delta,
793
search, log_rev_iterator, file_ids, direction)
884
log_rev_iterator = adapter(
885
branch, generate_delta, search, log_rev_iterator)
795
log_rev_iterator = adapter(branch, generate_delta,
796
search, log_rev_iterator)
886
797
return log_rev_iterator
889
def _make_search_filter(branch, generate_delta, match, log_rev_iterator):
800
def _make_search_filter(branch, generate_delta, search, log_rev_iterator):
890
801
"""Create a filtered iterator of log_rev_iterator matching on a regex.
892
803
:param branch: The branch being logged.
893
804
:param generate_delta: Whether to generate a delta for each revision.
894
:param match: A dictionary with properties as keys and lists of strings
895
as values. To match, a revision may match any of the supplied strings
896
within a single property but must match at least one string for each
805
:param search: A user text search string.
898
806
:param log_rev_iterator: An input iterator containing all revisions that
899
807
could be displayed, in lists.
900
808
:return: An iterator over lists of ((rev_id, revno, merge_depth), rev,
904
812
return log_rev_iterator
905
# Use lazy_compile so mapping to InvalidPattern error occurs.
906
searchRE = [(k, [lazy_regex.lazy_compile(x, re.IGNORECASE) for x in v])
907
for k, v in match.items()]
908
return _filter_re(searchRE, log_rev_iterator)
911
def _filter_re(searchRE, log_rev_iterator):
813
searchRE = re.compile(search, re.IGNORECASE)
814
return _filter_message_re(searchRE, log_rev_iterator)
817
def _filter_message_re(searchRE, log_rev_iterator):
912
818
for revs in log_rev_iterator:
913
new_revs = [rev for rev in revs if _match_filter(searchRE, rev[1])]
918
def _match_filter(searchRE, rev):
920
'message': (rev.message,),
921
'committer': (rev.committer,),
922
'author': (rev.get_apparent_authors()),
923
'bugs': list(rev.iter_bugs())
925
strings[''] = [item for inner_list in strings.values()
926
for item in inner_list]
927
for k, v in searchRE:
928
if k in strings and not _match_any_filter(strings[k], v):
933
def _match_any_filter(strings, res):
934
return any(r.search(s) for r in res for s in strings)
820
for (rev_id, revno, merge_depth), rev, delta in revs:
821
if searchRE.search(rev.message):
822
new_revs.append(((rev_id, revno, merge_depth), rev, delta))
937
826
def _make_delta_filter(branch, generate_delta, search, log_rev_iterator,
938
fileids=None, direction='reverse'):
827
fileids=None, direction='reverse'):
939
828
"""Add revision deltas to a log iterator if needed.
941
830
:param branch: The branch being logged.
984
873
if delta_type == 'full' and not check_fileids:
985
874
deltas = repository.get_deltas_for_revisions(revisions)
986
for rev, delta in zip(revs, deltas):
875
for rev, delta in izip(revs, deltas):
987
876
new_revs.append((rev[0], rev[1], delta))
989
878
deltas = repository.get_deltas_for_revisions(revisions, fileid_set)
990
for rev, delta in zip(revs, deltas):
879
for rev, delta in izip(revs, deltas):
991
880
if check_fileids:
992
881
if delta is None or not delta.has_changed():
1012
901
def _update_fileids(delta, fileids, stop_on):
1013
902
"""Update the set of file-ids to search based on file lifecycle events.
1015
904
:param fileids: a set of fileids to update
1016
905
:param stop_on: either 'add' or 'remove' - take file-ids out of the
1017
906
fileids set once their add or remove entry is detected respectively
1019
908
if stop_on == 'add':
1020
for item in delta.added + delta.copied:
1021
if item.file_id in fileids:
1022
fileids.remove(item.file_id)
909
for item in delta.added:
910
if item[1] in fileids:
911
fileids.remove(item[1])
1023
912
elif stop_on == 'delete':
1024
913
for item in delta.removed:
1025
if item.file_id in fileids:
1026
fileids.remove(item.file_id)
914
if item[1] in fileids:
915
fileids.remove(item[1])
1029
918
def _make_revision_objects(branch, generate_delta, search, log_rev_iterator):
1041
930
for revs in log_rev_iterator:
1042
931
# r = revision_id, n = revno, d = merge depth
1043
932
revision_ids = [view[0] for view, _, _ in revs]
1044
revisions = dict(repository.iter_revisions(revision_ids))
1045
yield [(rev[0], revisions[rev[0][0]], rev[2]) for rev in revs]
933
revisions = repository.get_revisions(revision_ids)
934
revs = [(rev[0], revision, rev[2]) for rev, revision in
935
izip(revs, revisions)]
1048
939
def _make_batch_filter(branch, generate_delta, search, log_rev_iterator):
1082
975
:return: (start_rev_id, end_rev_id) tuple.
977
branch_revno, branch_rev_id = branch.last_revision_info()
1084
978
start_rev_id = None
1086
if start_revision is not None:
1087
if not isinstance(start_revision, revisionspec.RevisionInfo):
1088
raise TypeError(start_revision)
1089
start_rev_id = start_revision.rev_id
1090
start_revno = start_revision.revno
1091
if start_revno is None:
979
if start_revision is None:
982
if isinstance(start_revision, revisionspec.RevisionInfo):
983
start_rev_id = start_revision.rev_id
984
start_revno = start_revision.revno or 1
986
branch.check_real_revno(start_revision)
987
start_revno = start_revision
988
start_rev_id = branch.get_rev_id(start_revno)
1094
990
end_rev_id = None
1096
if end_revision is not None:
1097
if not isinstance(end_revision, revisionspec.RevisionInfo):
1098
raise TypeError(start_revision)
1099
end_rev_id = end_revision.rev_id
1100
end_revno = end_revision.revno
991
if end_revision is None:
992
end_revno = branch_revno
994
if isinstance(end_revision, revisionspec.RevisionInfo):
995
end_rev_id = end_revision.rev_id
996
end_revno = end_revision.revno or branch_revno
998
branch.check_real_revno(end_revision)
999
end_revno = end_revision
1000
end_rev_id = branch.get_rev_id(end_revno)
1102
if branch.last_revision() != _mod_revision.NULL_REVISION:
1002
if branch_revno != 0:
1103
1003
if (start_rev_id == _mod_revision.NULL_REVISION
1104
or end_rev_id == _mod_revision.NULL_REVISION):
1105
raise errors.BzrCommandError(
1106
gettext('Logging revision 0 is invalid.'))
1107
if end_revno is not None and start_revno > end_revno:
1108
raise errors.BzrCommandError(
1109
gettext("Start revision must be older than the end revision."))
1004
or end_rev_id == _mod_revision.NULL_REVISION):
1005
raise errors.BzrCommandError('Logging revision 0 is invalid.')
1006
if start_revno > end_revno:
1007
raise errors.BzrCommandError("Start revision must be older than "
1008
"the end revision.")
1110
1009
return (start_rev_id, end_rev_id)
1160
1059
end_revno = end_revision
1162
1061
if ((start_rev_id == _mod_revision.NULL_REVISION)
1163
or (end_rev_id == _mod_revision.NULL_REVISION)):
1164
raise errors.BzrCommandError(gettext('Logging revision 0 is invalid.'))
1062
or (end_rev_id == _mod_revision.NULL_REVISION)):
1063
raise errors.BzrCommandError('Logging revision 0 is invalid.')
1165
1064
if start_revno > end_revno:
1166
raise errors.BzrCommandError(gettext("Start revision must be older "
1167
"than the end revision."))
1065
raise errors.BzrCommandError("Start revision must be older than "
1066
"the end revision.")
1169
1068
if end_revno < start_revno:
1170
1069
return None, None, None, None
1171
1070
cur_revno = branch_revno
1173
1072
mainline_revs = []
1174
graph = branch.repository.get_graph()
1175
for revision_id in graph.iter_lefthand_ancestry(
1176
branch_last_revision, (_mod_revision.NULL_REVISION,)):
1073
for revision_id in branch.repository.iter_reverse_revision_history(
1074
branch_last_revision):
1177
1075
if cur_revno < start_revno:
1178
1076
# We have gone far enough, but we always add 1 more revision
1179
1077
rev_nos[revision_id] = cur_revno
1193
1091
return mainline_revs, rev_nos, start_rev_id, end_rev_id
1094
@deprecated_function(deprecated_in((2, 2, 0)))
1095
def _filter_revision_range(view_revisions, start_rev_id, end_rev_id):
1096
"""Filter view_revisions based on revision ranges.
1098
:param view_revisions: A list of (revision_id, dotted_revno, merge_depth)
1099
tuples to be filtered.
1101
:param start_rev_id: If not NONE specifies the first revision to be logged.
1102
If NONE then all revisions up to the end_rev_id are logged.
1104
:param end_rev_id: If not NONE specifies the last revision to be logged.
1105
If NONE then all revisions up to the end of the log are logged.
1107
:return: The filtered view_revisions.
1109
if start_rev_id or end_rev_id:
1110
revision_ids = [r for r, n, d in view_revisions]
1112
start_index = revision_ids.index(start_rev_id)
1115
if start_rev_id == end_rev_id:
1116
end_index = start_index
1119
end_index = revision_ids.index(end_rev_id)
1121
end_index = len(view_revisions) - 1
1122
# To include the revisions merged into the last revision,
1123
# extend end_rev_id down to, but not including, the next rev
1124
# with the same or lesser merge_depth
1125
end_merge_depth = view_revisions[end_index][2]
1127
for index in xrange(end_index+1, len(view_revisions)+1):
1128
if view_revisions[index][2] <= end_merge_depth:
1129
end_index = index - 1
1132
# if the search falls off the end then log to the end as well
1133
end_index = len(view_revisions) - 1
1134
view_revisions = view_revisions[start_index:end_index+1]
1135
return view_revisions
1196
1138
def _filter_revisions_touching_file_id(branch, file_id, view_revisions,
1197
include_merges=True):
1139
include_merges=True):
1198
1140
r"""Return the list of revision ids which touch a given file id.
1200
1142
The function filters view_revisions and returns a subset.
1201
1143
This includes the revisions which directly change the file id,
1202
1144
and the revisions which merge these changes. So if the
1203
1145
revision graph is::
1245
1184
# indexing layer. We might consider passing in hints as to the known
1246
1185
# access pattern (sparse/clustered, high success rate/low success
1247
1186
# rate). This particular access is clustered with a low success rate.
1187
get_parent_map = branch.repository.texts.get_parent_map
1248
1188
modified_text_revisions = set()
1249
1189
chunk_size = 1000
1250
for start in range(0, len(text_keys), chunk_size):
1190
for start in xrange(0, len(text_keys), chunk_size):
1251
1191
next_keys = text_keys[start:start + chunk_size]
1252
1192
# Only keep the revision_id portion of the key
1253
1193
modified_text_revisions.update(
1220
@deprecated_function(deprecated_in((2, 2, 0)))
1221
def get_view_revisions(mainline_revs, rev_nos, branch, direction,
1222
include_merges=True):
1223
"""Produce an iterator of revisions to show
1224
:return: an iterator of (revision_id, revno, merge_depth)
1225
(if there is no revno for a revision, None is supplied)
1227
if not include_merges:
1228
revision_ids = mainline_revs[1:]
1229
if direction == 'reverse':
1230
revision_ids.reverse()
1231
for revision_id in revision_ids:
1232
yield revision_id, str(rev_nos[revision_id]), 0
1234
graph = branch.repository.get_graph()
1235
# This asks for all mainline revisions, which means we only have to spider
1236
# sideways, rather than depth history. That said, its still size-of-history
1237
# and should be addressed.
1238
# mainline_revisions always includes an extra revision at the beginning, so
1240
parent_map = dict(((key, value) for key, value in
1241
graph.iter_ancestry(mainline_revs[1:]) if value is not None))
1242
# filter out ghosts; merge_sort errors on ghosts.
1243
rev_graph = _mod_repository._strip_NULL_ghosts(parent_map)
1244
merge_sorted_revisions = tsort.merge_sort(
1248
generate_revno=True)
1250
if direction == 'forward':
1251
# forward means oldest first.
1252
merge_sorted_revisions = reverse_by_depth(merge_sorted_revisions)
1253
elif direction != 'reverse':
1254
raise ValueError('invalid direction %r' % direction)
1256
for (sequence, rev_id, merge_depth, revno, end_of_merge
1257
) in merge_sorted_revisions:
1258
yield rev_id, '.'.join(map(str, revno)), merge_depth
1280
1261
def reverse_by_depth(merge_sorted_revisions, _depth=0):
1281
1262
"""Reverse revisions by depth.
1283
1264
Revisions with a different depth are sorted as a group with the previous
1284
revision of that depth. There may be no topological justification for this
1265
revision of that depth. There may be no topological justification for this,
1285
1266
but it looks much nicer.
1287
1268
# Add a fake revision at start so that we can always attach sub revisions
1342
1319
to indicate which LogRevision attributes it supports:
1344
1321
- supports_delta must be True if this log formatter supports delta.
1345
Otherwise the delta attribute may not be populated. The 'delta_format'
1346
attribute describes whether the 'short_status' format (1) or the long
1347
one (2) should be used.
1322
Otherwise the delta attribute may not be populated. The 'delta_format'
1323
attribute describes whether the 'short_status' format (1) or the long
1324
one (2) should be used.
1349
1326
- supports_merge_revisions must be True if this log formatter supports
1350
merge revisions. If not, then only mainline revisions will be passed
1327
merge revisions. If not, then only mainline revisions will be passed
1353
1330
- preferred_levels is the number of levels this formatter defaults to.
1354
The default value is zero meaning display all levels.
1355
This value is only relevant if supports_merge_revisions is True.
1331
The default value is zero meaning display all levels.
1332
This value is only relevant if supports_merge_revisions is True.
1357
1334
- supports_tags must be True if this log formatter supports tags.
1358
Otherwise the tags attribute may not be populated.
1335
Otherwise the tags attribute may not be populated.
1360
1337
- supports_diff must be True if this log formatter supports diffs.
1361
Otherwise the diff attribute may not be populated.
1363
- supports_signatures must be True if this log formatter supports GPG
1338
Otherwise the diff attribute may not be populated.
1366
1340
Plugins can register functions to show custom revision properties using
1367
1341
the properties_handler_registry. The registered function
1368
must respect the following interface description::
1342
must respect the following interface description:
1370
1343
def my_show_properties(properties_dict):
1371
1344
# code that returns a dict {'name':'value'} of the properties
1395
1368
self.to_file = to_file
1396
1369
# 'exact' stream used to show diff, it should print content 'as is'
1397
# and should not try to decode/encode it to unicode to avoid bug
1370
# and should not try to decode/encode it to unicode to avoid bug #328007
1399
1371
if to_exact_file is not None:
1400
1372
self.to_exact_file = to_exact_file
1402
# XXX: somewhat hacky; this assumes it's a codec writer; it's
1403
# better for code that expects to get diffs to pass in the exact
1374
# XXX: somewhat hacky; this assumes it's a codec writer; it's better
1375
# for code that expects to get diffs to pass in the exact file
1405
1377
self.to_exact_file = getattr(to_file, 'stream', to_file)
1406
1378
self.show_ids = show_ids
1407
1379
self.show_timezone = show_timezone
1408
1380
if delta_format is None:
1409
1381
# Ensures backward compatibility
1410
delta_format = 2 # long format
1382
delta_format = 2 # long format
1411
1383
self.delta_format = delta_format
1412
1384
self.levels = levels
1413
1385
self._show_advice = show_advice
1588
1554
lines = [_LONG_SEP]
1589
1555
if revision.revno is not None:
1590
1556
lines.append('revno: %s%s' % (revision.revno,
1591
self.merge_marker(revision)))
1557
self.merge_marker(revision)))
1592
1558
if revision.tags:
1593
lines.append('tags: %s' % (', '.join(sorted(revision.tags))))
1594
if self.show_ids or revision.revno is None:
1595
lines.append('revision-id: %s' %
1596
(revision.rev.revision_id.decode('utf-8'),))
1559
lines.append('tags: %s' % (', '.join(revision.tags)))
1597
1560
if self.show_ids:
1561
lines.append('revision-id: %s' % (revision.rev.revision_id,))
1598
1562
for parent_id in revision.rev.parent_ids:
1599
lines.append('parent: %s' % (parent_id.decode('utf-8'),))
1563
lines.append('parent: %s' % (parent_id,))
1600
1564
lines.extend(self.custom_properties(revision.rev))
1602
1566
committer = revision.rev.committer
1627
1588
to_file.write("%s%s\n" % (indent, ('\n' + indent).join(lines)))
1628
1589
if revision.delta is not None:
1629
1590
# Use the standard status output to display changes
1630
from breezy.delta import report_delta
1631
report_delta(to_file, revision.delta, short_status=False,
1591
from bzrlib.delta import report_delta
1592
report_delta(to_file, revision.delta, short_status=False,
1632
1593
show_ids=self.show_ids, indent=indent)
1633
1594
if revision.diff is not None:
1634
1595
to_file.write(indent + 'diff:\n')
1678
1639
to_file = self.to_file
1680
1641
if revision.tags:
1681
tags = ' {%s}' % (', '.join(sorted(revision.tags)))
1642
tags = ' {%s}' % (', '.join(revision.tags))
1682
1643
to_file.write(indent + "%*s %s\t%s%s%s\n" % (revno_width,
1683
revision.revno or "", self.short_author(
1685
format_date(revision.rev.timestamp,
1686
revision.rev.timezone or 0,
1687
self.show_timezone, date_fmt="%Y-%m-%d",
1689
tags, self.merge_marker(revision)))
1690
self.show_properties(revision.rev, indent + offset)
1691
if self.show_ids or revision.revno is None:
1644
revision.revno, self.short_author(revision.rev),
1645
format_date(revision.rev.timestamp,
1646
revision.rev.timezone or 0,
1647
self.show_timezone, date_fmt="%Y-%m-%d",
1649
tags, self.merge_marker(revision)))
1650
self.show_properties(revision.rev, indent+offset)
1692
1652
to_file.write(indent + offset + 'revision-id:%s\n'
1693
% (revision.rev.revision_id.decode('utf-8'),))
1653
% (revision.rev.revision_id,))
1694
1654
if not revision.rev.message:
1695
1655
to_file.write(indent + offset + '(no message)\n')
1701
1661
if revision.delta is not None:
1702
1662
# Use the standard status output to display changes
1703
from breezy.delta import report_delta
1704
report_delta(to_file, revision.delta,
1705
short_status=self.delta_format == 1,
1663
from bzrlib.delta import report_delta
1664
report_delta(to_file, revision.delta,
1665
short_status=self.delta_format==1,
1706
1666
show_ids=self.show_ids, indent=indent + offset)
1707
1667
if revision.diff is not None:
1708
1668
self.show_diff(self.to_exact_file, revision.diff, ' ')
1742
1702
def log_revision(self, revision):
1743
1703
indent = ' ' * revision.merge_depth
1744
1704
self.to_file.write(self.log_string(revision.revno, revision.rev,
1745
self._max_chars, revision.tags, indent))
1705
self._max_chars, revision.tags, indent))
1746
1706
self.to_file.write('\n')
1748
1708
def log_string(self, revno, rev, max_chars, tags=None, prefix=''):
1749
1709
"""Format log info into one string. Truncate tail of string
1751
:param revno: revision number or None.
1752
Revision numbers counts from 1.
1753
:param rev: revision object
1754
:param max_chars: maximum length of resulting string
1755
:param tags: list of tags or None
1756
:param prefix: string to prefix each line
1757
:return: formatted truncated string
1710
:param revno: revision number or None.
1711
Revision numbers counts from 1.
1712
:param rev: revision object
1713
:param max_chars: maximum length of resulting string
1714
:param tags: list of tags or None
1715
:param prefix: string to prefix each line
1716
:return: formatted truncated string
1761
1720
# show revno only when is not None
1762
1721
out.append("%s:" % revno)
1763
if max_chars is not None:
1764
out.append(self.truncate(
1765
self.short_author(rev), (max_chars + 3) // 4))
1767
out.append(self.short_author(rev))
1722
out.append(self.truncate(self.short_author(rev), 20))
1768
1723
out.append(self.date_string(rev))
1769
1724
if len(rev.parent_ids) > 1:
1770
1725
out.append('[merge]')
1772
tag_str = '{%s}' % (', '.join(sorted(tags)))
1727
tag_str = '{%s}' % (', '.join(tags))
1773
1728
out.append(tag_str)
1774
1729
out.append(rev.get_summary())
1775
1730
return self.truncate(prefix + " ".join(out).rstrip('\n'), max_chars)
1791
1746
show_offset=False)
1792
1747
committer_str = self.authors(revision.rev, 'first', sep=', ')
1793
1748
committer_str = committer_str.replace(' <', ' <')
1794
to_file.write('%s %s\n\n' % (date_str, committer_str))
1749
to_file.write('%s %s\n\n' % (date_str,committer_str))
1796
1751
if revision.delta is not None and revision.delta.has_changed():
1797
1752
for c in revision.delta.added + revision.delta.removed + revision.delta.modified:
1798
if c.path[0] is None:
1802
1754
to_file.write('\t* %s:\n' % (path,))
1803
for c in revision.delta.renamed + revision.delta.copied:
1755
for c in revision.delta.renamed:
1756
oldpath,newpath = c[:2]
1804
1757
# For renamed files, show both the old and the new path
1805
to_file.write('\t* %s:\n\t* %s:\n' % (c.path[0], c.path[1]))
1758
to_file.write('\t* %s:\n\t* %s:\n' % (oldpath,newpath))
1806
1759
to_file.write('\n')
1808
1761
if not revision.rev.message:
1831
1784
return self.get(name)(*args, **kwargs)
1833
1786
def get_default(self, branch):
1834
c = branch.get_config_stack()
1835
return self.get(c.get('log_format'))
1787
return self.get(branch.get_config().log_format())
1838
1790
log_formatter_registry = LogFormatterRegistry()
1841
1793
log_formatter_registry.register('short', ShortLogFormatter,
1842
'Moderately short log format.')
1794
'Moderately short log format')
1843
1795
log_formatter_registry.register('long', LongLogFormatter,
1844
'Detailed log format.')
1796
'Detailed log format')
1845
1797
log_formatter_registry.register('line', LineLogFormatter,
1846
'Log format with one line per revision.')
1798
'Log format with one line per revision')
1847
1799
log_formatter_registry.register('gnu-changelog', GnuChangelogLogFormatter,
1848
'Format used by GNU ChangeLog files.')
1800
'Format used by GNU ChangeLog files')
1851
1803
def register_formatter(name, formatter):
1913
1870
# This is the first index which is different between
1915
1872
base_idx = None
1916
for i in range(max(len(new_rh), len(old_rh))):
1873
for i in xrange(max(len(new_rh),
1917
1875
if (len(new_rh) <= i
1918
1876
or len(old_rh) <= i
1919
or new_rh[i] != old_rh[i]):
1877
or new_rh[i] != old_rh[i]):
1923
1881
if base_idx is None:
1924
1882
to_file.write('Nothing seems to have changed\n')
1926
# TODO: It might be nice to do something like show_log
1927
# and show the merged entries. But since this is the
1928
# removed revisions, it shouldn't be as important
1884
## TODO: It might be nice to do something like show_log
1885
## and show the merged entries. But since this is the
1886
## removed revisions, it shouldn't be as important
1929
1887
if base_idx < len(old_rh):
1930
to_file.write('*' * 60)
1888
to_file.write('*'*60)
1931
1889
to_file.write('\nRemoved Revisions:\n')
1932
1890
for i in range(base_idx, len(old_rh)):
1933
1891
rev = branch.repository.get_revision(old_rh[i])
1934
lr = LogRevision(rev, i + 1, 0, None)
1892
lr = LogRevision(rev, i+1, 0, None)
1935
1893
lf.log_revision(lr)
1936
to_file.write('*' * 60)
1894
to_file.write('*'*60)
1937
1895
to_file.write('\n\n')
1938
1896
if base_idx < len(new_rh):
1939
1897
to_file.write('Added Revisions:\n')
1940
1898
show_log(branch,
1943
1902
direction='forward',
1944
start_revision=base_idx + 1,
1903
start_revision=base_idx+1,
1945
1904
end_revision=len(new_rh),
2015
1973
log_format = log_formatter_registry.get_default(branch)
2016
1974
lf = log_format(show_ids=False, to_file=output, show_timezone='original')
2017
1975
if old_history != []:
2018
output.write('*' * 60)
1976
output.write('*'*60)
2019
1977
output.write('\nRemoved Revisions:\n')
2020
1978
show_flat_log(branch.repository, old_history, old_revno, lf)
2021
output.write('*' * 60)
1979
output.write('*'*60)
2022
1980
output.write('\n\n')
2023
1981
if new_history != []:
2024
1982
output.write('Added Revisions:\n')
2025
1983
start_revno = new_revno - len(new_history) + 1
2026
show_log(branch, lf, verbose=False, direction='forward',
2027
start_revision=start_revno)
1984
show_log(branch, lf, None, verbose=False, direction='forward',
1985
start_revision=start_revno,)
2030
1988
def show_flat_log(repository, history, last_revno, lf):
2035
1993
:param last_revno: The revno of the last revision_id in the history.
2036
1994
:param lf: The log formatter to use.
1996
start_revno = last_revno - len(history) + 1
2038
1997
revisions = repository.get_revisions(history)
2039
1998
for i, rev in enumerate(revisions):
2040
1999
lr = LogRevision(rev, i + last_revno, 0, None)
2041
2000
lf.log_revision(lr)
2044
def _get_info_for_log_files(revisionspec_list, file_list, exit_stack):
2003
def _get_info_for_log_files(revisionspec_list, file_list, add_cleanup):
2045
2004
"""Find file-ids and kinds given a list of files and a revision range.
2047
2006
We search for files at the end of the range. If not found there,
2051
2010
:param file_list: the list of paths given on the command line;
2052
2011
the first of these can be a branch location or a file path,
2053
2012
the remainder must be file paths
2054
:param exit_stack: When the branch returned is read locked,
2055
an unlock call will be queued to the exit stack.
2013
:param add_cleanup: When the branch returned is read locked,
2014
an unlock call will be queued to the cleanup.
2056
2015
:return: (branch, info_list, start_rev_info, end_rev_info) where
2057
2016
info_list is a list of (relative_path, file_id, kind) tuples where
2058
2017
kind is one of values 'directory', 'file', 'symlink', 'tree-reference'.
2059
2018
branch will be read-locked.
2061
from breezy.builtins import _get_revision_range
2062
tree, b, path = controldir.ControlDir.open_containing_tree_or_branch(
2064
exit_stack.enter_context(b.lock_read())
2020
from builtins import _get_revision_range, safe_relpath_files
2021
tree, b, path = bzrdir.BzrDir.open_containing_tree_or_branch(file_list[0])
2022
add_cleanup(b.lock_read().unlock)
2065
2023
# XXX: It's damn messy converting a list of paths to relative paths when
2066
2024
# those paths might be deleted ones, they might be on a case-insensitive
2067
2025
# filesystem and/or they might be in silly locations (like another branch).
2071
2029
# case of running log in a nested directory, assuming paths beyond the
2072
2030
# first one haven't been deleted ...
2074
relpaths = [path] + tree.safe_relpath_files(file_list[1:])
2032
relpaths = [path] + safe_relpath_files(tree, file_list[1:])
2076
2034
relpaths = [path] + file_list[1:]
2078
2036
start_rev_info, end_rev_info = _get_revision_range(revisionspec_list, b,
2080
2038
if relpaths in ([], [u'']):
2081
2039
return b, [], start_rev_info, end_rev_info
2082
2040
if start_rev_info is None and end_rev_info is None:
2132
2090
tree1 = b.repository.revision_tree(rev_id)
2133
2091
file_id = tree1.path2id(fp)
2134
kind = _get_kind_for_file_id(tree1, fp, file_id)
2092
kind = _get_kind_for_file_id(tree1, file_id)
2135
2093
info_list.append((fp, file_id, kind))
2136
2094
return b, info_list, start_rev_info, end_rev_info
2139
def _get_kind_for_file_id(tree, path, file_id):
2097
def _get_kind_for_file_id(tree, file_id):
2140
2098
"""Return the kind of a file-id or None if it doesn't exist."""
2141
2099
if file_id is not None:
2142
return tree.kind(path)
2100
return tree.kind(file_id)
2147
2105
properties_handler_registry = registry.Registry()
2149
2107
# Use the properties handlers to print out bug information if available
2152
2108
def _bugs_properties_handler(revision):
2154
related_bug_urls = []
2155
for bug_url, status in revision.iter_bugs():
2156
if status == 'fixed':
2157
fixed_bug_urls.append(bug_url)
2158
elif status == 'related':
2159
related_bug_urls.append(bug_url)
2162
text = ngettext('fixes bug', 'fixes bugs', len(fixed_bug_urls))
2163
ret[text] = ' '.join(fixed_bug_urls)
2164
if related_bug_urls:
2165
text = ngettext('related bug', 'related bugs',
2166
len(related_bug_urls))
2167
ret[text] = ' '.join(related_bug_urls)
2109
if revision.properties.has_key('bugs'):
2110
bug_lines = revision.properties['bugs'].split('\n')
2111
bug_rows = [line.split(' ', 1) for line in bug_lines]
2112
fixed_bug_urls = [row[0] for row in bug_rows if
2113
len(row) > 1 and row[1] == 'fixed']
2116
return {'fixes bug(s)': ' '.join(fixed_bug_urls)}
2171
2119
properties_handler_registry.register('bugs_properties_handler',
2172
2120
_bugs_properties_handler)