comparison mercurial/hgweb/webcommands.py @ 29538:df7d8ea90695

hgweb: enumerate lines in loop header, not before Doing this will allow access to the lines in arbitrary order (because the result of enumerate() is an iterator), and that will help calculating rowspan for annotate blocks.
author Anton Shestakov <av6@dwimlabs.net>
date Thu, 14 Jul 2016 12:33:44 +0800
parents 9c37df347485
children d86b54d9bb0c
comparison
equal deleted inserted replaced
29537:5f8b36d5a6ec 29538:df7d8ea90695
873 873
874 def annotate(**map): 874 def annotate(**map):
875 if util.binary(fctx.data()): 875 if util.binary(fctx.data()):
876 mt = (mimetypes.guess_type(fctx.path())[0] 876 mt = (mimetypes.guess_type(fctx.path())[0]
877 or 'application/octet-stream') 877 or 'application/octet-stream')
878 lines = enumerate([((fctx.filectx(fctx.filerev()), 1), 878 lines = [((fctx.filectx(fctx.filerev()), 1), '(binary:%s)' % mt)]
879 '(binary:%s)' % mt)])
880 else: 879 else:
881 lines = enumerate(fctx.annotate(follow=True, linenumber=True, 880 lines = fctx.annotate(follow=True, linenumber=True,
882 diffopts=diffopts)) 881 diffopts=diffopts)
883 previousrev = None 882 previousrev = None
884 for lineno, ((f, targetline), l) in lines: 883 for lineno, ((f, targetline), l) in enumerate(lines):
885 rev = f.rev() 884 rev = f.rev()
886 blockhead = rev != previousrev or None 885 blockhead = rev != previousrev or None
887 previousrev = rev 886 previousrev = rev
888 yield {"parity": next(parity), 887 yield {"parity": next(parity),
889 "node": f.hex(), 888 "node": f.hex(),