[PATCH 1 of 5] hgweb: use scmutil.binnode() to translate None to wdir hash (issue5988)

Yuya Nishihara yuya at tcha.org
Sun Sep 23 13:28:17 UTC 2018


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1537686661 -32400
#      Sun Sep 23 16:11:01 2018 +0900
# Node ID dc7aae11254db3db8f8994c8dd620dd0a5963fab
# Parent  d25a329a22d1521efa61fcfec7530b7f99d10a95
hgweb: use scmutil.binnode() to translate None to wdir hash (issue5988)

I left some of ctx.node() calls unchanged as they seemed unlikely to be
workingctx, or passed to diff functions where None is the default value.

Note that a None revision can also cause a similar problem, but I'm not sure
if we can simply bulk-replace ctx.rev() with scmutil.intrev(ctx) as there's
large hole between tip revision and wdir revision. If such pair were passed
in to xrange() for example, we would waste CPU time.

diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -294,7 +294,7 @@ def _search(web):
 
         for ctx in searchfunc[0](funcarg):
             count += 1
-            n = ctx.node()
+            n = scmutil.binnode(ctx)
             showtags = webutil.showtag(web.repo, 'changelogtag', n)
             files = webutil.listfilediffs(ctx.files(), n, web.maxfiles)
 
@@ -521,7 +521,7 @@ def manifest(web):
         symrev = 'tip'
     path = webutil.cleanpath(web.repo, web.req.qsparams.get('file', ''))
     mf = ctx.manifest()
-    node = ctx.node()
+    node = scmutil.binnode(ctx)
 
     files = {}
     dirs = {}
@@ -868,7 +868,7 @@ def comparison(web):
     leftrev = parent.rev()
     leftnode = parent.node()
     rightrev = ctx.rev()
-    rightnode = ctx.node()
+    rightnode = scmutil.binnode(ctx)
     if path in ctx:
         fctx = ctx[path]
         rightlines = filelines(fctx)
diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -416,7 +416,7 @@ def _kwfunc(f):
     return f
 
 def commonentry(repo, ctx):
-    node = ctx.node()
+    node = scmutil.binnode(ctx)
     return {
         # TODO: perhaps ctx.changectx() should be assigned if ctx is a
         # filectx, but I'm not pretty sure if that would always work because
@@ -451,7 +451,7 @@ def changelistentry(web, ctx):
     '''
     repo = web.repo
     rev = ctx.rev()
-    n = ctx.node()
+    n = scmutil.binnode(ctx)
     showtags = showtag(repo, 'changelogtag', n)
     files = listfilediffs(ctx.files(), n, web.maxfiles)
 
@@ -485,7 +485,7 @@ def symrevorshortnode(req, ctx):
     if 'node' in req.qsparams:
         return templatefilters.revescape(req.qsparams['node'])
     else:
-        return short(ctx.node())
+        return short(scmutil.binnode(ctx))
 
 def _listfilesgen(context, ctx, stripecount):
     parity = paritygen(stripecount)
@@ -501,8 +501,9 @@ def _listfilesgen(context, ctx, stripeco
 def changesetentry(web, ctx):
     '''Obtain a dictionary to be used to render the "changeset" template.'''
 
-    showtags = showtag(web.repo, 'changesettag', ctx.node())
-    showbookmarks = showbookmark(web.repo, 'changesetbookmark', ctx.node())
+    showtags = showtag(web.repo, 'changesettag', scmutil.binnode(ctx))
+    showbookmarks = showbookmark(web.repo, 'changesetbookmark',
+                                 scmutil.binnode(ctx))
     showbranch = nodebranchnodefault(ctx)
 
     basectx = basechangectx(web.repo, web.req)


More information about the Mercurial-devel mailing list