[PATCH] hgweb: rewrite `template = A and B or C` to be a proper ternary operator

Anton Shestakov av6 at dwimlabs.net
Fri Dec 8 15:00:31 UTC 2017


# HG changeset patch
# User Anton Shestakov <av6 at dwimlabs.net>
# Date 1512743234 -28800
#      Fri Dec 08 22:27:14 2017 +0800
# Node ID 2cc3c1ae70e2286aa612b08a1671e6a5d77b4a22
# Parent  cb0df5a3affba6e8f1789de337230cbeecda9c5a
# EXP-Topic hgweb-cleanup
hgweb: rewrite `template = A and B or C` to be a proper ternary operator

diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -413,7 +413,7 @@ def changelog(web, req, tmpl, shortlog=F
     else:
         nextentry = []
 
-    return tmpl(shortlog and 'shortlog' or 'changelog', changenav=changenav,
+    return tmpl('shortlog' if shortlog else 'changelog', changenav=changenav,
                 node=ctx.hex(), rev=pos, symrev=symrev, changesets=count,
                 entries=entries,
                 latestentry=latestentry, nextentry=nextentry,
diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -411,7 +411,7 @@ def changesetentry(web, req, tmpl, ctx):
     files = []
     parity = paritygen(web.stripecount)
     for blockno, f in enumerate(ctx.files()):
-        template = f in ctx and 'filenodelink' or 'filenolink'
+        template = 'filenodelink' if f in ctx else 'filenolink'
         files.append(tmpl(template,
                           node=ctx.hex(), file=f, blockno=blockno + 1,
                           parity=next(parity)))
@@ -572,7 +572,7 @@ def diffstat(tmpl, ctx, statgen, parity)
 
     fileno = 0
     for filename, adds, removes, isbinary in stats:
-        template = filename in files and 'diffstatlink' or 'diffstatnolink'
+        template = 'diffstatlink' if filename in files else 'diffstatnolink'
         total = adds + removes
         fileno += 1
         yield tmpl(template, node=ctx.hex(), file=filename, fileno=fileno,


More information about the Mercurial-devel mailing list