# HG changeset patch # User Emanuele Aina # Date 1173213940 10800 # Node ID 691f9168a815968577ca18c7b39e179ef03ae55c # Parent e287d61dd2687c19f414c25d7acf4bb1d6eee1f8 Make the purge extension use the statwalk walker from the dirstate object diff -r e287d61dd268 -r 691f9168a815 contrib/purge/purge.py --- 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