bug 479420 - make pushlog compatible with hg 1.1
authorTed Mielczarek <ted.mielczarek@gmail.com>
Thu, 02 Apr 2009 09:41:25 -0400
changeset 58 dec4385b03f6
parent 57 4087fe690caf
child 59 c88bf6c80d4e
push id32
push usertmielczarek@mozilla.com
push dateThu, 02 Apr 2009 13:41:29 +0000
bugs479420
bug 479420 - make pushlog compatible with hg 1.1
pushlog-feed.py
runtests.py
--- a/pushlog-feed.py
+++ b/pushlog-feed.py
@@ -1,10 +1,11 @@
 import mercurial.hgweb.protocol as hgwebprotocol
 import mercurial.hgweb.webcommands as hgwebcommands
+import mercurial.hgweb.webutil as webutil
 from mercurial.templatefilters import xmlescape
 from mercurial.hgweb.common import HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR, paritygen
 from mercurial.node import short, bin, hex
 from mercurial import demandimport
 
 import sys, os.path, re
 from datetime import datetime
 import time
@@ -372,19 +373,26 @@ def pushlogHTML(web, req, tmpl):
                 l.append({"parity": parity.next(),
                           "user": user,
                           "date": localdate(date),
                           'numchanges': 0,
                           "changes": []})
                 ch = l[-1]['changes']
             ctx = web.repo.changectx(node)
             n = ctx.node()
+            # useless fallback
+            listfilediffs = lambda a,b,c: []
+            if hasattr(webutil, 'listfilediffs'):
+                listfilediffs = lambda a,b,c: webutil.listfilediffs(a,b,c, len(b))
+            elif hasattr(web, 'listfilediffs'):
+                listfilediffs = web.listfilediffs
+
             ch.append({"author": ctx.user(),
                        "desc": ctx.description(),
-                       "files": web.listfilediffs(tmpl, ctx.files(), n),
+                       "files": listfilediffs(tmpl, ctx.files(), n),
                        "rev": ctx.rev(),
                        "node": hex(n),
                        "tags": nodetagsdict(web.repo, n),
                        "branches": nodebranchdict(web.repo, ctx),
                        "inbranch": nodeinbranch(web.repo, ctx),
                        "parity": l[-1]["parity"]
                        })
             l[-1]['numchanges'] += 1
--- a/runtests.py
+++ b/runtests.py
@@ -121,16 +121,26 @@ class TestPushlog(unittest.TestCase):
         sleep(1)
         os.environ['TZ'] = "America/New_York"
 
     def tearDown(self):
         # kill hgweb process
         if self.hgwebprocess is not None:
             os.kill(self.hgwebprocess.pid, SIGTERM)
             self.hgwebprocess = None
+
+    def testpushloghtml(self):
+        """Sanity check the html output."""
+        u = urlopen("http://localhost:8000/pushloghtml")
+        data = ''.join(u.readlines())
+        u.close()
+        # ensure we didn't hit a server error in the middle
+        self.assertEqual(data.find("Internal Server Error"), -1, "should not get an internal server error in the html output")
+        # crap test, but I don't want to parse html
+        self.assertNotEqual(data.find("427bfb5defee"), -1, "should have the latest changeset in the html output")
         
     def testalljsonpushes(self):
         """Get all json data from json-pushes."""
         testjson = loadjsonurl("http://localhost:8000/json-pushes?startID=0")
         expectedjson = loadjsonfile("testdata/test-repo-data.json")
         self.assertEqual(testjson, expectedjson, "json-pushes did not yield expected json data!")
 
     def testprintpushlog(self):