[PATCH] purge extension to support subrepos (based on ctx 14005)
Patrick Mézard
pmezard at gmail.com
Sun May 8 11:21:25 CDT 2011
Using patchbomb extension will make it easier for everyone.
Le 08/05/11 17:39, Alex a écrit :
> diff -r bb391e0515ba hgext/purge.py
>
> --- a/hgext/purge.py Sat Apr 23 00:52:21 2011 +0300
>
> +++ b/hgext/purge.py Sun May 08 19:34:12 2011 +0400
>
> @@ -25,9 +25,9 @@
>
> '''command to delete untracked files from the working directory'''
>
> -from mercurial import util, commands, cmdutil
>
> +from mercurial import util, commands, cmdutil, localrepo, hg
>
> from mercurial.i18n import _
>
> -import os, stat
>
> +import os, stat, time, re
>
> def purge(ui, repo, *dirs, **opts):
>
> '''removes files not tracked by Mercurial
>
> @@ -83,7 +83,24 @@
>
> raise
>
> os.chmod(path, stat.S_IMODE(s.st_mode) | stat.S_IWRITE)
>
> os.remove(path)
>
> +
>
> + if opts['subrepos']:
>
> + 'Apply function to all subrepos repositories'
>
> + if (os.path.exists(repo.root + "/.hgsub")) :
>
> + f = open(repo.root + "/.hgsub" ,"r")
If you want to access the subrepos, use the workingctx.sub() and .substate() methods, do not parse the .hgsub yourself.
>
> + for nsubrepos in f:
>
> + pos = nsubrepos.find("=")
>
> + if (pos != -1):
>
> + npath = nsubrepos[0:pos].strip()
>
> + lpath = os.path.join(repo.root, npath)
>
> + lui = ui.copy()
>
> + lui.readconfig(os.path.join(lpath, '.hg', 'hgrc'))
>
> + nrepo = hg.repository(lui, lpath)
Not all subrepositories are hg repositories, you can have subversion or git ones.
>
> + purge(lui, nrepo, *dirs, **opts)
>
> + ui.write(" Purge %s\n" % repo.root)
>
> + ui.flush()
>
> +
>
> directories = []
>
> match = cmdutil.match(repo, dirs, opts)
>
> match.dir = directories.append
>
> @@ -104,6 +121,7 @@
>
> [('a', 'abort-on-err', None, _('abort if an error occurs')),
>
> ('', 'all', None, _('purge ignored files too')),
>
> ('p', 'print', None, _('print filenames instead of deleting them')),
>
> + ('S', 'subrepos', None, _('purge on subrepos')),
>
> ('0', 'print0', None, _('end filenames with NUL, for use with xargs'
>
> ' (implies -p/--print)')),
>
> ] + commands.walkopts,
The onsub extension (http://mercurial.selenic.com/wiki/OnsubExtension) may be enough to achieve this.
--
Patrick Mézard
More information about the Mercurial-devel
mailing list