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

Simon Farnsworth simonfar at fb.com
Mon Jan 18 17:47:24 CST 2016


On 15/01/2016, 11:25, "David Soria Parra" <dsp at experimentalworks.net> wrote:



>
>
>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.

Patch in preparation for this. I'm going to delay sending it out while the freeze for 3.7 is in place.

>
>> +
>> +        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.

I marginally prefer this style - it means that if cmdutil.commit or cmdutil.dorecord (either of which can end up being called with this function) later learns to parse an opt called 'extra', I'll still do the right thing. And we've already used it, in as much as interactivecommitfunc depends on it working to get at the definition of commitfunc.

>
>>              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.

Will do.

-- 
Simon Farnsworth


More information about the Mercurial-devel mailing list