Refactor pushlogFeed() so that it's a normal webcommand.
authorDirkjan Ochtman <dirkjan@ochtman.nl>
Fri, 06 Feb 2009 16:57:23 +0100
changeset 56 cd5ef08c3002c4f71f3ae6da79813fd80d2f4c7f
parent 55 6db4ef76c839f52f482847e3c00cd18c84cc80d6
child 57 4087fe690caf171535611c8e3d0ae6401907f86a
push id30
push userdirkjan@ochtman.nl
push dateFri, 06 Feb 2009 20:58:39 +0000
Refactor pushlogFeed() so that it's a normal webcommand. Makes compatibility easier and makes sure various values are available that are no longer available to protocol commands in newer hg.
pushlog-feed.py
--- a/pushlog-feed.py
+++ b/pushlog-feed.py
@@ -278,66 +278,52 @@ def pushlogSetup(repo, req):
         query.userquery = req.form.get('user', [])
 
     #TODO: use rev here, switch page to ?page=foo ?
     if 'changeset' in req.form:
         query.changesetquery = req.form.get('changeset', [])
 
     query.DoQuery()
     return query
+
+def pushlogFeed(web, req, tmpl):
+    """WebCommand for producing the ATOM feed of the pushlog."""
     
-def pushlogFeed(web, req):
-    """WebCommand for producing the ATOM feed of the pushlog."""
+    req.form['style'] = ['atom']
+    tmpl = web.templater(req)
     query = pushlogSetup(web.repo, req)
     isotime = lambda x: datetime.utcfromtimestamp(x).isoformat() + 'Z'
     
     if query.entries:
         dt = isotime(query.entries[0][2])
     else:
         dt = datetime.utcnow().isoformat().split('.', 1)[0] + 'Z'
 
-    resp = ["""<?xml version="1.0" encoding="UTF-8"?>
-<feed xmlns="http://www.w3.org/2005/Atom">
- <id>%(urlbase)s%(url)spushlog</id>
- <link rel="self" href="%(urlbase)s%(url)spushlog" />
- <updated>%(date)s</updated>
- <title>%(reponame)s Pushlog</title>""" % {'urlbase': query.urlbase,
-                              'url': req.url,
-                              'reponame': query.reponame,
-                              'date': dt}];
+    data = {
+        'urlbase': query.urlbase,
+        'url': req.url,
+        'repo': query.reponame,
+        'date': dt,
+        'entries': [],
+    }
 
+    entries = data['entries']
     for id, user, date, node in query.entries:
         ctx = web.repo.changectx(node)
-        resp.append("""
- <entry>
-  <title>Changeset %(node)s</title>
-  <id>http://www.selenic.com/mercurial/#changeset-%(node)s</id>
-  <link href="%(urlbase)s%(url)srev/%(node)s" />
-  <updated>%(date)s</updated>
-  <author>
-   <name>%(user)s</name>
-  </author>
-  <content type="xhtml">
-    <div xmlns="http://www.w3.org/1999/xhtml">
-      <ul class="filelist"><li class="file">%(files)s</li></ul>
-    </div>
-  </content>
- </entry>""" % {'node': node,
-                'date': isotime(date),
-                'user': xmlescape(user),
-                'urlbase': query.urlbase,
-                'url': req.url,
-                'files': '</li><li class="file">'.join(ctx.files())})
+        entries.append({
+            'node': node,
+            'date': isotime(date),
+            'user': xmlescape(user),
+            'urlbase': query.urlbase,
+            'url': req.url,
+            'files': [{'name': fn} for fn in ctx.files()],
+        })
 
-    resp.append("</feed>")
-
-    resp = "".join(resp)
-
-    req.respond(HTTP_OK, ATOM_MIMETYPE, length=len(resp))
-    req.write(resp)
+    req.respond(HTTP_OK, ATOM_MIMETYPE)
+    return tmpl('pushlog', **data)
 
 def pushlogHTML(web, req, tmpl):
     """WebCommand for producing the HTML view of the pushlog."""
     query = pushlogSetup(web.repo, req)
 
     # these three functions are in webutil in newer hg, but not in hg 1.0
     def nodetagsdict(repo, node):
         return [{"name": i} for i in repo.nodetags(node)]
@@ -455,15 +441,15 @@ def printpushlog(ui, repo, *args):
     query.querystart = QueryType.PUSHID
     query.querystart_value = startID
     if endID is not None:
         query.queryend = QueryType.PUSHID
         query.queryend_value = endID
     query.DoQuery()
     print e.encode(pushes_worker(query))
 
-addcommand(pushlogFeed, 'pushlog')
+addwebcommand(pushlogFeed, 'pushlog')
 addwebcommand(pushlogHTML, 'pushloghtml')
 addwebcommand(pushes, 'pushes')
 
 cmdtable = {
     'printpushlog': (printpushlog, [], "hg printpushlog [startID [endID]]"),
 }