# HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 1521184683 -19800 # Node ID 78d3ba4e17ac1b0d7df5ff5db664f0385adb474f # Parent 802441114400e62ae34cbf0a46b9f3bb96bf706f 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. diff -r 802441114400 -r 78d3ba4e17ac hgext3rd/evolve/__init__.py --- 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)