Mercurial > hg
changeset 4147:691f9168a815
Make the purge extension use the statwalk walker from the dirstate object
author | Emanuele Aina <faina.mail@tiscali.it> |
---|---|
date | Tue, 06 Mar 2007 17:45:40 -0300 |
parents | e287d61dd268 |
children | de85ff0aaac5 |
files | contrib/purge/purge.py |
diffstat | 1 files changed, 18 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/contrib/purge/purge.py Tue Mar 06 17:45:39 2007 -0300 +++ b/contrib/purge/purge.py Tue Mar 06 17:45:40 2007 -0300 @@ -34,23 +34,25 @@ self._repo = repo self._ui = ui self._hg_root = self._split_path(repo.root) - - if not dirs: - dirs = [repo.root] + + directories = [] + files = [] + for src, f, st in repo.dirstate.statwalk(files=dirs, ignored=True, + directories=True): + if src == 'd': + directories.append(f) + elif src == 'f' and f not in repo.dirstate: + files.append(f) - 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) + 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