[PATCH stable] purge: add option to recurse subrepos

Jack Bowman jack at fogcreek.com
Wed Jun 20 14:41:40 CDT 2012


# 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
 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):
+                ui.note(_('purging subrepository %s\n') % s)
+                purge(ui, sub._repo, **opts)
+
     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
+  removing file a
+
   $ cd ..


More information about the Mercurial-devel mailing list