Re: [PATCH v2 21/28] submodule--helper: don't call submodule_strategy_to_string() in BUG()
- From
Glen Choo <chooglen@google.com>
- Date
- Aug 2, 2022, 23:08 UTC
- Message-ID
- <kl6lo7x2tfa2.fsf@chooglen-macbookpro.roam.corp.google.com>
- In-Reply-To
- <patch-v2-21.28-bce1a014a2f-20220802T154036Z-avarab@gmail.com>
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
Show 27 quoted lines
> Don't call submodule_strategy_to_string() in a BUG() message. These
> calls added in c51f8f94e5b (submodule--helper: run update procedures
> from C, 2021-08-24) don't need the extra information
> submodule_strategy_to_string() gives us, as we'll never reach the
> SM_UPDATE_COMMAND case here.
>
> That case is the only one where we'd get any information beyond the
> straightforward number-to-string mapping.
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
> builtin/submodule--helper.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> index 955deb375ee..b49528e1ba9 100644
> --- a/builtin/submodule--helper.c
> +++ b/builtin/submodule--helper.c
> @@ -2155,8 +2155,8 @@ static int run_update_command(struct update_data *ud, int subforce)
> must_die_on_failure = 1;
> break;
> default:
> - BUG("unexpected update strategy type: %s",
> - submodule_strategy_to_string(&ud->update_strategy));
> + BUG("unexpected update strategy type: %d",
> + ud->update_strategy.type);
> }At first I worried that we would be losing readability by printing the raw int value instead of a string, but then I remembered that we probably wouldn't print anything sensible for an unknown value anyway :x
What makes this change obviously good is that we're switching on ud->update_strategy.type, so it makes the most sense to print that value (instead of ud->update_strategy). Unfortunately we can't see that from the context lines though.
Show 26 quoted lines
> strvec_push(&cp.args, oid);
>
> @@ -2181,8 +2181,8 @@ static int run_update_command(struct update_data *ud, int subforce)
> ud->update_strategy.command, oid, ud->displaypath);
> break;
> default:
> - BUG("unexpected update strategy type: %s",
> - submodule_strategy_to_string(&ud->update_strategy));
> + BUG("unexpected update strategy type: %d",
> + ud->update_strategy.type);
> }
> if (must_die_on_failure)
> exit(128);
> @@ -2212,8 +2212,8 @@ static int run_update_command(struct update_data *ud, int subforce)
> ud->displaypath, ud->update_strategy.command, oid);
> break;
> default:
> - BUG("unexpected update strategy type: %s",
> - submodule_strategy_to_string(&ud->update_strategy));
> + BUG("unexpected update strategy type: %d",
> + ud->update_strategy.type);
> }
>
> return 0;
> --
> 2.37.1.1233.ge8b09efaedc