Ignoring .svn directories

2006-08-14, , Comments

Files checked out from a Subversion server get replicated into hidden .svn directories in your working copy. This behaviour derives from the guiding principle that disk space costs less than network access. It means, for example, you can see what changes you’ve made to files without needing to visit the server — and indeed revert these changes without server access.

An unwanted side-effect of this is that you may get false hits when you search through a working copy. You match the cached base revisions in the .svn directory as well as the files you’re really working on.

Using find’s -prune option

To tell find to exclude .svn directories, use the -prune option:

find . -path '*/.svn' -prune -o -type f -print | \
      xargs -e grep -I -n -e PATTERN

Customising Emacs

You probably don’t want to have to type in that command all of the time. Since I live inside emacs I just added the following lines to my .emacs configuration file:

(global-set-key [f3] 'grep-find)
(setq grep-find-command
  "find . -path '*/.svn' -prune -o -type f -print | xargs -e grep -I -n -e ")

Now when I hit F3 my preferred find command appears. I just append the pattern I want to look for and hit return. The -n argument to grep causes line numbers to be generated in the grep-find results, meaning I can jump (CTRL-X-TICK) to the right place in a matching file.