From owner-svn-src-head@freebsd.org Sat Apr 21 13:46:08 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8B68AFA6E7B; Sat, 21 Apr 2018 13:46:08 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 3ECA87B283; Sat, 21 Apr 2018 13:46:08 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 2AA7B27B2D; Sat, 21 Apr 2018 13:46:08 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w3LDk7YY056253; Sat, 21 Apr 2018 13:46:07 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w3LDk7YM056252; Sat, 21 Apr 2018 13:46:07 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201804211346.w3LDk7YM056252@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Sat, 21 Apr 2018 13:46:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r332856 - head/usr.bin/grep X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/usr.bin/grep X-SVN-Commit-Revision: 332856 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 21 Apr 2018 13:46:08 -0000 Author: kevans Date: Sat Apr 21 13:46:07 2018 New Revision: 332856 URL: https://svnweb.freebsd.org/changeset/base/332856 Log: bsdgrep: Fix --include/--exclude ordering issues Prior to r332851: * --exclude always win out over --include * --exclude-dir always wins out over --include-dir r332851 broke that behavior, resulting in: * First of --exclude, --include wins * First of --exclude-dir, --include-dir wins As it turns out, both behaviors are wrong by modern grep standards- the latest rule wins. e.g.: `grep --exclude foo --include foo 'thing' foo` foo is included `grep --include foo --exclude foo 'thing' foo` foo is excluded As tested with GNU grep 3.1. This commit makes bsdgrep follow this behavior. Reported by: se Modified: head/usr.bin/grep/util.c Modified: head/usr.bin/grep/util.c ============================================================================== --- head/usr.bin/grep/util.c Sat Apr 21 09:58:00 2018 (r332855) +++ head/usr.bin/grep/util.c Sat Apr 21 13:46:07 2018 (r332856) @@ -109,10 +109,12 @@ file_matching(const char *fname) for (unsigned int i = 0; i < fpatterns; ++i) { if (fnmatch(fpattern[i].pat, fname, 0) == 0 || - fnmatch(fpattern[i].pat, fname_base, 0) == 0) { + fnmatch(fpattern[i].pat, fname_base, 0) == 0) + /* + * The last pattern matched wins exclusion/inclusion + * rights, so we can't reasonably bail out early here. + */ ret = (fpattern[i].mode != EXCL_PAT); - break; - } } free(fname_buf); return (ret); @@ -127,7 +129,11 @@ dir_matching(const char *dname) for (unsigned int i = 0; i < dpatterns; ++i) { if (dname != NULL && fnmatch(dpattern[i].pat, dname, 0) == 0) - return (dpattern[i].mode != EXCL_PAT); + /* + * The last pattern matched wins exclusion/inclusion + * rights, so we can't reasonably bail out early here. + */ + ret = (dpattern[i].mode != EXCL_PAT); } return (ret); }