backport: grep: support for -x, match whole line
authorDennis Groenen <tj.groenen@gmail.com>
Tue, 10 Apr 2012 15:32:13 +0000 (17:32 +0200)
committerDennis Groenen <tj.groenen@gmail.com>
Tue, 10 Apr 2012 15:32:13 +0000 (17:32 +0200)
debian/patches/git-backports/0001-grep-support-for-x-match-whole-line.patch [new file with mode: 0644]
debian/patches/series

diff --git a/debian/patches/git-backports/0001-grep-support-for-x-match-whole-line.patch b/debian/patches/git-backports/0001-grep-support-for-x-match-whole-line.patch
new file mode 100644 (file)
index 0000000..a381e22
--- /dev/null
@@ -0,0 +1,69 @@
+From cd09e81520b7917adebcffd7c361671f913325eb Mon Sep 17 00:00:00 2001
+From: Natanael Copa <ncopa@alpinelinux.org>
+Date: Thu, 23 Feb 2012 14:20:22 +0000
+Subject: [PATCH] grep: support for -x, match whole line
+
+Specified in POSIX.
+http://pubs.opengroup.org/onlinepubs/009604499/utilities/grep.html
+
+Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
+Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
+---
+ findutils/grep.c |   12 +++++++++---
+ 1 file changed, 9 insertions(+), 3 deletions(-)
+
+diff --git a/findutils/grep.c b/findutils/grep.c
+index 5f42242..f14d6e6 100644
+--- a/findutils/grep.c
++++ b/findutils/grep.c
+@@ -85,6 +85,7 @@
+ //usage:     "\n      -r      Recurse"
+ //usage:     "\n      -i      Ignore case"
+ //usage:     "\n      -w      Match whole words only"
++//usage:     "\n      -x      Match whole lines only"
+ //usage:     "\n      -F      PATTERN is a literal (not regexp)"
+ //usage:      IF_FEATURE_GREP_EGREP_ALIAS(
+ //usage:     "\n      -E      PATTERN is an extended regexp"
+@@ -113,7 +114,7 @@
+ //usage:#define fgrep_full_usage ""
+ #define OPTSTR_GREP \
+-      "lnqvscFiHhe:f:Lorm:w" \
++      "lnqvscFiHhe:f:Lorm:wx" \
+       IF_FEATURE_GREP_CONTEXT("A:B:C:") \
+       IF_FEATURE_GREP_EGREP_ALIAS("E") \
+       IF_EXTRA_COMPAT("z") \
+@@ -138,6 +139,7 @@ enum {
+       OPTBIT_r, /* recurse dirs */
+       OPTBIT_m, /* -m MAX_MATCHES */
+       OPTBIT_w, /* -w whole word match */
++      OPTBIT_x, /* -x whole line match */
+       IF_FEATURE_GREP_CONTEXT(    OPTBIT_A ,) /* -A NUM: after-match context */
+       IF_FEATURE_GREP_CONTEXT(    OPTBIT_B ,) /* -B NUM: before-match context */
+       IF_FEATURE_GREP_CONTEXT(    OPTBIT_C ,) /* -C NUM: -A and -B combined */
+@@ -160,6 +162,7 @@ enum {
+       OPT_r = 1 << OPTBIT_r,
+       OPT_m = 1 << OPTBIT_m,
+       OPT_w = 1 << OPTBIT_w,
++      OPT_x = 1 << OPTBIT_x,
+       OPT_A = IF_FEATURE_GREP_CONTEXT(    (1 << OPTBIT_A)) + 0,
+       OPT_B = IF_FEATURE_GREP_CONTEXT(    (1 << OPTBIT_B)) + 0,
+       OPT_C = IF_FEATURE_GREP_CONTEXT(    (1 << OPTBIT_C)) + 0,
+@@ -370,9 +373,12 @@ static int grep_file(FILE *file)
+                                                       &gl->matched_range) >= 0
+ #endif
+                               ) {
+-                                      if (!(option_mask32 & OPT_w))
++                                      if (option_mask32 & OPT_x) {
++                                              found = (gl->matched_range.rm_so == 0
++                                                       && line[gl->matched_range.rm_eo] == '\0');
++                                      } else if (!(option_mask32 & OPT_w)) {
+                                               found = 1;
+-                                      else {
++                                      } else {
+                                               char c = ' ';
+                                               if (gl->matched_range.rm_so)
+                                                       c = line[gl->matched_range.rm_so - 1];
+-- 
+1.7.9.3
+
index eac5971..cf503d1 100644 (file)
@@ -28,6 +28,7 @@ showkey-default-option.patch
 git-backports/0001-lineedit-fix-atomic-replace-of-history-file-hush-fix.patch
 git-backports/0002-lineedit-add-support-for-history-saving-on-exit.patch
 git-backports/0003-lineedit-remove-SAVE_HISTORY-bit-hist_file-can-be-us.patch
+git-backports/0001-grep-support-for-x-match-whole-line.patch
 
 #Miscellaneous
 0001-lineedit-fix-history-saving-when-history-MAX_HISTORY.patch