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

login
register
mail settings
Submitter Anton Shestakov
Date Dec. 8, 2017, 3 p.m.
Message ID <2cc3c1ae70e2286aa612.1512745231@neuro>
Download mbox | patch
Permalink /patch/26103/
State Accepted
Headers show

Comments

Anton Shestakov - Dec. 8, 2017, 3 p.m.
# HG changeset patch
# User Anton Shestakov <av6@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
Augie Fackler - Dec. 8, 2017, 7:43 p.m.
> On Dec 8, 2017, at 10:00, Anton Shestakov <av6@dwimlabs.net> wrote:
> 
> # HG changeset patch
> # User Anton Shestakov <av6@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

queued, thanks

Patch

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,