Subject: bug#43782: closed (Re: bug#43782: in egrep (grep 3.0), the order of include & exclude is surprisingly significant)

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 03 Oct 2020 19:45:02 +0000

Your bug report

#43782: in egrep (grep 3.0), the order of include & exclude is surprisingly significant

which was filed against the grep package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
43782: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=43782
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#43782: in egrep (grep 3.0), the order of include & exclude is surprisingly significant
From: Paul Eggert <[email-masked]>
To: John Ruckstuhl <[email-masked]>
Cc: [email-masked]
Date: Sat, 3 Oct 2020 12:44:22 -0700
List-Id: <debbugs-submit.debbugs.gnu.org>

On 10/3/20 12:00 PM, John Ruckstuhl wrote:
> In egrep (grep 3.0), the order of options (multiple --include and --exclude), is surprisingly significant.
> I was puzzled by 5 extra output lines in my first egrep,
> so I did another egrep, with the --include moved up front.

That's expected behavior, but it's not documented and should be. Thanks for 
bringing it up. I installed the attached doc patch.
>From ef74f67e27ad76a26670eb5551202bd4b268294d Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Sat, 3 Oct 2020 12:41:38 -0700
Subject: [PATCH] doc: document --include/--exclude better

Problem reported by John Ruckstuhl (Bug#43782).
* doc/grep.texi (File and Directory Selection):
Document what happens if contradictory options are given,
or if no option matches a file name.
* doc/grep.in.1:
---
 doc/grep.in.1 | 11 +++++++++++
 doc/grep.texi |  4 ++++
 2 files changed, 15 insertions(+)

diff --git a/doc/grep.in.1 b/doc/grep.in.1
index 91c0bca..7d5dfe5 100644
--- a/doc/grep.in.1
+++ b/doc/grep.in.1
@@ -680,6 +680,17 @@ Search only files whose base name matches
 .I GLOB
 (using wildcard matching as described under
 .BR \-\^\-exclude ).
+If contradictory
+.B \-\^\-include
+and
+.B \-\^\-exclude
+options are given, the last matching one wins.
+If no
+.B \-\^\-include
+or
+.B \-\^\-exclude
+options match, a file is included unless the first such option is
+.BR \-\^\-include .
 .TP
 .BR \-r ", " \-\^\-recursive
 Read all files under each directory, recursively,
diff --git a/doc/grep.texi b/doc/grep.texi
index bb76ae1..0c0bb12 100644
--- a/doc/grep.texi
+++ b/doc/grep.texi
@@ -728,6 +728,10 @@ this is equivalent to the @samp{--binary-files=without-match} option.
 @cindex searching directory trees
 Search only files whose name matches @var{glob},
 using wildcard matching as described under @option{--exclude}.
+If contradictory @option{--include} and @option{--exclude} options are
+given, the last matching one wins.  If no @option{--include} or
+@option{--exclude} options match, a file is included unless the first
+such option is @option{--include}.
 
 @item -r
 @itemx --recursive
-- 
2.25.1

Subject: in egrep (grep 3.0), the order of include & exclude is surprisingly significant
From: John Ruckstuhl <[email-masked]>
To: "[email-masked]" <[email-masked]>
Date: Sat, 3 Oct 2020 19:00:49 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

In egrep (grep 3.0), the order of options (multiple --include and --exclude), is surprisingly significant.
I was puzzled by 5 extra output lines in my first egrep,
so I did another egrep, with the --include moved up front.
Known bug?
Yes, I realize that the include by itself would have been sufficient, the exclude in this case is superfluous.
Thx,
John R.

Report bugs to: [email-masked]
Report Cygwin bugs to: [email-masked]
GNU grep home page: <http://www.gnu.org/software/grep/>
General help using GNU software: <http://www.gnu.org/gethelp/>

      johnru@ISIMFGDEV400 /cygdrive/c/Program Files (x86)/foxtrot/EC Test SW (750390-mango)
      $ egrep -r -i -n -l --exclude="*.bak" --include="*.py" "\.name\b|testname" ISITestFramework | cat -n
           1  ISITestFramework/DUT/CameraModule/CameraModule/CameraModule.py
           2  ISITestFramework/DUT/CameraModule/CameraModule/CameraModule_0.py
           3  ISITestFramework/DUT/EC/EC.py
           4  ISITestFramework/DUT/Endoscope/Endoscope.py
           5  ISITestFramework/DUT/GenericDUT.py
           6  ISITestFramework/DUT/LightEngine/LightEngine/LightEngine.py
      !!   7  ISITestFramework/HTML/BatFileUtils.html
      !!   8  ISITestFramework/HTML/Libs/jquery/1.12.2/jquery.min.js
           9  ISITestFramework/IQOQDQUtils.py
      !!  10  ISITestFramework/Reports/ReportTemplates/Libraries/GoogleChartsJsapi.js
      !!  11  ISITestFramework/Reports/ReportTemplates/Libraries/jquery-latest.min.js
      !!  12  ISITestFramework/Reports/ReportTemplates/TestResultsSimple.html
          13  ISITestFramework/Reports/ReportTools.py
          14  ISITestFramework/Reports/ReportUtils.py
          15  ISITestFramework/Reports/SummaryMetricWriter.py
          16  ISITestFramework/Test.py
          17  ISITestFramework/TestTools.py

      johnru@ISIMFGDEV400 /cygdrive/c/Program Files (x86)/foxtrot/EC Test SW (750390-mango)
      $ egrep -r -i -n -l --include="*.py" --exclude="*.bak" "\.name\b|testname" ISITestFramework | cat -n
           1  ISITestFramework/DUT/CameraModule/CameraModule/CameraModule.py
           2  ISITestFramework/DUT/CameraModule/CameraModule/CameraModule_0.py
           3  ISITestFramework/DUT/EC/EC.py
           4  ISITestFramework/DUT/Endoscope/Endoscope.py
           5  ISITestFramework/DUT/GenericDUT.py
           6  ISITestFramework/DUT/LightEngine/LightEngine/LightEngine.py
           7  ISITestFramework/IQOQDQUtils.py
           8  ISITestFramework/Reports/ReportTools.py
           9  ISITestFramework/Reports/ReportUtils.py
          10  ISITestFramework/Reports/SummaryMetricWriter.py
          11  ISITestFramework/Test.py
          12  ISITestFramework/TestTools.py

      johnru@ISIMFGDEV400 /cygdrive/c/Program Files (x86)/foxtrot/EC Test SW (750390-mango)
      $ egrep --version
      grep (GNU grep) 3.0
      Packaged by Cygwin (3.0-2)
      Copyright (C) 2017 Free Software Foundation, Inc.
      License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
      This is free software: you are free to change and redistribute it.
      There is NO WARRANTY, to the extent permitted by law.

      Written by Mike Haertel and others, see <http://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.