hg site extension
 
(arne)
2012-06-04: Added a diffstat for every commit.

Added a diffstat for every commit.

diff --git a/site.py b/site.py
--- a/site.py
+++ b/site.py
@@ -25,8 +25,8 @@ import mercurial
 import ftplib
 import socket
 import datetime
-from mercurial import cmdutil, util
-from mercurial import commands
+from mercurial import cmdutil, util, scmutil
+from mercurial import commands, dispatch
 from mercurial.i18n import _
 from mercurial import hg, discovery
 
@@ -70,8 +70,10 @@ templates = {
     "printstyle": """ """,
     "manifesthead": """<h2>""" + _("Commit (click to see the diff)")+""": <a href='../../commit/{hex}.html'>{hex}</a></h2>
 <p>{desc}</p><p>{user}</p>
+    <h2>""" + _("Diffstat") + """</h2>
+<pre>{diffstat}</pre>
     <h2>""" + _("Files in this revision") + "</h2>", 
-    "commitlog": """\n<div style='float: right; padding-left: 0.5em'><em>({author|person})</em></div><strong> {date|shortdate}: <a href='{relativepath}src/{node}/index.html'>{desc|strip|fill68|firstline}</a></strong> <span style='font-size: xx-small'>{branches} {tags} {bookmarks}</span><p>{desc|escape}</p>\n"""
+    "commitlog": """\n<div style='float: right; padding-left: 0.5em'><em>({author|person})</em></div><strong> {date|shortdate}: <a href='{relativepath}src/{node}/index.html'>{desc|strip|fill68|firstline}</a></strong> <span style='font-size: xx-small'>{branches} {tags} {bookmarks}</span><p>{desc|escape}</p>\n""",
 }
 
 _indexregexp = re.compile("^\\.*index.html$")
@@ -400,13 +402,28 @@ def rawpath(target, ctx, filename):
     """Get the relative path to the static sourcefile for an already escaped filename."""
     return join(target,"raw",ctx.hex(),filename)
 
-def createindex(target, ctx):
+def ctxdiffstat(ui, repo, ctx):
+    """Get the diffstat of a change context."""
+    command = "log -r " + ctx.hex() + " --stat --color=never"
+    req = dispatch.request(command.split(), ui=ui, repo=repo)
+    ui.pushbuffer()
+    dispatch.dispatch(req)
+    # FIXME: remove the color in an elegant way instead of fudging like this.
+    return ui.popbuffer().replace(
+        "[0;33m","").replace(
+        "[0;32m","").replace(
+            "[0m", "").replace(
+            "[0;31m", "").replace(
+                "","")
+    
+def createindex(ui, repo, target, ctx):
     """Create an index page for the changecontext: the commit message + the user + all files in the changecontext."""
     # first the head
     index = templates["manifesthead"].replace(
         "{hex}", ctx.hex()).replace(
         "{desc}", ctx.description()).replace(
-            "{user}", ctx.user())
+            "{user}", ctx.user()).replace(
+                "{diffstat}", ctxdiffstat(ui, repo, ctx))
     # then the files
     index += "<ul>"
     for filename in ctx:
@@ -465,7 +482,7 @@ def writesourcetree(ui, repo, target, na
         except OSError: pass # exists
         with open(filepath, "w") as f:
             f.write(templates["head"].replace("{reponame}", "<a href='../../'>"+name+"</a>").replace("{title}", name))
-            f.write(createindex(target, ctx))
+            f.write(createindex(ui, repo, target, ctx))
             f.write(templates["foot"].replace("{reponame}", "<a href='../../'>"+name+"</a>"))
 
 def parsesite(ui, repo, target, **opts):