Package: grep
Version: 2.5.1.ds1-4
Severity: wishlist
Tags: patch
with reference to http://savannah.gnu.org/patch/?func=detailitem&item_id=3521
Eric Haszlakiewicz tried to submit a patch to grep to add --exclude-dir
to grep. Primarily for SVN or CVS usage so .svn or CVS directories can
be skipped when searching. His patch was rejected by upstream (see
page), but I have modifed it for applying to HEAD and submit to you
with the hope you might include it in the .deb and/or punt it upstream
as it is clearly a very desirable feature!
-- System Information:
Debian Release: 3.1
APT prefers unstable
APT policy: (50, 'unstable')
Architecture: i386 (i686)
Kernel: Linux 2.6.9-1-686-smp
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)
Versions of packages grep depends on:
ii libc6 2.3.2.ds1-21 GNU C Library: Shared libraries an
-- no debconf information
diff -ur grep-2.5.1.orig/doc/grep.1 grep-2.5.1/doc/grep.1
--- grep-2.5.1.orig/doc/grep.1 2005-08-24 18:56:40.000000000 +0100
+++ grep-2.5.1/doc/grep.1 2005-08-24 19:06:43.000000000 +0100
@@ -330,10 +330,18 @@
Recurse in directories only searching file matching
.I PATTERN.
.TP
+.BR "\fR \fP \-\^\-include-dir=" PATTERN
+Only recurse into directories matching
+.I PATTERN.
+.TP
.BR "\fR \fP \-\^\-exclude=" PATTERN
Recurse in directories skip file matching
.I PATTERN.
.TP
+.BR "\fR \fP \-\^\-exclude-dir=" PATTERN
+Skip recursing into directories matching
+.I PATTERN.
+.TP
.BR \-s ", " \-\^\-no-messages
Suppress error messages about nonexistent or unreadable files.
Portability note: unlike \s-1GNU\s0
Only in grep-2.5.1/doc: grep.1.orig
diff -ur grep-2.5.1.orig/doc/grep.texi grep-2.5.1/doc/grep.texi
--- grep-2.5.1.orig/doc/grep.texi 2005-08-24 18:56:40.000000000 +0100
+++ grep-2.5.1/doc/grep.texi 2005-08-24 19:06:43.000000000 +0100
@@ -418,7 +418,14 @@
@cindex include files
@cindex searching directory trees
When processing directories recursively, only files matching @var{file_pattern}
-will be search.
+will be searched.
+
[EMAIL PROTECTED] [EMAIL PROTECTED]
[EMAIL PROTECTED] --include-dir
[EMAIL PROTECTED] include files
[EMAIL PROTECTED] searching directory trees
+When processing directories recursively, only directories matching
[EMAIL PROTECTED] will be searched.
@item [EMAIL PROTECTED]
@opindex --exclude
@@ -426,6 +433,13 @@
@cindex searching directory trees
When processing directories recursively, skip files matching @var{file_pattern}.
[EMAIL PROTECTED] [EMAIL PROTECTED]
[EMAIL PROTECTED] --exclude-dir
[EMAIL PROTECTED] exclude files
[EMAIL PROTECTED] searching directory trees
+When processing directories recursively, skip directories matching
[EMAIL PROTECTED]
+
@item -m @var{num}
@itemx [EMAIL PROTECTED]
@opindex -m
diff -ur grep-2.5.1.orig/lib/savedir.c grep-2.5.1/lib/savedir.c
--- grep-2.5.1.orig/lib/savedir.c 2001-03-04 05:33:12.000000000 +0000
+++ grep-2.5.1/lib/savedir.c 2005-08-24 19:06:43.000000000 +0100
@@ -100,7 +100,9 @@
Return NULL if DIR cannot be opened or if out of memory. */
char *
savedir (const char *dir, off_t name_size, struct exclude *included_patterns,
- struct exclude *excluded_patterns)
+ struct exclude *excluded_patterns,
+ struct exclude *included_dir_patterns,
+ struct exclude *excluded_dir_patterns)
{
DIR *dirp;
struct dirent *dp;
@@ -144,6 +146,17 @@
continue;
}
+ if ((included_dir_patterns || excluded_dir_patterns) &&
+ isdir1(dir, dp->d_name))
+ {
+ if (included_dir_patterns &&
+ !excluded_filename(included_dir_patterns, dp->d_name, 0))
+ continue;
+ if (excluded_dir_patterns &&
+ excluded_filename(excluded_dir_patterns, dp->d_name, 0))
+ continue;
+ }
+
if (size_needed > name_size)
{
char *new_name_space;
Only in grep-2.5.1/lib: savedir.c.orig
diff -ur grep-2.5.1.orig/lib/savedir.h grep-2.5.1/lib/savedir.h
--- grep-2.5.1.orig/lib/savedir.h 2001-03-04 05:33:12.000000000 +0000
+++ grep-2.5.1/lib/savedir.h 2005-08-24 19:06:43.000000000 +0100
@@ -13,6 +13,7 @@
extern char *
savedir PARAMS ((const char *dir, off_t name_size,
+ struct exclude *, struct exclude *,
struct exclude *, struct exclude *));
#endif
Only in grep-2.5.1/lib: savedir.h.orig
diff -ur grep-2.5.1.orig/src/grep.c grep-2.5.1/src/grep.c
--- grep-2.5.1.orig/src/grep.c 2005-08-24 18:56:40.000000000 +0100
+++ grep-2.5.1/src/grep.c 2005-08-24 19:09:27.000000000 +0100
@@ -84,6 +84,8 @@
static struct exclude *excluded_patterns;
static struct exclude *included_patterns;
+static struct exclude *excluded_dir_patterns;
+static struct exclude *included_dir_patterns;
/* Short options. */
static char const short_options[] =
"0123456789A:B:C:D:EFGHIPUVX:abcd:e:f:hiKLlm:noqRrsuvwxyZz";
@@ -101,6 +103,8 @@
COLOR_OPTION,
INCLUDE_OPTION,
EXCLUDE_OPTION,
+ INCLUDE_DIR_OPTION,
+ EXCLUDE_DIR_OPTION,
EXCLUDE_FROM_OPTION,
LINE_BUFFERED_OPTION,
LABEL_OPTION
@@ -122,6 +126,7 @@
{"directories", required_argument, NULL, 'd'},
{"extended-regexp", no_argument, NULL, 'E'},
{"exclude", required_argument, NULL, EXCLUDE_OPTION},
+ {"exclude-dir", required_argument, NULL, EXCLUDE_DIR_OPTION},
{"exclude-from", required_argument, NULL, EXCLUDE_FROM_OPTION},
{"file", required_argument, NULL, 'f'},
{"files-with-matches", no_argument, NULL, 'l'},
@@ -130,6 +135,7 @@
{"fixed-strings", no_argument, NULL, 'F'},
{"help", no_argument, &show_help, 1},
{"include", required_argument, NULL, INCLUDE_OPTION},
+ {"include-dir", required_argument, NULL, INCLUDE_DIR_OPTION},
{"ignore-case", no_argument, NULL, 'i'},
{"label", required_argument, NULL, LABEL_OPTION},
{"line-buffered", no_argument, NULL, LINE_BUFFERED_OPTION},
@@ -1023,7 +1029,8 @@
}
name_space = savedir (dir, stats->stat.st_size, included_patterns,
- excluded_patterns);
+ excluded_patterns,
+ included_dir_patterns, excluded_dir_patterns);
if (! name_space)
{
@@ -1121,7 +1128,9 @@
ACTION is 'read' or 'skip'\n\
-R, -r, --recursive equivalent to --directories=recurse\n\
--include=PATTERN files that match PATTERN will be examined\n\
+ --include-dir=PATTERN directories that match PATTERN will be examined.\n\
--exclude=PATTERN files that match PATTERN will be skipped.\n\
+ --exclude-dir=PATTERN directories that match PATTERN will be skipped.\n\
--exclude-from=FILE files that match PATTERN in FILE will be skipped.\n\
-L, --files-without-match only print FILE names containing no match\n\
-l, --files-with-matches only print FILE names containing matches\n\
@@ -1613,6 +1622,12 @@
}
break;
+ case EXCLUDE_DIR_OPTION:
+ if (!excluded_dir_patterns)
+ excluded_dir_patterns = new_exclude ();
+ add_exclude (excluded_dir_patterns, optarg);
+ break;
+
case EXCLUDE_OPTION:
if (!excluded_patterns)
excluded_patterns = new_exclude ();
@@ -1629,6 +1644,12 @@
}
break;
+ case INCLUDE_DIR_OPTION:
+ if (!included_dir_patterns)
+ included_dir_patterns = new_exclude ();
+ add_exclude (included_dir_patterns, optarg);
+ break;
+
case INCLUDE_OPTION:
if (!included_patterns)
included_patterns = new_exclude ();
@@ -1785,6 +1806,18 @@
excluded_filename (excluded_patterns, file, 0))
continue;
}
+
+ if ((included_dir_patterns || excluded_dir_patterns)
+ && isdir (file))
+ {
+ if (included_dir_patterns &&
+ ! excluded_filename (included_dir_patterns, file, 0))
+ continue;
+ if (excluded_dir_patterns &&
+ excluded_filename (excluded_dir_patterns, file, 0))
+ continue;
+ }
+
status &= grepfile (strcmp (file, "-") == 0
? (char *) NULL : file, &stats_base);
}
Only in grep-2.5.1/src: grep.c.orig
Only in grep-2.5.1/src: grep.c.rej
Only in grep-2.5.1/src: grep.c~