Re: [PATCH v2 15/22] t5515: make test hash independent

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"brian m. carlson" <sandals@xxxxxxxxxxxxxxxxxxxx> 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"

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"




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux