changeset 3550:78d3ba4e17ac

next: cleanup logic around return by returning early In the cmdnext function, there are some conditionals which returns early and some which sets a result value to be returned later. Let's return from all the conditionals early. There are if, elif and else involved, so it's sure we will end up in one of the conditional, each conditional will return, so it's guranteed that we are returning the correct value and returning everytime.
author Pulkit Goyal <7895pulkit@gmail.com>
date Fri, 16 Mar 2018 12:48:03 +0530
parents 802441114400
children ce346c6165c6
files hgext3rd/evolve/__init__.py
diffstat 1 files changed, 4 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/__init__.py	Fri Mar 16 12:14:39 2018 +0530
+++ b/hgext3rd/evolve/__init__.py	Fri Mar 16 12:48:03 2018 +0530
@@ -1107,7 +1107,7 @@
                                               {'template': shorttemplate})
         if len(children) == 1:
             c = children[0]
-            result = _updatetonext(ui, repo, c, displayer, opts)
+            return _updatetonext(ui, repo, c, displayer, opts)
         elif children:
             cheader = _("ambiguous next changeset, choose one to update:")
             crevs = [c.rev() for c in children]
@@ -1117,9 +1117,9 @@
                 for c in children:
                     displayer.show(c)
                 ui.warn(_("explicitly update to one of them\n"))
-                result = 1
+                return 1
             else:
-                result = _updatetonext(ui, repo, repo[choosedrev], displayer, opts)
+                return _updatetonext(ui, repo, repo[choosedrev], displayer, opts)
         else:
             aspchildren = evolvecmd._aspiringchildren(repo, [repo['.'].rev()])
             if topic:
@@ -1137,7 +1137,7 @@
                     msg = _('(%i unstable changesets to be evolved here, '
                             'do you want --evolve?)\n')
                     ui.warn(msg % len(aspchildren))
-                result = 1
+                return 1
             elif 1 < len(aspchildren):
                 cheader = _("ambiguous next (unstable) changeset, choose one to"
                             " evolve and update:")
@@ -1153,8 +1153,6 @@
                     return _nextevolve(ui, repo, repo[choosedrev], opts)
             else:
                 return _nextevolve(ui, repo, aspchildren[0], opts)
-            return 1
-        return result
     finally:
         lockmod.release(wlock)