[PATCH 04 of 13] Make the purge extension use the statwalk walker from the dirstate object

Alexis S. L. Carvalho alexis at cecm.usp.br
Sun Mar 4 08:21:05 CST 2007


Thus spake Emanuele Aina:
> # 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]

You can remove this, and...

> -
> +        
> +        directories = []
> +        files = []
>          for path in dirs:
>              path = os.path.abspath(path)

... you want to remove this loop since you're just calling statwalk with
the same arguments over and over.

Then you can either change the purge function to not accept any subdir
argument, or change things to use util.matcher (something like this:

    files, match, anypats = util.cmdmatcher(repo.root, names=dirs,
			        opts.get('include'), opts.get('exclude'))
    repo.dirstate.statwalk(files=files, match=match)

But I'm not sure this will really work with the
statwalk-returns-directories change...
)


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

Use repo.wjoin(f) instead of os.path.join on what statwalk returns.
They're the same thing right now, but that's cleaner.  This also applies
to some other patches.

Alexis


More information about the Mercurial-devel mailing list