hg site extension
 
(Arne Babenhauserheide)
2011-10-07: create commit files, too.

create commit files, too.

diff --git a/static.py b/static.py
--- a/static.py
+++ b/static.py
@@ -15,7 +15,7 @@ without the interactivity).
 
 * Create the static-dir in the repo:
   - Overview: Readme + commits + template ✔
-  - Changes: Commit-Log + each commit as changeset/<hex>
+  - Changes: Commit-Log + each commit as commit/<hex> ✔
   - source: a filetree, shown as sourcecode: src/<path> and raw/<path>
   - if b is used: a bugtracker: issue/<id>/<name>
   - fork-/clone-info for each entry in [paths] with its incoming data (if it has some):
@@ -98,6 +98,8 @@ def writeoverview(ui, repo, target, name
 def writelog(ui, repo, target, name):
     """Write the full changelog, in steps of 100."""
     commits = join(target, "commits")
+
+    # create the folders
     if not isdir(commits):
         os.makedirs(commits)
     for i in range(len(repo.changelog)/100):
@@ -105,6 +107,7 @@ def writelog(ui, repo, target, name):
         if not isdir(d):
             os.makedirs(d)
 
+    # create the log files
     t = cmdutil.changeset_templater(ui, repo, patch=False, diffopts=None, mapfile=None, buffered=False)
     t.use_template("""<div style='float: right; padding-left: 0.5em'><em>({author|person})</em></div><strong> {date|shortdate}: <a href='../commit/{node}.html'>{desc|strip|fill68|firstline}</a> <span style='font-size: xx-small'>{branches} {tags}</span><p>{desc|escape}</p>""")
     logs = []
@@ -136,6 +139,32 @@ def writelog(ui, repo, target, name):
         l.close()
 
 
+def writecommits(ui, repo, target, name, force=False):
+    """Write all not yet existing commit files."""
+    commit = join(target, "commit")
+
+    # create the folders
+    if not isdir(commit):
+        os.makedirs(commit)
+
+    t = cmdutil.changeset_templater(ui, repo, patch=False, diffopts=None, mapfile=None, buffered=False)
+    t.use_template("""<div style='float: right; padding-left: 0.5em'><em>({author|person})</em></div><strong> {date|shortdate}: <a href='../commit/{node}.html'>{desc|strip|fill68|firstline}</a> <span style='font-size: xx-small'>{branches} {tags}</span><p>{desc|escape}</p>""")
+    for c in range(len(repo.changelog)):
+        ctx = repo.changectx(str(c))
+        cpath = join(commit, ctx.hex() + ".html")
+        if not force and isfile(cpath):
+            continue
+        with open(cpath, "w") as cf:
+            cf.write(templates["head"].replace("{reponame}", name))
+            ui.pushbuffer()
+            t.show(ctx)
+            cf.write(ui.popbuffer())
+            ui.pushbuffer()
+            commands.diff(ui, repo, change=str(c), git=True)
+            cf.write("<pre>"+ui.popbuffer().replace("<", "<")+"</pre>")
+            cf.write(templates["foot"].replace("{reponame}", name))
+
+
 def parsesite(ui, repo, target, **opts):
     """Create the static folder."""
     idfile = join(target, _staticidentifier)
@@ -174,6 +203,10 @@ def parsesite(ui, repo, target, **opts):
     # and the log
     writelog(ui, repo, target, name)
 
+    # and all commit files
+    writecommits(ui, repo, target, name, force=opts["force"])
+
+
 def addrepo(ui, repo, target):
     """Add the repo to the target and make sure it is up to date."""
     try:
@@ -206,6 +239,7 @@ cmdtable = {
                       ('a', 'all', None, 'parse all revisions (requires much space)'),
                       ('n', 'name', None, 'the repo name. Default: folder or last segment of the repo-path.'),
                       ('u', 'upload', None, 'upload the repo'),
+                      ('f', 'force', False, 'force recreating all commit files. Slow.'),
                       ('s', 'screenstyle', None, 'use a custom stylesheet for display on screen'),
                       ('p', 'printstyle', None, 'use a custom stylesheet for printing')],
                      "[options] [folder]")