[PATCH 2 of 2] shelve: Permit shelves to contain unknown files

David Soria Parra dsp at experimentalworks.net
Fri Jan 15 11:25:49 UTC 2016



On 1/14/16 9:09 PM, Simon Farnsworth wrote:
> diff --git a/hgext/shelve.py b/hgext/shelve.py
> --- a/hgext/shelve.py
> +++ b/hgext/shelve.py
> @@ -304,6 +304,16 @@
>          if name.startswith('.'):
>              raise error.Abort(_("shelved change names may not start with '.'"))
>          interactive = opts.get('interactive', False)
> +        includeunknown = (opts.get('includeunknown', False) and
> +                          not opts.get('addremove', False))

This can be unexpected for people. We should check if they are both set
and raise an error, to make it clear to people that they are incompatible.

> +
> +        extra={}
> +        if includeunknown:
> +            s = repo.status(match=scmutil.match(repo[None], pats, opts),
> +                            unknown=True)
> +            if s.unknown:
> +                extra['shelve_unknown'] = '\0'.join(s.unknown)
> +                repo[None].add(s.unknown)
>  
>          def commitfunc(ui, repo, message, match, opts):
>              hasmq = util.safehasattr(repo, 'mq')
> @@ -315,7 +325,7 @@
>                  editor = cmdutil.getcommiteditor(editform='shelve.shelve',
>                                                   **opts)
>                  return repo.commit(message, user, opts.get('date'), match,
> -                                   editor=editor)
> +                                   editor=editor, extra=extra)

If I understand cmdutil.commit (which will be called with commitfunc as
a parameter) correctly, you should be able to hand in 'extra' as an opt
and then use extra=opts.get('extra') to retrieve them.
This should remove the locality problem of having to reference and
external variable.

>              finally:
>                  repo.ui.restoreconfig(backup)
>                  if hasmq:
> @@ -679,8 +689,10 @@
>          # and shelvectx is the unshelved changes. Then we merge it all down
>          # to the original pctx.
>  
> -        # Store pending changes in a commit
> +        # Store pending changes in a commit and remember added in case a shelve
> +        # contains unknown files that are part of the pending change
>          s = repo.status()
> +        addedbefore = frozenset(s.added)
>          if s.modified or s.added or s.removed or s.deleted:
>              ui.status(_("temporarily committing pending changes "
>                          "(restore with 'hg unshelve --abort')\n"))
> @@ -745,6 +757,16 @@
>                  shelvectx = tmpwctx
>  


>    
>     -A --addremove           mark new/missing files as added/removed before
>                              shelving
> +   -u --unknown             Store unknown files in the shelve
>        --cleanup             delete all shelved changes
>        --date DATE           shelve with the specified commit date
>     -d --delete              delete the named shelved change(s)
> @@ -1245,3 +1246,71 @@
>       test                      4:33f7f61e6c5e
>  
>    $ cd ..
> +
> +Shelve and unshelve unknown files. For the purposes of unshelve, a shelved
> +unknown file is the same as a shelved added file, except that it will be in
> +unknown state after unshelve if and only if it was either absent or unknown
> +before the unshelve operation.

Can you add a test for the incompatibility between --addremove and
--unknown.



More information about the Mercurial-devel mailing list