Patchwork [1,of,6] branches: reduce nesting in for loop

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 2, 2014, 2:59 p.m.
Message ID <4ec9dd1b52889c73bbf3.1412261943@mimosa>
Download mbox | patch
Permalink /patch/6083/
State Accepted
Headers show

Comments

Yuya Nishihara - Oct. 2, 2014, 2:59 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1412254690 -32400
#      Thu Oct 02 21:58:10 2014 +0900
# Node ID 4ec9dd1b52889c73bbf39159222a161e4374cd4a
# Parent  4a00110fd8708373ed8e69f96367383b2dd10661
branches: reduce nesting in for loop
Matt Mackall - Oct. 2, 2014, 7:10 p.m.
On Thu, 2014-10-02 at 23:59 +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1412254690 -32400
> #      Thu Oct 02 21:58:10 2014 +0900
> # Node ID 4ec9dd1b52889c73bbf39159222a161e4374cd4a
> # Parent  4a00110fd8708373ed8e69f96367383b2dd10661
> branches: reduce nesting in for loop

I've queued this first one.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1104,28 +1104,29 @@  def branches(ui, repo, active=False, clo
                   reverse=True)
 
     for tag, ctx, isactive, isopen in branches:
-        if (not active) or isactive:
-            if isactive:
-                label = 'branches.active'
-                notice = ''
-            elif not isopen:
-                if not closed:
-                    continue
-                label = 'branches.closed'
-                notice = _(' (closed)')
-            else:
-                label = 'branches.inactive'
-                notice = _(' (inactive)')
-            if tag == repo.dirstate.branch():
-                label = 'branches.current'
-            rev = str(ctx.rev()).rjust(31 - encoding.colwidth(tag))
-            rev = ui.label('%s:%s' % (rev, hexfunc(ctx.node())),
-                           'log.changeset changeset.%s' % ctx.phasestr())
-            labeledtag = ui.label(tag, label)
-            if ui.quiet:
-                ui.write("%s\n" % labeledtag)
-            else:
-                ui.write("%s %s%s\n" % (labeledtag, rev, notice))
+        if active and not isactive:
+            continue
+        if isactive:
+            label = 'branches.active'
+            notice = ''
+        elif not isopen:
+            if not closed:
+                continue
+            label = 'branches.closed'
+            notice = _(' (closed)')
+        else:
+            label = 'branches.inactive'
+            notice = _(' (inactive)')
+        if tag == repo.dirstate.branch():
+            label = 'branches.current'
+        rev = str(ctx.rev()).rjust(31 - encoding.colwidth(tag))
+        rev = ui.label('%s:%s' % (rev, hexfunc(ctx.node())),
+                       'log.changeset changeset.%s' % ctx.phasestr())
+        labeledtag = ui.label(tag, label)
+        if ui.quiet:
+            ui.write("%s\n" % labeledtag)
+        else:
+            ui.write("%s %s%s\n" % (labeledtag, rev, notice))
 
 @command('bundle',
     [('f', 'force', None, _('run even when the destination is unrelated')),