[PATCH v2] shelve: make unshelve be able to abort in any case

Yuya Nishihara yuya at tcha.org
Fri Jul 8 09:32:32 EDT 2016


On Thu, 7 Jul 2016 21:12:41 +0000, Kostia Balytskyi wrote:
> # HG changeset patch
> # User Kostia Balytskyi <ikostia at fb.com>
> # Date 1467925588 -7200
> #      Thu Jul 07 23:06:28 2016 +0200
> # Node ID f06ece8d99297bb9e3e8446be6bedff66acbb831
> # Parent  b4d117cee636be8a566f56e84d4b351a736a1299
> shelve: make unshelve be able to abort in any case
> 
> diff --git a/hgext/shelve.py b/hgext/shelve.py
> --- a/hgext/shelve.py
> +++ b/hgext/shelve.py
> @@ -662,10 +662,23 @@ def _dounshelve(ui, repo, *shelved, **op
>  
>          try:
>              state = shelvedstate.load(repo)
> +        except error.HintException:
> +            raise

HintException isn't a category of error. I'll send a patch to make it private.

>          except IOError as err:
> -            if err.errno != errno.ENOENT:
> -                raise
> -            cmdutil.wrongtooltocontinue(repo, _('unshelve'))
> +            if err.errno == errno.ENOENT:
> +                cmdutil.wrongtooltocontinue(repo, _('unshelve'))

IOError would lost.

> +        except Exception as err:
> +            if continuef:
> +                msg = _('could not read shelved state file\nplease run '
> +                        'hg unshelve --abort to abort unshelve operation\n')
> +                raise error.Abort(msg)
> +            elif abortf:
> +                msg = _('could not read shelved state file, your working copy '
> +                        'may be in an unexpected state\nplease update to some '
> +                        'commit\n')
> +                ui.warn(msg)
> +                shelvedstate.clear(repo)
> +            return

Catching "Exception" is too broad to detect corruption. Instead,
shelvedstate.load() can translate ValueError, TypeError, etc. to CorruptedState
or something.


More information about the Mercurial-devel mailing list