summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2018-07-12 14:07:53 +0200
committerErich Eckner <git@eckner.net>2018-07-12 14:07:53 +0200
commit47e77aaa2bed7c96e727a3d33cf3fb779212be2f (patch)
tree6d1f8ec4399963cc952b63d6b48e4382f255aa62
parentf667025d2076b31eab833aafdeb2e24c765dd1a7 (diff)
downloadmerge-kernel-configs-47e77aaa2bed7c96e727a3d33cf3fb779212be2f.tar.xz
merge-kernel-configs: run in O(n log(n)) instead of O(n^2)HEADmaster
-rwxr-xr-xmerge-kernel-configs52
1 files changed, 29 insertions, 23 deletions
diff --git a/merge-kernel-configs b/merge-kernel-configs
index d8d86e3..cf58157 100755
--- a/merge-kernel-configs
+++ b/merge-kernel-configs
@@ -1,26 +1,32 @@
#!/bin/bash
-# merge-kernel-configs $out
-# (reads from stdin)
+# merge-kernel-configs
+# (reads from stdin, writes to stdout)
-rm -f "$1"
-touch "$1"
-
-while read -r line; do
- variable=$(
- printf '%s\n' "${line}" | \
- sed '
- s/^# \(\S\+\) is not set$/\1/
- t
- s/=.*$//
- t
- d
- '
- )
- if [ -z "${variable}" ] || \
- grep -q '^\(# \)\?'"${variable}"'[= ]' "$1"; then
- continue
- fi
- printf '%s\n' "${line}" >> \
- "$1"
-done
+sed '
+ s/^# \(\S\+\) is not set$/\1 \0/
+ tf
+ s/^\(\S\+\)=/\1 \0/
+ tf
+ d
+ :f
+ =
+' | \
+ sed '
+ N
+ s/\n/ /
+ ' | \
+ while read -r num variable line; do
+ printf '%s %s %s\n' \
+ "${num}" \
+ "$(
+ printf '%s\n' "${line}" | \
+ base64 -w0
+ )" \
+ "${variable}"
+ done | \
+ sort -k3,3 -k1n,1 -k2,2 | \
+ uniq -f2 | \
+ sort -k1,1 | \
+ cut -d' ' -f2 | \
+ parallel --pipe -L1 base64 -d