[PATCH 5 of 6 DEFAULT] remove: support removing explicit paths in subrepos

David M. Carr david at carrclan.us
Sun Jan 15 10:21:34 CST 2012


On Sun, Jan 15, 2012 at 10:26 AM, Martin Geisler <mg at lazybytes.net> wrote:
> "David M. Carr" <david at carrclan.us> writes:
>
>> # HG changeset patch
>> # User David M. Carr  <david at carrclan.us>
>> # Date 1326514745 18000
>> # Node ID 471cea2010939c4186b269e0bf47db1f445ad516
>> # Parent  97f8b28771e6ad077e58b6536d207e79516b61ac
>> remove: support removing explicit paths in subrepos
>>
>> Change the behavior of the remove command such that explicit paths in
>> subrepos are handled by removing the file in the subrepo.  This eliminates
>> the previous behavior where if you called "hg remove" for an explicit
>> path in a subrepo, it would warn and skip removing the file.  After
>> this change, calling "hg remove" with explicit paths in subrepos
>> should now have the same behavior as explicitly named paths in the
>> same repository, including Warn/Remove/Delete behavior as modified
>> by the --after and --force options.
>>
>> diff -r 97f8b28771e6 -r 471cea201093 mercurial/commands.py
>> --- a/mercurial/commands.py   Fri Jan 13 22:21:23 2012 -0500
>> +++ b/mercurial/commands.py   Fri Jan 13 23:19:05 2012 -0500
>> @@ -4526,11 +4526,21 @@
>>      m = scmutil.match(wctx, pats, opts)
>>      s = repo.status(match=m, clean=True)
>>      modified, added, deleted, clean = s[0], s[1], s[3], s[6]
>> +    substatus = {}
>>      subremove = []
>>
>>      for subpath in wctx.substate:
>> +        sub = wctx.sub(subpath)
>>          try:
>>              submatch = matchmod.narrowmatcher(subpath, m)
>> +            ss = sub.status(None, match=submatch, clean=True)
>> +            def exactmatch(x): return submatch.exact(x)
>> +            submodified, subadded, subdeleted, subclean = \
>> +                    filter(exactmatch, ss[0]), filter(exactmatch, ss[1]),\
>> +                    filter(exactmatch, ss[3]), filter(exactmatch, ss[6])
>> +            substatus[sub] = {'path': subpath, 'matcher': submatch,
>> +                              'modified': submodified, 'added': subadded,
>> +                              'deleted': subdeleted, 'clean': subclean}
>
> If I understand this part correctly, then it loops over the current
> subrepositories and then filters/removes/... files.
>
> I think that is wrong. There can be further nested Mercurial subrepos
> inside the top-level Mercurial subrepos. So there need to be some form
> of recusion here.
>
> The code for 'hg add' should be similar. In 877236cdd437 I moved it from
> mercurial.commands to mercurial.cmdutil and in 166b9866580a I made it
> understand the -S flag. The basic idea is to have a flow where
>
> * command.add kicks things off by calling cmdutil.add
>
> * cmdutil.add does two things:
>
>  - operates on the current repo
>
>  - iterates over subrepos and calls sub.add on the sub objects
>    (polymorphism at work)
>
> * for a hgsubrepo sub, sub.add calls cmdutil.add with the subrepo as the
>  current repo. Other subrepo classes just add the files and have no
>  further recursive calls (no hgsubrepo inside a gitsubrepo).
>
> So you can have multiple levels of recursion where cmdutil.add calls
> sub.add, which in turn calls back to cmdutil.add.
>
> That way both mercurial.commands and mercurial.subrepo becomes fairly
> thin and the main work is done in mercurial.cmdutil.
>
> --
> Martin Geisler
>
> Mercurial links: http://mercurial.ch/

Thanks for the feedback, Martin.  I'll rework this patch series based
on the approach of extracting logic out of commands.remove into
cmdutil.remove, and add testing of multi-level subrepo recursion.  It
looks like subrepo already has a "remove" method, that is used for
removing the subrepo, as opposed to removing files.  Any suggestions
on how to handle that?
-- 
David M. Carr
david at carrclan.us


More information about the Mercurial-devel mailing list