No need for repo parameter to JSON encoder.
authorDirkjan Ochtman <dirkjan@ochtman.nl>
Wed, 06 Aug 2008 15:42:39 +0200
changeset 38 e4fa26d9ea14031fee573a6868e8a4b7d01c2eea
parent 37 accff725eb903365de08e6bee1bf6db0ad649e69
child 39 8d8e307c084ed50e7969aaa7b91b199a71c1ed97
push id15
push usertmielczarek@mozilla.com
push dateWed, 13 Aug 2008 19:07:41 +0000
No need for repo parameter to JSON encoder.
hgwebjson.py
--- a/hgwebjson.py
+++ b/hgwebjson.py
@@ -6,34 +6,32 @@ from mercurial.hgweb.hgwebdir_mod import
 
 demandimport.disable()
 import simplejson
 demandimport.enable()
 
 isodate = lambda x: util.datestr(x, '%Y-%m-%d %H:%M %1%2')
 
 class HGJSONEncoder(simplejson.JSONEncoder):
-    def __init__(self, repo):
-        self.repo = repo
+    def __init__(self):
         simplejson.JSONEncoder.__init__(self, indent=1)
 
     def default(self, v):
         if isinstance(v, context.changectx):
             return {'rev':         v.rev(),
                     'node':        hex(v.node()),
                     'user':        v.user(),
                     'date':        isodate(v.date()),
                     'description': v.description(),
                     'branch':      v.branch(),
                     'tags':        v.tags(),
-                    'parents':     [hex(n) for n in
-                                    self.repo.changelog.parents(v.node())
+                    'parents':     [hex(n.node()) for n in v.parents()
                                     if n != nullid],
-                    'children':    [hex(n) for n in
-                                    self.repo.changelog.children(v.node())],
+                    'children':    [hex(n.node()) for n in v.children()
+                                    if n != nullid],
                     'files':       v.files(),
                     }
         
         if isinstance(v, context.filectx):
             return {'filerev':     v.filerev(),
                     'filenode':    hex(v.filenode())}
 
         if hasattr(v, '__iter__'):
@@ -55,26 +53,26 @@ cmdtable = {
 
 def addwebcommand(f, name):
     setattr(hgwebprotocol, name, f)
     hgwebprotocol.__all__.append(name)
 
 JSON_MIMETYPE = 'application/json'
 
 def heads(web, req):
-    e = HGJSONEncoder(web.repo)
+    e = HGJSONEncoder()
     resp = e.encode([web.repo.changectx(n) for n in web.repo.heads()])
     req.respond(HTTP_OK, JSON_MIMETYPE, length=len(resp))
     req.write(resp)
 
 addwebcommand(heads, 'jsonheads')
 
 def tags(web, req):
     tags = web.repo.tagslist()
-    e = HGJSONEncoder(web.repo)
+    e = HGJSONEncoder()
     resp = e.encode([{'tag': tag,
                       'changeset': web.repo.changectx(node)}
                      for tag, node in tags])
     req.respond(HTTP_OK, JSON_MIMETYPE, length=len(resp))
     req.write(resp)
 
 addwebcommand(tags, 'jsontags')
 
@@ -113,17 +111,17 @@ def family(web, req):
                      'nodes': nodelist})
     req.respond(HTTP_OK, JSON_MIMETYPE, length=len(resp))
     req.write(resp)
 
 addwebcommand(family, 'jsonfamily')    
 
 def info(web, req):
     """Get JSON information about the specified nodes."""
-    e = HGJSONEncoder(web.repo)
+    e = HGJSONEncoder()
     d = {}
     for node in req.form['node']:
         d[node] = web.repo.changectx(node)
 
     resp = e.encode(d)
     req.respond(HTTP_OK, JSON_MIMETYPE, length=len(resp))
     req.write(resp)