Patchwork [1,of,2] annotate: rewrite long short-circuit statement by if-elif-else

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 15, 2014, 1:47 p.m.
Message ID <a5faa142ebeed6a65c50.1408110457@mimosa>
Download mbox | patch
Permalink /patch/5414/
State Accepted
Headers show

Comments

Yuya Nishihara - Aug. 15, 2014, 1:47 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1408080570 -32400
#      Fri Aug 15 14:29:30 2014 +0900
# Node ID a5faa142ebeed6a65c504586ef04eafa788d05d7
# Parent  2965804483e31210b495f5b3cd498a4e3d3272b0
annotate: rewrite long short-circuit statement by if-elif-else
Matt Mackall - Aug. 15, 2014, 4:05 p.m.
On Fri, 2014-08-15 at 22:47 +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1408080570 -32400
> #      Fri Aug 15 14:29:30 2014 +0900
> # Node ID a5faa142ebeed6a65c504586ef04eafa788d05d7
> # Parent  2965804483e31210b495f5b3cd498a4e3d3272b0
> annotate: rewrite long short-circuit statement by if-elif-else

Awesome, queued for default. I'd love to get to the point where we can
ban this construction in check-code.

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -777,9 +777,12 @@  class basefilectx(object):
             size = len(text.splitlines())
             return ([(rev, i) for i in xrange(1, size + 1)], text)
 
-        decorate = (((linenumber is None) and decorate_compat) or
-                    (linenumber and with_linenumber) or
-                    without_linenumber)
+        if linenumber is None:
+            decorate = decorate_compat
+        elif linenumber:
+            decorate = with_linenumber
+        else:
+            decorate = without_linenumber
 
         def pair(parent, child):
             blocks = mdiff.allblocks(parent[1], child[1], opts=diffopts,