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

Yuya Nishihara yuya at tcha.org
Thu Oct 2 09:59:03 CDT 2014


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1412254690 -32400
#      Thu Oct 02 21:58:10 2014 +0900
# Node ID 4ec9dd1b52889c73bbf39159222a161e4374cd4a
# Parent  4a00110fd8708373ed8e69f96367383b2dd10661
branches: reduce nesting in for loop

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')),


More information about the Mercurial-devel mailing list