[PATCH 04 of 13] Make the purge extension use the statwalk walker from the dirstate object
Emanuele Aina
faina.mail at tiscali.it
Tue Feb 27 07:06:04 UTC 2007
# HG changeset patch
# User Emanuele Aina <em at nerd.ocracy.org>
# Date 1172563536 -3600
# Node ID 94ddfaa09ed610b36e4c7114b5406416f220c451
# Parent 342e9d3258d2637653f838175e0a34691105af23
Make the purge extension use the statwalk walker from the dirstate object
diff --git a/contrib/purge/purge.py b/contrib/purge/purge.py
--- a/contrib/purge/purge.py
+++ b/contrib/purge/purge.py
@@ -39,20 +39,26 @@ class Purge(object):
if not dirs:
dirs = [repo.root]
-
+
+ directories = []
+ files = []
for path in dirs:
path = os.path.abspath(path)
- for root, dirs, files in os.walk(path, topdown=False):
- if '.hg' in self._split_path(root):
- # Skip files in the .hg directory.
- # Note that if the repository is in a directory
- # called .hg this command does not work.
- continue
- for name in files:
- self._remove_file(os.path.join(root, name))
- if not os.listdir(root):
- # Remove this directory if it is empty.
- self._remove_dir(root)
+ for src, f, st in repo.dirstate.statwalk():
+ if src == 'd':
+ directories.append(f)
+ elif src == 'f' and src not in repo.dirstate:
+ files.append(f)
+
+ directories.sort()
+
+ for f in files:
+ self._remove_file(os.path.join(repo.root, f))
+
+ for f in directories[::-1]:
+ f = os.path.join(repo.root, f)
+ if not os.listdir(f):
+ self._remove_dir(f)
self._repo = None
self._ui = None
More information about the Mercurial-devel
mailing list