[PATCH] purge: add --ignored-only/-i option to delete only ignored files

Patrick Mézard patrick at mezard.eu
Thu Apr 5 02:43:11 CDT 2012


Le 22/03/12 20:22, Matt Mackall a écrit :
> On Wed, 2012-03-21 at 21:49 -0400, Greg Ward wrote:
>> On 21 March 2012, Matt Mackall said:
>>> On Tue, 2012-03-20 at 21:50 -0400, Greg Ward wrote:
>>>> # HG changeset patch
>>>> # User Greg Ward <greg at gerg.ca>
>>>> # Date 1332294424 14400
>>>> # Node ID bfde5bbbc3bb0d804a70cad737f0bf95086a448c
>>>> # Parent  12e3f93b1cbc7c930e941f0adfe632c8ad70b73d
>>>> purge: add --ignored-only/-i option to delete only ignored files
>>>>
>>>> This is handy when you trust .hgignore to specify all of your build
>>>> products, but you do not trust yourself to always remember to "hg add"
>>>> new files. This treats unknown files as valuable, since they might
>>>> become added files soon.
> 
> Ignored files may also be valuable. Config files are a common example of
> things you never want to commit, but that you don't want Mercurial to
> clobber. I think maybe half of projects have one or more of these.
> 
>>> Does this work?
>>>
>>>  hg purge "set:ignored()"
>>
>> No, but
>>
>>   hg purge --all "set:ignored()" 
> 
> Hmm, perhaps we should fix that.

By detecting the "ignored()" fileset in the match object and implicitely enabling --all in that case?

>> Also, this does not remove empty directories.
> 
> Seems buggy.

purge behaviour with match objects is unique, it applies them to directories as well. The code looks like:

- Call repo.status(match) and collect directory trees with match.dir().
- Remove unknown and possibly ignored files
- Remove collected directory entries *matched* by the matcher object.

For instance:

  $ hg init repo
  $ cd repo
  $ mkdir -p dir/subdir
  $ touch dir/subdir/file
  $ hg purge -v dir/subdir
  Removing file dir/subdir/file
  Removing directory dir/subdir

Note that "dir" was not removed because it is not matched by "dir/subdir".

Looking at the code history, this behaviour is at least partially by design, to let people ignore empty directories using --exclude. Basically, you can use patterns to define which subset of files *and directories* are going to be purged.

That said, I tried to fix this "feature" for a good hour before coming to this explanation. Not sure what should be done at this point though, besides documenting some stuff a bit more.

--
Patrick Mézard


More information about the Mercurial-devel mailing list