Re: [bsdgrep] --exclude-dir doesn't work

From: Test Rat <ttsestt_at_gmail.com>
Date: Wed, 10 Aug 2011 12:45:18 +0400
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)
_at__at_ -103,7 +103,6 _at__at_ grep_tree(char **argv)
 {
 	FTS *fts;
 	FTSENT *p;
-	char *d, *dir = NULL;
 	int c, fts_flags;
 	bool ok;
 
_at__at_ -135,6 +134,10 _at__at_ 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 */
_at__at_ -144,18 +147,6 _at__at_ 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);
 
%%
Received on Wed Aug 10 2011 - 06:45:39 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:16 UTC