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

Greg Ward greg at gerg.ca
Wed Mar 21 20:49:36 CDT 2012


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.
> 
> Does this work?
> 
>  hg purge "set:ignored()"

No, but

  hg purge --all "set:ignored()" 

does. purge only considers ignored files with --all.

Also, this does not remove empty directories.

However, this totally fails the usability test. I can just see me
trying to explain to one of my co-workers how to clean up a messy
working dir.

  me: OK, first you need to enable the purge extension

  them: huh?

  me: you know, extensions? one of Mercurial's nice selling points?
  I enable a bunch for you in our default environment, but I don't
  enable dangerous ones like purge: I expect you to RTFM or STFW.

  them: huh? what's STFW?

  me: never mind. edit .hg/hgrc

  them: you mean ~/.hgrc?

  me: no. if I meant ~/.hgrc, I would have said ~/.hgrc. edit .hg/hgrc.

  (eventually they get it, and eventually manage to enable purge)

  me: OK, now run "hg purge --all 'set:ignored()'"

  them: huh?

  me: hg, purge. no. hg, space, purge. space. dash dash all. a-l-l.

  them: [...type type type...]

  me: no no. you need to quote set:ignored() because parentheses are
  special to the Unix shell.

  them: huh?

  me: you know, Unix. that operating system we use. OK, OK, it's really
  Linux, but close enough. that program you're interacting with is
  called a shell. it's a simple programming language in its own right
  with its own syntax ... oh, never mind. just put quotes in.

  them: there! got it! hg purge --all 'set:ignored'

  me: no. parentheses. you're using Mercurial's fileset feature, which
  is a tiny little functional language. you're calling a predicate, and
  the syntax for that language requires paren ... oh, never mind.

Long before that, of course, I would give up and go back to our wiki
page that recommends

  hg status -ni0 | xargs -0 rm

because I don't have to explain about parentheses. (We'll leave -0 and
xargs for another day.) It's less typing and has the same effect as
"hg purge --all 'set:ignored()'", i.e it too fails to remove empty
dirs.

Frankly, it would make my life much easier if I could just tell people
"hg purge -i". Once they manage to enable the extension, we're good.

        Greg
-- 
Greg Ward                                http://www.gerg.ca/
Moderation is for monks.


More information about the Mercurial-devel mailing list