Re: [PATCH v2 15/22] t5515: make test hash independent
- From
brian m. carlson <sandals@crustytoothpaste.net>
- Date
- Jan 29, 2020, 04:04 UTC
- Message-ID
- <20200129040445.GM4113372@camp.crustytoothpaste.net>
- In-Reply-To
- <xmqqk15b8mfs.fsf@gitster-ct.c.googlers.com>
On 2020-01-28 at 18:28:55, Junio C Hamano wrote:
Show 23 quoted lines
> "brian m. carlson" <sandals@crustytoothpaste.net> writes:
>
> > +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"This is a good idea. We could also write a small sed script to a file at the beginning and invoke it with sed -f. That's portable (POSIX supports it) and should be easy and efficient to do.
-- brian m. carlson: Houston, Texas, US OpenPGP: https://keybase.io/bk2204