quilt-dev
[Top][All Lists]
Advanced

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

[Quilt-dev] [PATCH v2] Avoid warnings with grep 3.8


From: Jean Delvare
Subject: [Quilt-dev] [PATCH v2] Avoid warnings with grep 3.8
Date: Thu, 8 Sep 2022 13:30:42 +0200

GNU grep version 3.8 became more strict about needless quoting in
patterns. We have one occurrence of that in quilt, where "/"
characters are being quoted by default. There are cases where they
indeed need to be quoted (typically when used in a sed s/// command)
but most of the time they do not, and this results in the following
warning:

grep: warning: stray \ before /

So rename quote_bre() to quote_sed_re(), and introduce
quote_grep_re() which does not quote "/".

Signed-off-by: Jean Delvare <jdelvare@suse.de>
---
Changes since v1:
 * Make quote_sed_re() a separate function (suggested by Andreas
   Grünbacher)

For consistency, should we rename quote_re() to quote_awk_re() (in a
separate patch)?

 quilt/diff.in             |    2 +-
 quilt/patches.in          |    2 +-
 quilt/scripts/patchfns.in |   18 ++++++++++++------
 quilt/upgrade.in          |    4 ++--
 4 files changed, 16 insertions(+), 10 deletions(-)

--- quilt.orig/quilt/scripts/patchfns.in        2022-09-08 11:47:37.227482698 
+0200
+++ quilt/quilt/scripts/patchfns.in     2022-09-08 13:16:01.437819905 +0200
@@ -79,7 +79,13 @@ array_join()
 }
 
 # Quote a string for use in a basic regular expression.
-quote_bre()
+quote_grep_re()
+{
+       echo "$1" | sed -e 's:\([][^$.*\\]\):\\\1:g'
+}
+
+# Quote a string for use in a regular expression for a sed s/// command.
+quote_sed_re()
 {
        echo "$1" | sed -e 's:\([][^$/.*\\]\):\\\1:g'
 }
@@ -215,7 +221,7 @@ patch_in_series()
 
        if [ -e "$SERIES" ]
        then
-               grep -q "^$(quote_bre $patch)\([ \t]\|$\)" "$SERIES"
+               grep -q "^$(quote_grep_re $patch)\([ \t]\|$\)" "$SERIES"
        else
                return 1
        fi
@@ -365,7 +371,7 @@ is_applied()
 {
        local patch=$1
        [ -e $DB ] || return 1
-       grep -q "^$(quote_bre $patch)\$" $DB
+       grep -q "^$(quote_grep_re $patch)\$" $DB
 }
 
 applied_patches()
@@ -465,7 +471,7 @@ remove_from_db()
        local tmpfile
        if tmpfile=$(gen_tempfile)
        then
-               grep -v "^$(quote_bre $patch)\$" $DB > $tmpfile
+               grep -v "^$(quote_grep_re $patch)\$" $DB > $tmpfile
                cat $tmpfile > $DB
                rm -f $tmpfile
                [ -s $DB ] || rm -f $DB
@@ -520,7 +526,7 @@ find_patch()
                fi
 
                local patch=${1#$SUBDIR_DOWN$QUILT_PATCHES/}
-               local bre=$(quote_bre "$patch")
+               local bre=$(quote_sed_re "$patch")
                set -- $(sed -e 
"/^$bre\(\|\.patch\|\.diff\?\)\(\|\.gz\|\.bz2\|\.xz\|\.lzma\|\.lz\)\([ 
"$'\t'"]\|$\)/!d" \
                               -e 's/[ '$'\t''].*//' "$SERIES")
                if [ $# -eq 1 ]
@@ -631,7 +637,7 @@ files_in_patch()
        then
                find "$path" -type f \
                               -a ! -path "$(quote_glob "$path")/.timestamp" |
-               sed -e "s/$(quote_bre "$path")\///"
+               sed -e "s/$(quote_sed_re "$path")\///"
        fi
 }
 
--- quilt.orig/quilt/diff.in    2022-09-08 11:47:37.227482698 +0200
+++ quilt/quilt/diff.in 2022-09-08 13:16:25.718149499 +0200
@@ -255,7 +255,7 @@ then
        # Add all files in the snapshot into the file list (they may all
        # have changed).
        files=( $(find $QUILT_PC/$snap_subdir -type f \
-                 | sed -e "s/^$(quote_bre $QUILT_PC/$snap_subdir/)//" \
+                 | sed -e "s/^$(quote_sed_re $QUILT_PC/$snap_subdir/)//" \
                  | sort) )
        printf "%s\n" "${files[@]}" >&4
        unset files
--- quilt.orig/quilt/patches.in 2021-06-10 17:20:57.451690733 +0200
+++ quilt/quilt/patches.in      2022-09-08 13:17:13.540798670 +0200
@@ -60,7 +60,7 @@ scan_unapplied()
        # Quote each file name only once
        for file in "${opt_files[@]}"
        do
-               files_bre[${#files_bre[@]}]=$(quote_bre "$file")
+               files_bre[${#files_bre[@]}]=$(quote_grep_re "$file")
        done
 
        # "Or" all files in a single pattern
--- quilt.orig/quilt/upgrade.in 2021-06-10 17:14:19.076768466 +0200
+++ quilt/quilt/upgrade.in      2022-09-08 13:16:41.625365433 +0200
@@ -74,7 +74,7 @@ printf $"Converting meta-data to version
 
 for patch in $(applied_patches)
 do
-       proper_name="$(grep "^$(quote_bre 
$patch)"'\(\|\.patch\|\.diff?\)\(\|\.gz\|\.bz2\)\([ \t]\|$\)' $SERIES)"
+       proper_name="$(grep "^$(quote_grep_re 
$patch)"'\(\|\.patch\|\.diff?\)\(\|\.gz\|\.bz2\)\([ \t]\|$\)' $SERIES)"
        proper_name=${proper_name#$QUILT_PATCHES/}
        proper_name=${proper_name%% *}
        if [ -z "$proper_name" ]
@@ -84,7 +84,7 @@ do
        fi
 
        if [ "$patch" != "$proper_name" -a -d $QUILT_PC/$patch ] \
-          && grep -q "^$(quote_bre $patch)\$" \
+          && grep -q "^$(quote_grep_re $patch)\$" \
                   $QUILT_PC/applied-patches
        then
                mv $QUILT_PC/$patch $QUILT_PC/$proper_name \


-- 
Jean Delvare
SUSE L3 Support



reply via email to

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