X-Loop: help-debbugs@HIDDEN Subject: bug#29139: add --include for recursive searches Resent-From: Kevin Hunter Kesling <hunteke@HIDDEN> Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> Resent-CC: bug-diffutils@HIDDEN Resent-Date: Fri, 03 Nov 2017 20:16:01 +0000 Resent-Message-ID: <handler.29139.B.150974013010231 <at> debbugs.gnu.org> Resent-Sender: help-debbugs@HIDDEN X-GNU-PR-Message: report 29139 X-GNU-PR-Package: diffutils X-GNU-PR-Keywords: To: 29139 <at> debbugs.gnu.org X-Debbugs-Original-To: Diffutils Bug List <bug-diffutils@HIDDEN> Received: via spool by submit <at> debbugs.gnu.org id=B.150974013010231 (code B ref -1); Fri, 03 Nov 2017 20:16:01 +0000 Received: (at submit) by debbugs.gnu.org; 3 Nov 2017 20:15:30 +0000 Received: from localhost ([127.0.0.1]:49884 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1eAiNG-0002ev-46 for submit <at> debbugs.gnu.org; Fri, 03 Nov 2017 16:15:30 -0400 Received: from eggs.gnu.org ([208.118.235.92]:55441) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <hunteke@HIDDEN>) id 1eAiM0-0002cK-BZ for submit <at> debbugs.gnu.org; Fri, 03 Nov 2017 16:14:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from <hunteke@HIDDEN>) id 1eAiLt-00071b-Q8 for submit <at> debbugs.gnu.org; Fri, 03 Nov 2017 16:14:07 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM, T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:35840) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from <hunteke@HIDDEN>) id 1eAiLt-00071W-Kq for submit <at> debbugs.gnu.org; Fri, 03 Nov 2017 16:14:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46407) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <hunteke@HIDDEN>) id 1eAiLr-00054I-Ve for bug-diffutils@HIDDEN; Fri, 03 Nov 2017 16:14:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from <hunteke@HIDDEN>) id 1eAiLo-0006xo-Os for bug-diffutils@HIDDEN; Fri, 03 Nov 2017 16:14:03 -0400 Received: from mail-io0-x22b.google.com ([2607:f8b0:4001:c06::22b]:49131) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from <hunteke@HIDDEN>) id 1eAiLo-0006xV-GE for bug-diffutils@HIDDEN; Fri, 03 Nov 2017 16:14:00 -0400 Received: by mail-io0-x22b.google.com with SMTP id d66so8818854ioe.5 for <bug-diffutils@HIDDEN>; Fri, 03 Nov 2017 13:14:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=JkQTkmUy6CiBKed2SpQMWG2eF/AWzDY3UpJhc8tWiQA=; b=QCRmh/86kqR6QP0esqg7tj0KpJeohHVwWialyU3eF7rQUrFljUS1j9z4ZPCcgk2ixy uZYhaxRsM20N507doVkbf6Dy9ums3SnPJyoDkASQgyaoBVrItHGSaoK4ldgDMhJBzvqr 6PWMOETNICibcwZM4npDS5X4/VqUnTHYZ1la0MR59f7hpM6J+E1ki/27BThlgx8nXDv+ 6PmIpUak+fPre63GMdJ4cwba5p4uQrwIxscU8hme0aX1reDYaFg8ncn4xB7LoiqdJgkU mVKsMILUlMZoN4PI1jccF10TaPo+0vljQ3t0tppZQ7UBgiApjdjAEQkY1Wkg+QTDFPHQ Nptg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language; bh=JkQTkmUy6CiBKed2SpQMWG2eF/AWzDY3UpJhc8tWiQA=; b=Ruq6EzgwQnHmAaRXLH+bSjOBq5/20cX1KAyh0FomUYcF70Pnks0i46xOg/N/37yqpp A71Wz0mLYYg9uDH+BsZM7EjZlS4Reg++GglPkV7Q8PESksY3u1buwG30WVyHxthzcEod 1FuJvd/mdR1IbtRBqxu/32CrkSTKaWPiL/ZhXrbHHpmUuemFt+x1IiB+VWxAkQtVOQjM Tf7PGYiji+RMJrYROSKzVtJbYFA7YrTnX+gNOqiHJ45wjtEDzhha3LtP7z+zvXejo0oR wNjQ/WzvWNWZuFdW7VtCXOYyRrQB+fLzM6xZO5VMacb1d9AjJccgROWwxlcVyxbueRW0 Bvhg== X-Gm-Message-State: AJaThX7o9i+CaObV+6SYIoscCNnYnb+KtnpQ0qQSXRoA/c3MDFuZH+79 skRlzBKRj0Ed4jkay69UVmsYFA== X-Google-Smtp-Source: ABhQp+TrZtMyaj7DmqI4/rwXJm+Pu2ulOBuAAUjXeOdeOIN1AuM6sxFxJKVLjAqj6hZJLRcWp3/MKQ== X-Received: by 10.107.46.32 with SMTP id i32mr10027771ioo.8.1509740039285; Fri, 03 Nov 2017 13:13:59 -0700 (PDT) Received: from [10.45.1.112] (rrcs-97-78-212-242.se.biz.rr.com. [97.78.212.242]) by smtp.googlemail.com with ESMTPSA id l206sm1549123ita.29.2017.11.03.13.13.57 for <bug-diffutils@HIDDEN> (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Nov 2017 13:13:58 -0700 (PDT) From: Kevin Hunter Kesling <hunteke@HIDDEN> Message-ID: <a654916a-502c-f1dc-d115-2672aced4d29@HIDDEN> Date: Fri, 3 Nov 2017 16:13:57 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------F5C7DDBEDF82FA878CE0B3E8" Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.0 (----) X-Mailman-Approved-At: Fri, 03 Nov 2017 16:15:28 -0400 X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -4.0 (----) This is a multi-part message in MIME format. --------------F5C7DDBEDF82FA878CE0B3E8 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Hello List, I've been annoyed and confused when I'm on autopilot and attempting to recursively compare directory trees. I've become accustomed to Grep's --include functionality, and have more than a few times been surprised (to the tune of "What? Unrecognized option??") that diff does not have it. Well, with the attached patch, it now does. Thanks to diff and grep both using gnulib, and the expressiveness of add_exclude(), this was a much easier change that I was expecting when I embarked on this a couple of hours ago. Further, in the past hour since implementing it, this patch has already saved me a ton of time (no thanks to an unfortunately slow VPN setup and other beleaguered business requirements). Use is exactly like with grep. For example: $ diff --recursive --brief -w --include="*.c" --include="*.h" \ dir1/ \ dir2/ Would this be of use to the community? Thanks, Kevin --------------F5C7DDBEDF82FA878CE0B3E8 Content-Type: text/x-patch; name="diff-Add-include-command-line-option.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="diff-Add-include-command-line-option.patch" From 9b5ff988f8c49a179ee64dbb075cb289b0c1868c Mon Sep 17 00:00:00 2001 From: Kevin Hunter Kesling <hunteke@HIDDEN> Date: Fri, 3 Nov 2017 11:36:03 -0400 Subject: [PATCH] diff: Add include command line option Referencing a number of requests, both public[1] and internal, this patch now enables --include, in a similar vein to grep's --include. Heavy thanks to grep's sourcecode for having already solved this wheel. [1] "Only include files that match a given pattern in a recursive diff" https://stackoverflow.com/questions/10131908/ --- NEWS | 3 +++ doc/diffutils.texi | 6 ++++++ src/diff.c | 14 +++++++++++--- tests/Makefile.am | 3 ++- tests/include-exclude | 23 +++++++++++++++++++++++ 5 files changed, 45 insertions(+), 4 deletions(-) create mode 100755 tests/include-exclude diff --git a/NEWS b/NEWS index 949136c..89afd91 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,9 @@ GNU diffutils NEWS -*- outline -*- * Noteworthy changes in release ?.? (????-??-??) [?] +** New features + + With --include, diff now can include file patterns, like grep. * Noteworthy changes in release 3.6 (2017-05-21) [stable] diff --git a/doc/diffutils.texi b/doc/diffutils.texi index 8479b3f..5bca8ee 100644 --- a/doc/diffutils.texi +++ b/doc/diffutils.texi @@ -3842,6 +3842,12 @@ comparison of @file{d} to @file{e} might compare the contents of might compare the contents of @file{d/Init} and @file{inIt}. @xref{Comparing Directories}. +@item --include=@var{glob} +@cindex include files +@cindex searching directory trees +When comparing directories, only compare files whose name matches @var{glob}. +@xref{Comparing Directories}. + @item -l @itemx --paginate Pass the output through @command{pr} to paginate it. @xref{Pagination}. diff --git a/src/diff.c b/src/diff.c index df3338c..8252264 100644 --- a/src/diff.c +++ b/src/diff.c @@ -144,6 +144,7 @@ enum COLOR_PALETTE_OPTION, PRESUME_OUTPUT_TTY_OPTION, + INCLUDE_OPTION, }; static char const group_format_option[][sizeof "--unchanged-group-format"] = @@ -185,6 +186,7 @@ static struct option const longopts[] = {"ignore-space-change", 0, 0, 'b'}, {"ignore-tab-expansion", 0, 0, 'E'}, {"ignore-trailing-space", 0, 0, 'Z'}, + {"include", 1, 0, INCLUDE_OPTION}, {"inhibit-hunk-merge", 0, 0, INHIBIT_HUNK_MERGE_OPTION}, {"initial-tab", 0, 0, 'T'}, {"label", 1, 0, 'L'}, @@ -648,9 +650,14 @@ main (int argc, char **argv) set_color_palette (optarg); break; - case PRESUME_OUTPUT_TTY_OPTION: - presume_output_tty = true; - break; + case PRESUME_OUTPUT_TTY_OPTION: + presume_output_tty = true; + break; + + case INCLUDE_OPTION: + add_exclude (excluded, optarg, 0); + add_exclude (excluded, optarg, EXCLUDE_WILDCARDS | EXCLUDE_INCLUDE | EXCLUDE_ANCHORED); + break; default: try_help (NULL, NULL); @@ -919,6 +926,7 @@ static char const * const option_help_msgid[] = { N_(" --no-ignore-file-name-case consider case when comparing file names"), N_("-x, --exclude=PAT exclude files that match PAT"), N_("-X, --exclude-from=FILE exclude files that match any pattern in FILE"), + N_(" --include=PAT include files that match PAT"), N_("-S, --starting-file=FILE start with FILE when comparing directories"), N_(" --from-file=FILE1 compare FILE1 to all operands;\n" " FILE1 can be a directory"), diff --git a/tests/Makefile.am b/tests/Makefile.am index 6668863..ef236c7 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -13,7 +13,8 @@ TESTS = \ invalid-re \ function-line-vs-leading-space \ ignore-matching-lines \ - label-vs-func \ + include-exclude \ + label-vs-func \ new-file \ no-dereference \ no-newline-at-eof \ diff --git a/tests/include-exclude b/tests/include-exclude new file mode 100755 index 0000000..260d552 --- /dev/null +++ b/tests/include-exclude @@ -0,0 +1,23 @@ +#!/bin/sh +# Use of any --include or --exclude* option would segfault in 2.6 and 2.6.1 +. "${srcdir=.}/init.sh"; path_prepend_ ../src + +mkdir -p x1/dir x2/dir || framework_failure_ +echo aaa > x1/a || framework_failure_ +echo bbb > x1/b || framework_failure_ +echo ddd > x1/dir/d || framework_failure_ +echo aaa > x2/a || framework_failure_ +echo bbb > x2/c || framework_failure_ +echo ddd > x2/dir/d || framework_failure_ + +printf '%s\n' "Only in x1: b" "Only in x2: c" > only-in-b-c || framework_failure_ + +diff -r --exclude='a*' x1 x2 > out +sort -o out out || framework_failure_ +compare only-in-b-c out > /tmp/t + +diff -r --include='a*' x1 x2 > out +sort -o out out || framework_failure_ +compare only-in-b-c out || fail=1 + +Exit $fail -- 2.7.4 --------------F5C7DDBEDF82FA878CE0B3E8--
Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) Content-Type: text/plain; charset=utf-8 X-Loop: help-debbugs@HIDDEN From: help-debbugs@HIDDEN (GNU bug Tracking System) To: Kevin Hunter Kesling <hunteke@HIDDEN> Subject: bug#29139: Acknowledgement (add --include for recursive searches) Message-ID: <handler.29139.B.150974013010231.ack <at> debbugs.gnu.org> References: <a654916a-502c-f1dc-d115-2672aced4d29@HIDDEN> X-Gnu-PR-Message: ack 29139 X-Gnu-PR-Package: diffutils Reply-To: 29139 <at> debbugs.gnu.org Date: Fri, 03 Nov 2017 20:16:02 +0000 Thank you for filing a new bug report with debbugs.gnu.org. This is an automatically generated reply to let you know your message has been received. Your message is being forwarded to the package maintainers and other interested parties for their attention; they will reply in due course. Your message has been sent to the package maintainer(s): bug-diffutils@HIDDEN If you wish to submit further information on this problem, please send it to 29139 <at> debbugs.gnu.org. Please do not send mail to help-debbugs@HIDDEN unless you wish to report a problem with the Bug-tracking system. --=20 29139: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D29139 GNU Bug Tracking System Contact help-debbugs@HIDDEN with problems
X-Loop: help-debbugs@HIDDEN Subject: bug#29139: Never mind References: <a654916a-502c-f1dc-d115-2672aced4d29@HIDDEN> In-Reply-To: <a654916a-502c-f1dc-d115-2672aced4d29@HIDDEN> Resent-From: Kevin Hunter Kesling <hunteke@HIDDEN> Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> Resent-CC: bug-diffutils@HIDDEN Resent-Date: Fri, 03 Nov 2017 20:42:01 +0000 Resent-Message-ID: <handler.29139.B29139.150974171312632 <at> debbugs.gnu.org> Resent-Sender: help-debbugs@HIDDEN X-GNU-PR-Message: followup 29139 X-GNU-PR-Package: diffutils X-GNU-PR-Keywords: To: 29139 <at> debbugs.gnu.org Received: via spool by 29139-submit <at> debbugs.gnu.org id=B29139.150974171312632 (code B ref 29139); Fri, 03 Nov 2017 20:42:01 +0000 Received: (at 29139) by debbugs.gnu.org; 3 Nov 2017 20:41:53 +0000 Received: from localhost ([127.0.0.1]:49893 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1eAimn-0003Hg-FL for submit <at> debbugs.gnu.org; Fri, 03 Nov 2017 16:41:53 -0400 Received: from mail-io0-f179.google.com ([209.85.223.179]:48259) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <hunteke@HIDDEN>) id 1eAimm-0003HU-Q2 for 29139 <at> debbugs.gnu.org; Fri, 03 Nov 2017 16:41:53 -0400 Received: by mail-io0-f179.google.com with SMTP id d66so8962216ioe.5 for <29139 <at> debbugs.gnu.org>; Fri, 03 Nov 2017 13:41:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=UlayPyd2qDzAFeYVzK9w7YESVg0u71pN7tqdBqY8QU0=; b=Tz522rwW9/KeeGWBuxA88/HnGn6y/ekptMYrmr2i3l6qoQF0OnZX9O5fnXazS38OeH NEEiZ1gN4lFUEX+/Kav8KP/V5nJPSI8ii9r7qVU+ZWV3UBzMBbVJ4V/+je2VLmpbPKmG ZH/GglI8JjAzCoP4wE4g9iJE0nnc8qQ+xDV/aSfgl8hLxvJztzdg5CZCJ+4Oq/zLqH35 SmNX5msc+xG9EnoR/vpFBb7g26Hu44qe8p32sEF4E8NFlBSeq2Rk6r6hgi4UnrFmBzwi Hog8j5B1WkAp7kOS+YT+F24vCSQFpPSYCqly7baU7fMfSZhfE4aC5fQrGxPTz+8p66nN Ih4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=UlayPyd2qDzAFeYVzK9w7YESVg0u71pN7tqdBqY8QU0=; b=ln8wPHQjbkekCMzk5zXxY7xIqyaMvK/9eGopJqYEum+KC3a0IkhhIrJq6D5+kAHvSP m95tmx1ngkLZXdw4PWpG9pW+RtlY1PJhifWfQ82w78toJRWgM3VSCOtZuMVXqBoZ0KnR o6wAaylcGmFvEjSs7O3QxldJ68wff8KrtI1wz4Zl+dEHDi63QfZogfgKKSmDT7Faohxr LzUUkdtAnHCzVvQOtaXMRk0CaB1p7GXxyCKHUz0uDh0VQlAr+gMP/8RfriHtyY56rGtA HX9anHa2+oBtOfuLjD6o6WxmaMAiEGLAhbwKQHwkni7R1rYoode2KisVI4zdXTZOsAjb Bkow== X-Gm-Message-State: AJaThX4gjchI46zF5pKWvrrmWJgynn42T42f+r312APk2WitQ4X+hDFH 7vV1qpii5uDKIZz5mM1j90h5DA== X-Google-Smtp-Source: ABhQp+TapEaRBx18QFi6n9ywNrE9ss0kDL2GoAjUudIsNDzhq5Il0586P/t2Vw/QmnVWZq4+yvxmXQ== X-Received: by 10.36.53.15 with SMTP id k15mr308134ita.75.1509741706729; Fri, 03 Nov 2017 13:41:46 -0700 (PDT) Received: from [10.45.1.112] (rrcs-97-78-212-242.se.biz.rr.com. [97.78.212.242]) by smtp.googlemail.com with ESMTPSA id 191sm1531345itb.21.2017.11.03.13.41.45 for <29139 <at> debbugs.gnu.org> (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Nov 2017 13:41:45 -0700 (PDT) From: Kevin Hunter Kesling <hunteke@HIDDEN> Message-ID: <555c9646-5356-1962-a110-5a6787df86e3@HIDDEN> Date: Fri, 3 Nov 2017 16:41:45 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -2.3 (--) Having used it in a couple of ways which at first appeared to work, I've had a couple of use cases (of course, after I email the list) since surprise me. Please ignore or delete; this patch has some more baking to do ... Sorry for the noise. Kevin
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997 nCipher Corporation Ltd,
1994-97 Ian Jackson.