# HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 2018-05-24 19:55:31 # Node ID 58b08f4ce5f5b11a073ea2c1fa7cbe83094d3609 # Parent 009aa4af50939faa5f7b45fbae0b2bcee8a50131 graft: use state.cmdstate() to check whether graftstate exists This is a step towards make graft use the new state.cmdstate() class. This patch replaces the ugly try-except with nice if-else conditionals. Differential Revision: https://phab.mercurial-scm.org/D3652 diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -54,6 +54,7 @@ from . import ( rewriteutil, scmutil, server, + state as statemod, streamclone, tags as tagsmod, templatekw, @@ -2216,17 +2217,16 @@ def _dograft(ui, repo, *revs, **opts): **pycompat.strkwargs(opts)) cont = False + graftstate = statemod.cmdstate(repo, 'graftstate') if opts.get('continue'): cont = True if revs: raise error.Abort(_("can't specify --continue and revisions")) # read in unfinished revisions - try: + if graftstate.exists(): nodes = _readgraftstate(repo)['nodes'] revs = [repo[node].rev() for node in nodes] - except IOError as inst: - if inst.errno != errno.ENOENT: - raise + else: cmdutil.wrongtooltocontinue(repo, _('graft')) else: if not revs: