[PATCH stable] purge: add option to recurse subrepos

Patrick Mézard patrick at mezard.eu
Sun Jun 24 09:26:41 UTC 2012


Le 20/06/12 21:41, Jack Bowman a écrit :
> # HG changeset patch
> # User Jack Bowman <jack at fogcreek.com>
> # Date 1340220246 14400
> # Node ID 218fcb8cb8128e2dbfff7886e30171dae29281c1
> # Parent  132ea1736751cb02b16992cf421e7de8bad888a1
> purge: add option to recurse subrepos
> 
> diff -r 132ea1736751 -r 218fcb8cb812 hgext/purge.py
> --- a/hgext/purge.py	Mon Jun 18 13:01:12 2012 -0500
> +++ b/hgext/purge.py	Wed Jun 20 15:24:06 2012 -0400
> @@ -25,6 +25,7 @@
>  '''command to delete untracked files from the working directory'''
>  
>  from mercurial import util, commands, cmdutil, scmutil
> +from mercurial.subrepo import hgsubrepo

Please avoid importing symbols from modules:

  from mercurial import subrepo

then use:

  subrepo.hgsubrepo

>  from mercurial.i18n import _
>  import os, stat
>  
> @@ -38,7 +39,7 @@
>      ('p', 'print', None, _('print filenames instead of deleting them')),
>      ('0', 'print0', None, _('end filenames with NUL, for use with xargs'
>                              ' (implies -p/--print)')),
> -    ] + commands.walkopts,
> +    ] + commands.walkopts + commands.subrepoopts,
>      _('hg purge [OPTION]... [DIR]...'))
>  def purge(ui, repo, *dirs, **opts):
>      '''removes files not tracked by Mercurial
> @@ -72,6 +73,14 @@
>          eol = '\0'
>          act = False # --print0 implies --print
>  
> +    if opts.get('subrepos'):
> +        wctx = repo[None]
> +        for s in wctx.substate:
> +            sub = wctx.sub(s)
> +            if isinstance(sub, hgsubrepo):

This is fine for now but it immediately asks how we would do that for non-hg subrepos. I guess we could keep going with the isinstance() version on other types, or if we want extensions to be able to share this kind of things, define a subreposetup() hook like the reposetup() one. Probably not a big deal.

> +                ui.note(_('purging subrepository %s\n') % s)
> +                purge(ui, sub._repo, **opts)

*dirs arguments are not honored.

> +
>      def remove(remove_func, name):
>          if act:
>              try:
> diff -r 132ea1736751 -r 218fcb8cb812 tests/test-purge.t
> --- a/tests/test-purge.t	Mon Jun 18 13:01:12 2012 -0500
> +++ b/tests/test-purge.t	Wed Jun 20 15:24:06 2012 -0400
> @@ -215,4 +215,16 @@
>    $ hg purge -p -X .svn -X '*/.svn'
>    $ hg purge -p -X re:.*.svn
>  
> +subrepo recursion
> +
> +  $ hg purge
> +  $ hg init foo
> +  $ echo "foo = foo" >> .hgsub
> +  $ hg add .hgsub
> +  $ touch a foo/b
> +  $ hg purge -v -S
> +  purging subrepository foo
> +  removing file b

It would be nice to have it say "removing file foo/b". Same thing with the --print option. When you use --print, you really want an accurate view of what is going to happen, not have to wild guess whether b is in foo/ or in the base repository. The subrepo call probably has to be aware it runs in a subrepo context.

Please test:

  $ hg purge -p -v -S directory

And --include/--exclude too, though these should work.

> +  removing file a
> +
>    $ cd ..

Finally, it would be nice to have at least one test calling purge -S with non-hg subrepos. Commands with -S have a long history of failing hard on subrepos types not considered in the initial implementation. Yours will not, but it would be great to keep a check on that. Just add a call like:

  hg --config extensions.purge= purge -S

somewhere in test-subrepo-git.t or the svn one.

--
Patrick Mézard



More information about the Mercurial-devel mailing list