[PATCH] trim author and description on gitweb summary page
TK Soh
teekaysoh at gmail.com
Fri Jun 2 10:37:39 CDT 2006
The trimming code has been adapted from original gitweb's CGI [perl]
script, and it looks a bit mysterious to me - without a tiny bit of
comment of the part of code. So, the filter names I used may not
reflect the true maximum length of the trimmed text.
-------------- next part --------------
# HG changeset patch
# User TK Soh <teekaysoh at yahoo.com>
# Date 1149262139 18000
# Node ID f7000016573a3fbe484193d3724666538b3218d5
# Parent 482d3fb47d80693f929101f95944bf019009dd79
gitweb: trim long description and author entries in summary page
diff -r 482d3fb47d80 -r f7000016573a mercurial/templater.py
--- a/mercurial/templater.py Thu Jun 01 19:08:29 2006 +0200
+++ b/mercurial/templater.py Fri Jun 02 10:28:59 2006 -0500
@@ -265,6 +265,17 @@ def indent(text, prefix):
if i < num_lines - 1 or text.endswith('\n'):
fp.write('\n')
return fp.getvalue()
+
+def trim(text, width, add_width=10):
+ '''trim a long line in one with tail'''
+ m = re.match(r'(.{0,%d}[^ \/\-_:\.@]{0,%d})(.*)' %
+ (width, add_width), text)
+ if m:
+ body, tail = m.groups()
+ if len(tail) > 4:
+ tail = " ..."
+ text = "%s%s" % (body, tail)
+ return text
common_filters = {
"addbreaks": nl2br,
@@ -287,6 +298,8 @@ common_filters = {
"shortdate": shortdate,
"stringify": stringify,
"strip": lambda x: x.strip(),
+ "trim20": lambda x: trim(x, 15, 5),
+ "trim60": lambda x: trim(x, 50, 10),
"urlescape": lambda x: urllib.quote(x),
"user": lambda x: util.shortuser(x),
}
diff -r 482d3fb47d80 -r f7000016573a templates/map-gitweb
--- a/templates/map-gitweb Thu Jun 01 19:08:29 2006 +0200
+++ b/templates/map-gitweb Fri Jun 02 10:28:59 2006 -0500
@@ -45,6 +45,6 @@ filediffchild = '<tr><th class="child">c
filediffchild = '<tr><th class="child">child #rev#:</th><td class="child"><a href="?cmd=changeset;node=#node#;style=gitweb">#node|short#</a></td></tr>'
filelogchild = '<tr><td align="right">child #rev#: </td><td><a href="?cmd=file;file=#file|urlescape#;filenode=#node#;style=gitweb">#node|short#</a></td></tr>'
shortlog = shortlog-gitweb.tmpl
-shortlogentry = '<tr class="parity#parity#"><td class="age"><i>#date|age# ago</i></td><td><i>#author#</i></td><td><a class="list" href="?cmd=changeset;node=#node|short#;style=gitweb"><b>#desc|strip|firstline|escape#</b></a></td><td class="link"><a href="?cmd=changeset;node=#node|short#;style=gitweb">changeset</a> | <a href="?cmd=manifest;manifest=#manifest|short#;path=/;style=gitweb">manifest</a></td></tr>'
+shortlogentry = '<tr class="parity#parity#"><td class="age"><i>#date|age# ago</i></td><td><i>#author|trim20#</i></td><td><a class="list" href="?cmd=changeset;node=#node|short#;style=gitweb"><b>#desc|strip|firstline|trim60|escape#</b></a></td><td class="link"><a href="?cmd=changeset;node=#node|short#;style=gitweb">changeset</a> | <a href="?cmd=manifest;manifest=#manifest|short#;path=/;style=gitweb">manifest</a></td></tr>'
filelogentry = '<tr class="parity#parity#"><td class="age"><i>#date|age# ago</i></td><td><a class="list" href="?cmd=changeset;node=#node|short#;style=gitweb"><b>#desc|strip|firstline|escape#</b></a></td><td class="link"><!-- FIXME: <a href="?fd=#node|short#;file=#file|urlescape#;style=gitweb">diff</a> | --> <a href="?fa=#filenode|short#;file=#file|urlescape#;style=gitweb">annotate</a> #rename%filelogrename#</td></tr>'
archiveentry = ' | <a href="?ca=#node|short#;type=#type|urlescape#">#type|escape#</a> '
More information about the Mercurial
mailing list