From 68e276cc19f796c905dd886d9222c2ef3db13c39 Mon Sep 17 00:00:00 2001 From: Michal Koutný Date: Feb 21 2023 18:12:48 +0000 Subject: scripts/renamepatches: Optimize search Use bash hashmap instead of grepping list file. sample: 5.0s -> 2.5s Composed result with previous commit on SLE15-SP4->SLE15-SP5: original Executed in 207.82 secs fish external usr time 263.64 secs 459.00 micros 263.64 secs sys time 60.61 secs 185.00 micros 60.61 secs optimized Executed in 65.73 secs fish external usr time 49.16 secs 639.00 micros 49.16 secs sys time 18.52 secs 0.00 micros 18.52 secs --- diff --git a/scripts/renamepatches b/scripts/renamepatches index fa2b5bc..8292b69 100755 --- a/scripts/renamepatches +++ b/scripts/renamepatches @@ -29,15 +29,20 @@ fi branch=$1 trap 'rm -f "$temp"' EXIT temp=$(mktemp) -git grep -iE '^(Git-commit:|No-fix:|\(cherry picked from commit)' $branch | grep -vF patches.kernel.org > $temp +git grep -iE '^(Git-commit:|No-fix:|\(cherry picked from commit)' $branch | tr ':' ' ' | \ + awk '!/patches.kernel.org/ {fn=$2; hash=$NF; map[hash]=map[hash] fn;} + END { for (hash in map) printf("map[%s]=\"%s\"\n", hash, map[hash]); }' \ + >$temp + +declare -A map +source $temp grep -E "^[[:space:]]*patches\.[a-z]+\/" < series.conf | while read patch ; do [ ! -f "$patch" ] && continue commit="$(awk -v IGNORECASE=1 '/^(Git-commit|No-fix):/ { print $2} /^\(cherry picked from commit/ { print $5}' $patch)" - [ -n "$commit" ] && echo "$commit" | while read c ; do - grep -F $c < $temp | tr ':' ' ' | while read junk fn blah ; do - [ -n "$fn" ] && [ $fn != $patch ] && git mv $patch $fn && sed -i -e "s,$patch,$fn," series.conf - done - done + [ -z "$commit" ] && continue + for fn in ${map[$commit]} ; do + [ $fn != $patch ] && git mv $patch $fn && sed -i -e "s,$patch,$fn," series.conf + done done