Re: [PATCH v4 4/4] lib-submodule-update: use callbacks in test_submodule_switch_common()

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

 



On Thu, Jun 18, 2020 at 04:49:14AM -0400, Denton Liu wrote:

> Instead of invoking $command as one monolithic helper function, break it
> up into three parts:
> 
> 	1. $command which is always a git command.
> 	2. $before which is a callback function that runs just prior to
> 	   $command.
> 	3. $after which is a callback function that runs just after
> 	   $command.

Thanks for reworking it in this way. I do think it's less confusing than
the original.

> If the command requires a filename argument, specify it as `\$arg` since
> that variable will be set and the whole $command string will be eval'd.
> Unfortunately, there is no way to get rid of the eval as some of the
> commands that are passed (such as the `git pull` tests) require that no
> additional arguments are passed so we must have some mechanism for the
> caller to specify whether or not it wants the filename argument.

We didn't need that "\$arg" thing before because we were passing whole
functions (which then decided to pass the arg or not). Can we just keep
doing that (using functions)?

That puts the onus on callers who want to ignore the arg to wrap any
commands in a function, but saves ones who _do_ want to use the arg from
having to do anything. So it's a tradeoff, but I think an extra function
wrapper is less magical than the "\$arg" eval (plus from skimming the
diff, I think most callers do use it).

So for example, this:

> +test_submodule_switch_func "apply --3way diff" "create_diff"

becomes:

  apply_diff () {
          git apply --3way diff
  }
  test_submodule_switch_func apply_diff create_diff

Obviously that requires dropping the implicit "git" from $command (but
I'd argue that makes things less magical, too).

> @@ -326,7 +336,10 @@ test_submodule_switch_common () {
>  		(
>  			cd submodule_update &&
>  			git branch -t add_sub1 origin/add_sub1 &&
> -			$command add_sub1 &&
> +			arg=add_sub1 &&
> +			$before "$arg" &&
> +			eval $command &&
> +			$after "$arg" &&

This block gets repeated a lot, and I wondered if a helper function
could make it better. But:

  1. We'd have to pass in a bunch of variables (or consider them as
     magic globals).

  2. Some callers want test_must_fail and other's don't.

So I think it would be something like:

  do_command () {
    $before "$1" &&
    "$2" $command "$1" &&
    $after "$1"
  }

  ...
  do_command add_sub1 &&
  ...

There's definitely still some magic there, but at least it's all
contained within the one script. I could go either way on it.

-Peff



[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