From owner-freebsd-current@FreeBSD.ORG Wed Aug 10 08:45:39 2011 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CFFC9106566C; Wed, 10 Aug 2011 08:45:39 +0000 (UTC) (envelope-from ttsestt@gmail.com) Received: from mail-gw0-f54.google.com (mail-gw0-f54.google.com [74.125.83.54]) by mx1.freebsd.org (Postfix) with ESMTP id 7CE508FC19; Wed, 10 Aug 2011 08:45:39 +0000 (UTC) Received: by gwb15 with SMTP id 15so616437gwb.13 for ; Wed, 10 Aug 2011 01:45:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type; bh=evLnZmoveOOmcrPHe6Zp7kQL6JcSIPC0NqM+g0HnEWM=; b=lIKLaUyrml5J/EB6Q/HIxG+pAA5zledjp+uUeQ9MGlxOIwlDLdh5r0EK/7A6QcggBp 9Fmfy5XyEL/K55yyy4WPGok+LLqrCqUszjE4Ak2K3sxJaAJvHe37iorn4ZA1+Z6/fj2u Pw1j0yJ0GvxhLNeG3vUy1FpInzxIGhO1jtyY4= Received: by 10.91.33.35 with SMTP id l35mr7358022agj.33.1312965938554; Wed, 10 Aug 2011 01:45:38 -0700 (PDT) Received: from localhost (eth-216.248-homell.natm.ru [84.242.216.248]) by mx.google.com with ESMTPS id h36sm643092anm.29.2011.08.10.01.45.33 (version=SSLv3 cipher=OTHER); Wed, 10 Aug 2011 01:45:35 -0700 (PDT) From: Test Rat To: freebsd-current@freebsd.org References: <86fwlaeovw.fsf@gmail.com> Date: Wed, 10 Aug 2011 12:45:18 +0400 In-Reply-To: <86fwlaeovw.fsf@gmail.com> (Test Rat's message of "Tue, 09 Aug 2011 16:43:47 +0400") Message-ID: <86liv164f5.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain Cc: Gabor Kovesdan Subject: Re: [bsdgrep] --exclude-dir doesn't work X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Aug 2011 08:45:39 -0000 Test Rat 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); %%