File quilt-patches-optimize-processing-of-unapplied-patches.patch of Package quilt.4649

From: Jean Delvare <jdelvare@suse.de>
Date: Sat, 15 Feb 2014 18:43:41 +0100
Subject: patches: Optimize processing of unapplied patches
Patch-mainline: yes
Git-commit: 1b95644e3a00f07a6711c881d2dcdac14206a57e
References: bnc#872719

* Don't check for $strip = ab twice, once is enough.
* Quote the file names to be suitable in regular expressions only
  once, instead of doing it again for every patch. This fixes a
  performance regression introduced in 8ebb056d ("patches: Add
  support for multiple files"), sorry about that.

These two simple changes bring a huge performance boost on unapplied
patches, of about 50% in the single file case and growing as you add
files.

diff --git a/quilt/patches.in b/quilt/patches.in
index 3f3caed..6ec5e01 100644
--- a/quilt/patches.in
+++ b/quilt/patches.in
@@ -70,7 +70,6 @@ scan_applied()
 touched_by_patch()
 {
 	local strip=$1 patch=$2
-	[ $strip = ab ] && strip=1
 	cat_file $(patch_file_name $patch) \
 	|  awk '
 	/^(\+\+\+|---)[ \t]/ {
@@ -89,7 +88,14 @@ scan_unapplied()
 {
 	local color=$1 prefix=$2 strip
 	shift 2
-	local patch file file_bre match
+	local patch file match
+	local -a files_bre
+
+	# Quote each file name only once
+	for file in "${opt_files[@]}"
+	do
+		files_bre[${#files_bre[@]}]=$(quote_bre "$file")
+	done
 
 	for patch in "$@"
 	do
@@ -97,11 +103,10 @@ scan_unapplied()
 		[ "$strip" = ab ] && strip=1
 
 		match=
-		for file in "${opt_files[@]}"
+		for file in "${files_bre[@]}"
 		do
-			file_bre="$(quote_bre "$file")"
 			if touched_by_patch $strip $patch \
-			   | grep -q "^$file_bre\$"
+			   | grep -q "^$file\$"
 			then
 				match=1
 				break
openSUSE Build Service is sponsored by