[PATCH] purge extension to support subrepos (based on ctx 14005)

Alex kavgrb at gmail.com
Sun May 8 10:39:05 CDT 2011


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")

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

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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20110508/14f14b75/attachment.htm>


More information about the Mercurial-devel mailing list