SHA256
1
0
forked from pool/quilt
quilt/quilt-patches-optimize-the-multiple-files-case.patch
Jean Delvare 3a7d64b475 Backport functional and performance regression fixes from upstream:
* Fix bash completion of patch names
* Fix refresh error message
* Fix quilt diff -z on file names including spaces
* Fix quilt files output when there are no files
* Fix patches heuristic for unapplied patches with timestamps
* Re-enable testing of patch-wrapper
* Fix performance regression in quilt patches
* Performance boost for series, applies and unapplied commands

OBS-URL: https://build.opensuse.org/package/show/devel:tools:scm/quilt?expand=0&rev=78
2014-04-25 16:11:32 +00:00

86 lines
2.1 KiB
Diff

From: Jean Delvare <jdelvare@suse.de>
Date: Sat, 15 Feb 2014 18:43:48 +0100
Subject: patches: Optimize the multiple files case
Patch-mainline: yes
Git-commit: aadae7a30499c318ae18cb6b216f1d7fe60e49b7
References: bnc#872719
I didn't put too many thoughts when adding support for multiple files
to the "patches" command. The nested loop approach turns out to be
very inefficient for unapplied patches.
Get rid of the innermost loop by building a single pattern matching
all filenames at once. That way, performance no longer depends on the
number of files (as far as unapplied patches are concerned.)
diff --git a/quilt/patches.in b/quilt/patches.in
index 6ec5e01..89c5b86 100644
--- a/quilt/patches.in
+++ b/quilt/patches.in
@@ -88,7 +88,7 @@ scan_unapplied()
{
local color=$1 prefix=$2 strip
shift 2
- local patch file match
+ local patch file
local -a files_bre
# Quote each file name only once
@@ -97,23 +97,19 @@ scan_unapplied()
files_bre[${#files_bre[@]}]=$(quote_bre "$file")
done
+ # "Or" all files in a single pattern
+ file=\\\($(array_join \\\| "${files_bre[@]}")\\\)
+
for patch in "$@"
do
strip=$(patch_strip_level $patch)
[ "$strip" = ab ] && strip=1
- match=
- for file in "${files_bre[@]}"
- do
- if touched_by_patch $strip $patch \
- | grep -q "^$file\$"
- then
- match=1
- break
- fi
- done
-
- [ -z "$match" ] || echo "$color$prefix$(print_patch $patch)$color_clear"
+ if touched_by_patch $strip "$patch" \
+ | grep -q "^$file\$"
+ then
+ echo "$color$prefix$(print_patch $patch)$color_clear"
+ fi
done
}
diff --git a/quilt/scripts/patchfns.in b/quilt/scripts/patchfns.in
index 42e8de8..e00c819 100644
--- a/quilt/scripts/patchfns.in
+++ b/quilt/scripts/patchfns.in
@@ -76,6 +76,20 @@ trap run_exit_handlers EXIT
# ========================================================
+# Join multiple stings using the given separator.
+array_join()
+{
+ local sep=$1 str=$2
+ shift 2
+
+ printf %s "$str"
+
+ for str in "$@"
+ do
+ printf %s%s "$sep" "$str"
+ done
+}
+
# Quote a string for use in a basic regular expression.
quote_bre()
{