Show More
@@ -369,6 +369,11 b' class annotateline(object):' | |||||
369 | # Whether this annotation was the result of a skip-annotate. |
|
369 | # Whether this annotation was the result of a skip-annotate. | |
370 | skip = attr.ib(default=False) |
|
370 | skip = attr.ib(default=False) | |
371 |
|
371 | |||
|
372 | def _countlines(text): | |||
|
373 | if text.endswith("\n"): | |||
|
374 | return text.count("\n") | |||
|
375 | return text.count("\n") + int(bool(text)) | |||
|
376 | ||||
372 | def _annotatepair(parents, childfctx, child, skipchild, diffopts): |
|
377 | def _annotatepair(parents, childfctx, child, skipchild, diffopts): | |
373 | r''' |
|
378 | r''' | |
374 | Given parent and child fctxes and annotate data for parents, for all lines |
|
379 | Given parent and child fctxes and annotate data for parents, for all lines | |
@@ -436,18 +441,13 b' def annotate(base, parents, linenumber=F' | |||||
436 | `parents(fctx)` is a function returning a list of parent filectxs. |
|
441 | `parents(fctx)` is a function returning a list of parent filectxs. | |
437 | """ |
|
442 | """ | |
438 |
|
443 | |||
439 | def lines(text): |
|
|||
440 | if text.endswith("\n"): |
|
|||
441 | return text.count("\n") |
|
|||
442 | return text.count("\n") + int(bool(text)) |
|
|||
443 |
|
||||
444 | if linenumber: |
|
444 | if linenumber: | |
445 | def decorate(text, rev): |
|
445 | def decorate(text, rev): | |
446 | return ([annotateline(fctx=rev, lineno=i) |
|
446 | return ([annotateline(fctx=rev, lineno=i) | |
447 | for i in xrange(1, lines(text) + 1)], text) |
|
447 | for i in xrange(1, _countlines(text) + 1)], text) | |
448 | else: |
|
448 | else: | |
449 | def decorate(text, rev): |
|
449 | def decorate(text, rev): | |
450 | return ([annotateline(fctx=rev)] * lines(text), text) |
|
450 | return ([annotateline(fctx=rev)] * _countlines(text), text) | |
451 |
|
451 | |||
452 | # This algorithm would prefer to be recursive, but Python is a |
|
452 | # This algorithm would prefer to be recursive, but Python is a | |
453 | # bit recursion-hostile. Instead we do an iterative |
|
453 | # bit recursion-hostile. Instead we do an iterative |
General Comments 0
You need to be logged in to leave comments.
Login now