# HG changeset patch # User Martin von Zweigbergk # Date 2017-08-15 06:26:51 # Node ID 5d286eb7009fde5d070bba656ff4e98e45377896 # Parent 42ad7cc645a41f7091359abe81496bb008350288 commit: move dirstateguard creation out of try-block This is just a simple refactoring to make the next patch simpler. If the dirstateguard constructor raises an exception, the finally-block won't do anything anyway, so this is functionally equivalent (and there is no except-block). Differential Revision: https://phab.mercurial-scm.org/D405 diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -2998,9 +2998,10 @@ def commit(ui, repo, commitfunc, pats, o dsguard = None # extract addremove carefully -- this function can be called from a command # that doesn't support addremove + if opts.get('addremove'): + dsguard = dirstateguard.dirstateguard(repo, 'commit') try: - if opts.get('addremove'): - dsguard = dirstateguard.dirstateguard(repo, 'commit') + if dsguard: if scmutil.addremove(repo, matcher, "", opts) != 0: raise error.Abort( _("failed to mark all new/missing files as added/removed"))