git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] test-lib: fix "$remove_trash" regression and match_pattern_list() bugs

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Jun 16, 2021, 11:38 UTC
Message-ID
<87k0muxcd7.fsf@evledraar.gmail.com>
In-Reply-To
<YMnRC8v4RLDk2+K9@coredump.intra.peff.net>
On Wed, Jun 16 2021, Jeff King wrote:
Show 14 quoted lines
> On Wed, Jun 16, 2021 at 06:22:10PM +0900, Junio C Hamano wrote:
>
>> Jeff King <peff@peff.net> writes:
>> 
>> > ... Still, I kind of like the "set -f" version because it doesn't need
>> > the extra directory which could cause problems with "ls-files -o", etc,
>> > as you mentioned. You could also create the empty directory on the fly,
>> > though if "set -f" works portably, that seems less complicated to me.
>> 
>> FWIW, I share that.
>
> Here it is with some cosmetic cleanups and a commit message. I don't
> mean to preempt further discussion if Ævar prefers another route, but I
> want to make sure we didn't stall out.

I mildly prefer mine as noted in https://lore.kernel.org/git/87pmwmxd6f.fsf@evledraar.gmail.com/; but I'd mainly prefer just to fix the immediate breakage on master, so whatever variant of reverting, taking yours or mine Junio prefers I'm fine with.

Just inline comments on the patch:
Show 31 quoted lines
> @@ -732,14 +732,24 @@ match_pattern_list () {
>  	arg="$1"
>  	shift
>  	test -z "$*" && return 1
> -	for pattern_
> -	do
> -		case "$arg" in
> -		$pattern_)
> -			return 0
> -		esac
> -	done
> -	return 1
> +	# We need to use "$*" to get field-splitting, but we want to
> +	# disable globbing, since we are matching against an arbitrary
> +	# $arg, not what's in the filesystem. Using "set -f" accomplishes
> +	# that, but we must do it in a subshell to avoid impacting the
> +	# rest of the script. The exit value of the subshell becomes
> +	# the function's return value.
> +	(
> +		set -f
> +		for pattern_ in $*
> +		do
> +			case "$arg" in
> +			$pattern_)
> +				exit 0
> +				;;
> +			esac
> +		done
> +		exit 1
> +	)
>  }

Why not just start with a ret=1, set ret=0 if we have a match and break from the loop, and then do a "set +f" afterwards? I.e. is there an actual need for the subshell here.

I'm mildly paranoid about a new "set -<flag>" in the codebase for vague fears of portability (as noted in my linked message), but whatever shell supports "set -<flag>" surely supports the inverse with "set +<flag>", no?

Previous: Jeff KingNext: Jeff King
Message 12 of 17 in “[BUG] question mark in GIT_SKIP_TESTS is broken in master”
  1. Andrei RybakJun 15, 2021
  2. [BUG] range expressions in GIT_SKIP_TESTS are broken in master (was [BUG] question mark in GIT_SKIP_TESTS is broken in master)Andrei Rybak, Jun 15, 2021
  3. Junio C HamanoJun 16, 2021
  4. Junio C HamanoJun 16, 2021
  5. Jeff KingJun 16, 2021
  6. Junio C HamanoJun 16, 2021
  7. test-lib: fix "$remove_trash" regression and match_pattern_list() bugsÆvar Arnfjörð Bjarmason, Jun 16, 2021
  8. Jeff KingJun 16, 2021
  9. Junio C HamanoJun 16, 2021
  10. Jeff KingJun 16, 2021
  11. Jeff KingJun 16, 2021
  12. Ævar Arnfjörð BjarmasonJun 16, 2021
  13. Jeff KingJun 16, 2021
  14. Junio C HamanoJun 17, 2021
  15. Ævar Arnfjörð BjarmasonJun 16, 2021
  16. Jeff KingJun 16, 2021
  17. Junio C HamanoJun 17, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.