[PATCH 3 of 4 V6 STABLE] revert: suggest update on revert to non-parent

Adrian Buehlmann adrian at cadifra.com
Tue Jun 21 02:31:28 CDT 2011


On 2011-06-21 06:11, Kevin Bullock wrote:
> # HG changeset patch
> # User Kevin Bullock <kbullock at ringworld.org>
> # Date 1308626766 18000
> # Branch stable
> # Node ID ee0ea22c40b86d58437630881ec5ea1815ebe354
> # Parent  59f92ee58bc1ff014d11d009ab8e39ae86fb5af7
> revert: suggest update on revert to non-parent
> 
> uncommitted changes, revert to non-parent:
> 
>  BEFORE:
>    $ hg revert -d 2011-05-05
>    Found revision 7423 from Thu May 05 19:56:05 2011 +0200
>    abort: no files or directories specified
>    (use --all to discard all changes)
> 
>  AFTER:
>    $ hg revert -d 2011-05-05
>    Found revision 7423 from Thu May 05 19:56:05 2011 +0200
>    uncommitted changes
>    abort: no files or directories specified
>    (use --all to discard all changes, or 'hg update 7423' to check out that revision)
> 
> clean, revert to non-parent:
> 
>  BEFORE:
>    $ hg revert -d 2011-05-05
>    Found revision 7423 from Thu May 05 19:56:05 2011 +0200
>    abort: no files or directories specified
>    (use --all to discard all changes)
> 
>  AFTER:
>    $ hg revert -d 2011-05-05
>    Found revision 7423 from Thu May 05 19:56:05 2011 +0200
>    abort: no files or directories specified
>    (use --all to revert all files, or 'hg update 7423' to check out that revision)
> 
> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -4180,16 +4180,27 @@
>  
>      parent, p2 = repo.dirstate.parents()
>  
> +    ctx = scmutil.revsingle(repo, opts.get('rev'))
> +    node = ctx.node()
> +
> +    dirty = util.any(repo.status())

There's no need to pay for an extra status call here, we only need dirty
if no patterns are specified and --all was not set

Move it to under the if (like I did)

>      if not pats and not opts.get('all'):
>          msg = _('no files or directories specified')
>          hint = _('use --all to discard all changes')
>          if p2 != nullid:
>              hint = _('use --all to discard all changes, or '
>                       "'hg update -C .' to cancel uncommitted merge")
> +        elif node != parent:
> +            if dirty:
> +                hint = _('use --all to discard all changes, or '
> +                         "'hg update %s' to check out that revision"
> +                         ) % ctx.rev()
> +            else:
> +                hint = _('use --all to revert all files, or '
> +                         "'hg update %s' to check out that revision"
> +                         ) % ctx.rev()
>          raise util.Abort(msg, hint=hint)
>  
> -    ctx = scmutil.revsingle(repo, opts.get('rev'))
> -    node = ctx.node()
>      mf = ctx.manifest()
>      if node == parent:
>          pmf = mf
> diff --git a/tests/test-revert.t b/tests/test-revert.t
> --- a/tests/test-revert.t
> +++ b/tests/test-revert.t
> @@ -186,7 +186,7 @@
>  
>    $ hg revert -rtip
>    abort: no files or directories specified
> -  (use --all to discard all changes)
> +  (use --all to revert all files, or 'hg update 1' to check out that revision)
>    [255]
>  
>  should succeed
> 
> 


More information about the Mercurial-devel mailing list