Patch to fix tab display when browsing source in hg serve and hgweb

Dave Hines mercurial at dph.fluff.org
Wed Jul 18 11:03:00 CDT 2012


Problem:
	When using a web browser to display files from a mercurial
server, using either a hg serv command or a cgi script in apache,
files containing leading tabs are displayed incorrectly. This is
because each line has seven characters (a six character line number
field and a space) prepended to it, with no adjustment to any tabs in
the line following.

Discussion:
	While there is some disagreement about how tab characters
should be interpreted, there is also a long standing de facto
convention that tab stops occur at every eighth character from the
start of a line, and there is a lot of hardware and software which
follows this scheme.

Solution:
	Changing mercurial/hgweb/webcommands.py so that the prepended
line number & space add eight characters to the start of each line
allows the correct display of files containing tabs, providing that
the file and display system both follow the convention discussed.
Other files should not be adversely affected by this change.

I attach a trivial patch which implements the change, which works here
on my computer.

Regards -- Dave Hines.
-------------- next part --------------
# HG changeset patch
# User Dave Hines <daveh at dph.fluff.org>
# Date 1342620274 -3600
# Branch stable
# Node ID 9b178e3bb43bd8f452a926f262ec45c472dd0118
# Parent  b013baa3898e117959984fc64c29d8c784d2f28b
Change the line number string to 8 characters so ASCII tabs render correctly in web listing pages

diff -r b013baa3898e -r 9b178e3bb43b mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py	Sun Jul 01 13:10:54 2012 -0500
+++ b/mercurial/hgweb/webcommands.py	Wed Jul 18 15:04:34 2012 +0100
@@ -76,7 +76,7 @@
         for lineno, t in enumerate(text.splitlines(True)):
             yield {"line": t,
                    "lineid": "l%d" % (lineno + 1),
-                   "linenumber": "% 6d" % (lineno + 1),
+                   "linenumber": "% 7d" % (lineno + 1),
                    "parity": parity.next()}
 
     return tmpl("filerevision",


More information about the Mercurial-devel mailing list