[PATCH 1 of 5] hgweb: enumerate lines in loop header, not before

Anton Shestakov av6 at dwimlabs.net
Thu Jul 14 03:31:26 EDT 2016


# HG changeset patch
# User Anton Shestakov <av6 at dwimlabs.net>
# Date 1468470824 -28800
#      Thu Jul 14 12:33:44 2016 +0800
# Node ID 1d5710a9fc8f764030af5c14bfef7da20eaea989
# Parent  5b70070b8716b58d3d3a75ce8646981492cfa5f3
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.

diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -875,13 +875,12 @@ def annotate(web, req, tmpl):
         if util.binary(fctx.data()):
             mt = (mimetypes.guess_type(fctx.path())[0]
                   or 'application/octet-stream')
-            lines = enumerate([((fctx.filectx(fctx.filerev()), 1),
-                                '(binary:%s)' % mt)])
+            lines = [((fctx.filectx(fctx.filerev()), 1), '(binary:%s)' % mt)]
         else:
-            lines = enumerate(fctx.annotate(follow=True, linenumber=True,
-                                            diffopts=diffopts))
+            lines = fctx.annotate(follow=True, linenumber=True,
+                                  diffopts=diffopts)
         previousrev = None
-        for lineno, ((f, targetline), l) in lines:
+        for lineno, ((f, targetline), l) in enumerate(lines):
             rev = f.rev()
             blockhead = rev != previousrev or None
             previousrev = rev


More information about the Mercurial-devel mailing list