[bsdgrep] --exclude-dir doesn't work
Test Rat
ttsestt at gmail.com
Wed Aug 10 08:45:39 UTC 2011
Test Rat <ttsestt at gmail.com> writes:
> It seems fnmatch(3) args were accidentally swapped. Try
>
> $ bsdgrep -Fr --exclude-dir '*.svn*' grep_ usr.bin/grep | bsdgrep -c svn
> 72
And it should probably use FTS_SKIP to save time like textproc/gnugrep.
# turn off caching before testing
$ zfs set primarycache=none ...
$ zfs set secondarycache=none ...
$ time bsdgrep -Fr --exclude-dir .svn blah /usr/src/sys
$ time /usr/local/bin/grep -Fr --exclude-dir .svn blah /usr/src/sys
%%
Index: usr.bin/grep/util.c
===================================================================
--- usr.bin/grep/util.c (revision 224746)
+++ usr.bin/grep/util.c (working copy)
@@ -103,7 +103,6 @@ grep_tree(char **argv)
{
FTS *fts;
FTSENT *p;
- char *d, *dir = NULL;
int c, fts_flags;
bool ok;
@@ -135,6 +134,10 @@ grep_tree(char **argv)
case FTS_D:
/* FALLTHROUGH */
case FTS_DP:
+ if (dexclude || dinclude)
+ if (!dir_matching(p->fts_name) ||
+ !dir_matching(p->fts_path))
+ fts_set(fts, p, FTS_SKIP);
break;
case FTS_DC:
/* Print a warning for recursive directory loop */
@@ -144,18 +147,6 @@ grep_tree(char **argv)
default:
/* Check for file exclusion/inclusion */
ok = true;
- if (dexclude || dinclude) {
- if ((d = strrchr(p->fts_path, '/')) != NULL) {
- dir = grep_malloc(sizeof(char) *
- (d - p->fts_path + 1));
- memcpy(dir, p->fts_path,
- d - p->fts_path);
- dir[d - p->fts_path] = '\0';
- }
- ok = dir_matching(dir);
- free(dir);
- dir = NULL;
- }
if (fexclude || finclude)
ok &= file_matching(p->fts_path);
%%
More information about the freebsd-current
mailing list