xref: /OK3568_Linux_fs/yocto/poky/meta/recipes-devtools/quilt/quilt/fix-grep-3.8.patch (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1From f73f8d7f71de2878d3f92881a5fcb8eafd78cb5f Mon Sep 17 00:00:00 2001
2From: Jean Delvare <jdelvare@suse.de>
3Date: Fri, 9 Sep 2022 10:10:37 +0200
4Subject: Avoid warnings with grep 3.8
5
6GNU grep version 3.8 became more strict about needless quoting in
7patterns. We have one occurrence of that in quilt, where "/"
8characters are being quoted by default. There are cases where they
9indeed need to be quoted (typically when used in a sed s/// command)
10but most of the time they do not, and this results in the following
11warning:
12
13grep: warning: stray \ before /
14
15So rename quote_bre() to quote_sed_re(), and introduce
16quote_grep_re() which does not quote "/".
17
18Signed-off-by: Jean Delvare <jdelvare@suse.de>
19Upstream-Status: Backport [https://git.savannah.nongnu.org/cgit/quilt.git/commit/?id=f73f8d7f71de2878d3f92881a5fcb8eafd78cb5f]
20Signed-off-by: Alexander Kanavin <alex@linutronix.de>
21---
22 quilt/diff.in             |  2 +-
23 quilt/patches.in          |  2 +-
24 quilt/scripts/patchfns.in | 20 +++++++++++++-------
25 quilt/upgrade.in          |  4 ++--
26 4 files changed, 17 insertions(+), 11 deletions(-)
27
28diff --git a/quilt/diff.in b/quilt/diff.in
29index e90dc33..07788ff 100644
30--- a/quilt/diff.in
31+++ b/quilt/diff.in
32@@ -255,7 +255,7 @@ then
33 	# Add all files in the snapshot into the file list (they may all
34 	# have changed).
35 	files=( $(find $QUILT_PC/$snap_subdir -type f \
36-		  | sed -e "s/^$(quote_bre $QUILT_PC/$snap_subdir/)//" \
37+		  | sed -e "s/^$(quote_sed_re $QUILT_PC/$snap_subdir/)//" \
38 		  | sort) )
39 	printf "%s\n" "${files[@]}" >&4
40 	unset files
41diff --git a/quilt/patches.in b/quilt/patches.in
42index bb17a46..eac45a9 100644
43--- a/quilt/patches.in
44+++ b/quilt/patches.in
45@@ -60,7 +60,7 @@ scan_unapplied()
46 	# Quote each file name only once
47 	for file in "${opt_files[@]}"
48 	do
49-		files_bre[${#files_bre[@]}]=$(quote_bre "$file")
50+		files_bre[${#files_bre[@]}]=$(quote_grep_re "$file")
51 	done
52
53 	# "Or" all files in a single pattern
54diff --git a/quilt/scripts/patchfns.in b/quilt/scripts/patchfns.in
55index c2d5f9d..1bd7233 100644
56--- a/quilt/scripts/patchfns.in
57+++ b/quilt/scripts/patchfns.in
58@@ -78,8 +78,14 @@ array_join()
59 	done
60 }
61
62-# Quote a string for use in a basic regular expression.
63-quote_bre()
64+# Quote a string for use in a regular expression for a grep pattern.
65+quote_grep_re()
66+{
67+	echo "$1" | sed -e 's:\([][^$.*\\]\):\\\1:g'
68+}
69+
70+# Quote a string for use in a regular expression for a sed s/// command.
71+quote_sed_re()
72 {
73 	echo "$1" | sed -e 's:\([][^$/.*\\]\):\\\1:g'
74 }
75@@ -215,7 +221,7 @@ patch_in_series()
76
77 	if [ -e "$SERIES" ]
78 	then
79-		grep -q "^$(quote_bre $patch)\([ \t]\|$\)" "$SERIES"
80+		grep -q "^$(quote_grep_re $patch)\([ \t]\|$\)" "$SERIES"
81 	else
82 		return 1
83 	fi
84@@ -365,7 +371,7 @@ is_applied()
85 {
86 	local patch=$1
87 	[ -e $DB ] || return 1
88-	grep -q "^$(quote_bre $patch)\$" $DB
89+	grep -q "^$(quote_grep_re $patch)\$" $DB
90 }
91
92 applied_patches()
93@@ -465,7 +471,7 @@ remove_from_db()
94 	local tmpfile
95 	if tmpfile=$(gen_tempfile)
96 	then
97-		grep -v "^$(quote_bre $patch)\$" $DB > $tmpfile
98+		grep -v "^$(quote_grep_re $patch)\$" $DB > $tmpfile
99 		cat $tmpfile > $DB
100 		rm -f $tmpfile
101 		[ -s $DB ] || rm -f $DB
102@@ -520,7 +526,7 @@ find_patch()
103 		fi
104
105 		local patch=${1#$SUBDIR_DOWN$QUILT_PATCHES/}
106-		local bre=$(quote_bre "$patch")
107+		local bre=$(quote_sed_re "$patch")
108 		set -- $(sed -e "/^$bre\(\|\.patch\|\.diff\?\)\(\|\.gz\|\.bz2\|\.xz\|\.lzma\|\.lz\)\([ "$'\t'"]\|$\)/!d" \
109 			       -e 's/[ '$'\t''].*//' "$SERIES")
110 		if [ $# -eq 1 ]
111@@ -631,7 +637,7 @@ files_in_patch()
112 	then
113 		find "$path" -type f \
114 			       -a ! -path "$(quote_glob "$path")/.timestamp" |
115-		sed -e "s/$(quote_bre "$path")\///"
116+		sed -e "s/$(quote_sed_re "$path")\///"
117 	fi
118 }
119
120diff --git a/quilt/upgrade.in b/quilt/upgrade.in
121index dbf7d05..866aa33 100644
122--- a/quilt/upgrade.in
123+++ b/quilt/upgrade.in
124@@ -74,7 +74,7 @@ printf $"Converting meta-data to version %s\n" "$DB_VERSION"
125
126 for patch in $(applied_patches)
127 do
128-	proper_name="$(grep "^$(quote_bre $patch)"'\(\|\.patch\|\.diff?\)\(\|\.gz\|\.bz2\)\([ \t]\|$\)' $SERIES)"
129+	proper_name="$(grep "^$(quote_grep_re $patch)"'\(\|\.patch\|\.diff?\)\(\|\.gz\|\.bz2\)\([ \t]\|$\)' $SERIES)"
130 	proper_name=${proper_name#$QUILT_PATCHES/}
131 	proper_name=${proper_name%% *}
132 	if [ -z "$proper_name" ]
133@@ -84,7 +84,7 @@ do
134 	fi
135
136 	if [ "$patch" != "$proper_name" -a -d $QUILT_PC/$patch ] \
137-	   && grep -q "^$(quote_bre $patch)\$" \
138+	   && grep -q "^$(quote_grep_re $patch)\$" \
139 		   $QUILT_PC/applied-patches
140 	then
141 		mv $QUILT_PC/$patch $QUILT_PC/$proper_name \
142--
143cgit v1.1
144
145