bug-grep
[Top][All Lists]
Advanced

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

[PATCH 1/2] --include etc. now work on command-line args more consistent


From: Paul Eggert
Subject: [PATCH 1/2] --include etc. now work on command-line args more consistently
Date: Sat, 24 Dec 2011 02:16:47 -0800
User-agent: Mozilla/5.0 (X11; Linux i686; rv:8.0) Gecko/20111124 Thunderbird/8.0

--include and --exclude apply only to non-directories and
--exclude-dir applies only to directories.  "-" (standard input)
is never excluded, since it is not a file name.
This bug was discovered while fixing a read-directory bug (Bug#10355).
* NEWS: Document this.
* src/main.c (main): Implement this.
* tests/include-exclude: Test for it.
---
 NEWS                  |    7 +++++++
 src/main.c            |   27 +++++++++++++++++++--------
 tests/include-exclude |    6 +++++-
 3 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/NEWS b/NEWS
index 5e187f8..32cb32e 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,13 @@ GNU grep NEWS                                    -*- outline 
-*-
 
 ** Bug fixes
 
+  The --include, --exclude, and --exclude-dir options now handle
+  command-line arguments more consistently.  --include and --exclude
+  apply only to non-directories and --exclude-dir applies only to
+  directories.  "-" (standard input) is never excluded, since it is
+  not a file name.
+  [bug introduced in grep-2.5]
+
   grep no longer rejects "grep -qr . > out", i.e., when run with -q
   and an input file is the same as the output file, since with -q
   grep generates no output, so there is no risk of infinite loop or
diff --git a/src/main.c b/src/main.c
index afd77c5..70197f4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2205,15 +2205,26 @@ main (int argc, char **argv)
         do
         {
           char *file = argv[optind];
-          if ((included_patterns || excluded_patterns)
-              && !isdir (file))
+          if (!STREQ (file, "-")
+              && (included_patterns || excluded_patterns
+                  || excluded_directory_patterns))
             {
-              if (included_patterns
-                  && excluded_file_name (included_patterns, file))
-                continue;
-              if (excluded_patterns
-                  && excluded_file_name (excluded_patterns, file))
-                continue;
+              if (isdir (file))
+                {
+                  if (excluded_directory_patterns
+                      && excluded_file_name (excluded_directory_patterns,
+                                             file))
+                    continue;
+                }
+              else
+                {
+                  if (included_patterns
+                      && excluded_file_name (included_patterns, file))
+                    continue;
+                  if (excluded_patterns
+                      && excluded_file_name (excluded_patterns, file))
+                    continue;
+                }
             }
           status &= grepfile (STREQ (file, "-") ? (char *) NULL : file,
                               &stats_base);
diff --git a/tests/include-exclude b/tests/include-exclude
index 4249c56..12955c0 100755
--- a/tests/include-exclude
+++ b/tests/include-exclude
@@ -12,6 +12,7 @@ printf '%s\n'         x/dir/d:ddd > exp-not-ab  || 
framework_failure_
 printf '%s\n' x/a:aaa x/b:bbb     > exp-not-d   || framework_failure_
 printf '%s\n' x/a:aaa x/b:bbb     > exp-not-dir || framework_failure_
 printf '%s\n' x/a:aaa             > exp-a       || framework_failure_
+printf '%s\n' aaa                 > exp-aaa     || framework_failure_
 
 grep -r --exclude='a*'    . x > out || fail=1
 sort out > k && mv k out
@@ -40,7 +41,10 @@ grep -r --include='a*'    . x > out || fail=1
 compare exp-a out || fail=1
 
 # --include (without --recursive) uses different code
-grep --include=a '^aaa$' x/* > out || fail=1
+grep --include=a --exclude-dir=dir '^aaa$' x/* > out || fail=1
 compare exp-a out || fail=1
 
+grep --exclude=- '^aaa$' - < x/a > out || fail=1
+compare exp-aaa out || fail=1
+
 Exit $fail
-- 
1.7.6.4



reply via email to

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