bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug #29876] --include not working as expected


From: Jim Meyering
Subject: Re: [bug #29876] --include not working as expected
Date: Sat, 14 Aug 2010 02:13:45 +0200

Joe Perches wrote:
> Follow-up Comment #1, bug #29876 (project grep):
>
> 2.6.3 --include doesn't work as 2.5.4 does.
>
> For instance:
>
> $ mkdir foo
> $ cd foo
> $ echo 1 > 1
> $ echo 2 > 2
> $ grep2.5.4 -P --include=[12] "d" *
> 1:1
> 2:2
> $ grep2.6.3 -P --include=[12] "d" *
> $

Thanks for the report!
That is indeed a bug.

(note that the above lacked a "\" before the "d" in the mail,
probably due to web-form quoting)

Here's a demo of the failure that doesn't use -P or globbing:

  $ echo x > 1
  $ grep --include=1 x 1
  [Exit 1]

Here's how the fixed version works:

  $ ./grep --include=1 x 1
  x


The semantics of the excluded_file_name function
changed (in the gnulib "exclude" module) and I
forgot to adjust the use here when I updated
everything to use the latest from gnulib.

Here's the fix I'll push tomorrow:

>From 9c45c193825d1f59e1d341e556ecf4adeb7a03a2 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Fri, 13 Aug 2010 18:19:16 -0500
Subject: [PATCH] make --include=FILE work once again

The semantics of excluded_file_name changed (when operating on
an "included" file name list).
* src/main.c (main): Adjust for changed semantics of excluded_file_name
simply by removing a negation.
* NEWS (Bug fixes): Mention this fix.
* tests/include-exclude: Add a test for this.
Reported by Joe Perches in http://savannah.gnu.org/bugs/?29876.
---
 NEWS                  |    3 +++
 src/main.c            |    8 ++++----
 tests/include-exclude |    4 ++++
 3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/NEWS b/NEWS
index e64ec40..95c2e88 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,9 @@ GNU grep NEWS                                    -*- outline -*-

 ** Bug fixes

+  grep --include=FILE works once again, rather than working like --exclude=FILE
+  [bug introduced in grep-2.6]
+
   Searching with grep -Fw for an empty string would not match an
   empty line. [bug present since "the beginning"]

diff --git a/src/main.c b/src/main.c
index 20168bb..6c4fcd6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2172,11 +2172,11 @@ There is NO WARRANTY, to the extent permitted by 
law.\n"),
           if ((included_patterns || excluded_patterns)
               && !isdir (file))
             {
-              if (included_patterns &&
-                  ! excluded_file_name (included_patterns, file))
+              if (included_patterns
+                  && excluded_file_name (included_patterns, file))
                 continue;
-              if (excluded_patterns &&
-                  excluded_file_name (excluded_patterns, file))
+              if (excluded_patterns
+                  && excluded_file_name (excluded_patterns, file))
                 continue;
             }
           status &= grepfile (STREQ (file, "-") ? (char *) NULL : file,
diff --git a/tests/include-exclude b/tests/include-exclude
index 0192b78..8a8e86c 100644
--- a/tests/include-exclude
+++ b/tests/include-exclude
@@ -39,4 +39,8 @@ grep -r --include='a*'    . x > out || fail=1
 # no need to sort
 compare out exp-a || fail=1

+# --include (without --recursive) uses different code
+grep --include=a a x/* > out || fail=1
+compare out exp-a || fail=1
+
 Exit $fail
--
1.7.2.rc3.475.g72d0



reply via email to

[Prev in Thread] Current Thread [Next in Thread]