Index: gnu/usr.bin/grep/grep.c =========================================================================== --- gnu/usr.bin/grep/grep.c 2009/09/12 22:50:04 #12 +++ gnu/usr.bin/grep/grep.c 2009/09/12 22:50:04 @@ -102,6 +102,7 @@ INCLUDE_OPTION, EXCLUDE_OPTION, EXCLUDE_FROM_OPTION, + EXCLUDE_JUNK_OPTION, LINE_BUFFERED_OPTION, LABEL_OPTION }; @@ -123,6 +124,7 @@ {"extended-regexp", no_argument, NULL, 'E'}, {"exclude", required_argument, NULL, EXCLUDE_OPTION}, {"exclude-from", required_argument, NULL, EXCLUDE_FROM_OPTION}, + {"exclude-junk", no_argument, NULL, EXCLUDE_JUNK_OPTION}, {"file", required_argument, NULL, 'f'}, {"files-with-matches", no_argument, NULL, 'l'}, {"files-without-match", no_argument, NULL, 'L'}, @@ -169,6 +171,7 @@ int match_words; int match_lines; unsigned char eolbyte; +int exclude_junk; /* For error messages. */ /* The name the program was run with, stripped of any leading path. */ @@ -1709,6 +1712,10 @@ label = optarg; break; + case EXCLUDE_JUNK_OPTION: + exclude_junk = 1; + break; + case 0: /* long options */ break; Index: gnu/usr.bin/grep/grep.h =========================================================================== --- gnu/usr.bin/grep/grep.h 2009/09/12 22:50:04 #4 +++ gnu/usr.bin/grep/grep.h 2009/09/12 22:50:04 @@ -42,3 +42,4 @@ extern int match_words; /* -w */ extern int match_lines; /* -x */ extern unsigned char eolbyte; /* -z */ +extern int exclude_junk; /* --exclude-junk */ Index: gnu/usr.bin/grep/savedir.c =========================================================================== --- gnu/usr.bin/grep/savedir.c 2009/09/12 22:50:04 #4 +++ gnu/usr.bin/grep/savedir.c 2009/09/12 22:50:04 @@ -71,6 +71,7 @@ #include #include "savedir.h" +#include "grep.h" char *path; size_t pathlen; @@ -136,6 +137,15 @@ { off_t size_needed = (namep - name_space) + NAMLEN (dp) + 2; + /* Exclude SCM control files and other known junk */ + if (exclude_junk && + (strcmp(dp->d_name, ".svn") == 0 || + strcmp(dp->d_name, "CVS") == 0 || + strcmp(dp->d_name, "RCS") == 0 || + strcmp(dp->d_name, "obj") == 0 || + strcmp(dp->d_name, "compile") == 0) && isdir1 (dir, dp->d_name)) + continue; + if ((included_patterns || excluded_patterns) && !isdir1 (dir, dp->d_name)) {