Re: [PATCH v2 15/22] t5515: make test hash independent
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jan 28, 2020, 18:28 UTC
- Message-ID
- <xmqqk15b8mfs.fsf@gitster-ct.c.googlers.com>
- In-Reply-To
- <20200125230035.136348-16-sandals@crustytoothpaste.net>
"brian m. carlson" <sandals@crustytoothpaste.net> writes:
Show 9 quoted lines
> +convert_expected () {
> + file="$1" &&
> + for i in one three_file master master2 one_tree three two two2 three2
> + do
> + sed -e "s/$(test_oid --hash=sha1 "$i")/$(test_oid "$i")/g" \
> + "$file" >"$file.tmp" &&
> + mv "$file.tmp" "$file"
> + done
> +}Perhaps we can avoid rewriting the same file that many times, by feeding the mapping to a single invocation of sed? E.g.
sedScript=
for i in one three_file master master2 one_tree three two two2 three2
do
i="s/$(test_oid --hash=sha1 $i/$(test_oid $i)/g"
sedScript=$sedScript${sedScript:+;}$i"
done &&
sed -e "$sedScript" "$file" >"$file.new" &&
mv "$file.new" "$file"If somebody's "sed" does not like multiple command concatenated with ";", we can take advantage of the fact that we are just replacing hexadecimal string without anything funny and go eval, e.g.
sedCmd="sed" for i in one three_file master master2 one_tree three two two2 three2 do sedCmd="$sedCmd -e s/$(test_oid --hash=sha1 $i/$(test_oid $i)/g" done && eval "$sedCmd" "$file" >"$file.new" && mv "$file.new" "$file"