Re: [PATCH] submodule--helper.c: add only-active to foreach
- From
Shourya Shukla <shouryashukla.oo@gmail.com>
- Date
- May 12, 2020, 14:15 UTC
- Message-ID
- <20200512141520.GA8133@konoha>
- In-Reply-To
- <CAOEXN9yyL8T8kDmpHKTjjaG9tVS1kh34B-=PuH1hRaA7jF_K6A@mail.gmail.com>
On 10/05 11:51, Guillaume Galeazzi wrote:
Before I comment on the patch, I want to apologise for the delay in the reply. I got caught up with some stuff.
Show 10 quoted lines
> Now with the vice-versa idea in mind, I think it is maybe better to > change a bit the original patch > to add the option to execute command only on inactive submodule as > well. Could someone need > that in future? > > Basically this would mean: > > On struct foreach_cb instead of only_active adding field: > int active;
Yeah, keeping the option name as `active` would be better if we were to go for the inactive submodules option as well.
Show 7 quoted lines
> Defining some macro to hold possible value:
> #define FOREACH_ACTIVE 1
> #define FOREACH_INACTIVE 0
> #define FOREACH_ACTIVE_NOT_SET -1
>
> Changing the FOREACH_CB_INIT to
> #define FOREACH_CB_INIT { 0, NULL, NULL, 0, 0, FOREACH_ACTIVE_NOT_SET }Do we really need to include the last macro here?
Show 8 quoted lines
> The filter become:
> int is_active;
> if (FOREACH_ACTIVE_NOT_SET != info->active) {
> is_active = is_submodule_active(the_repository, path);
> if ((is_active && (FOREACH_ACTIVE != info->active)) ||
> (!is_active && (FOREACH_ACTIVE == info->active)))
> return;
> }Is it okay to compare a macro directly? I have not actually seen it happen so I am a bit skeptical. I am tagging along some people who will be able to weigh in a solid opinion regarding this.
Show 10 quoted lines
> It need two additionnal function to parse the argument:
> static int parse_active(const char *arg)
> {
> int active = git_parse_maybe_bool(arg);
>
> if (active < 0)
> die(_("invalid --active option: %s"), arg);
>
> return active;
> }Alright, this one is used for parsing out the active submodules right?
Show 22 quoted lines
> static int parse_opt_active_cb(const struct option *opt, const char *arg,
> int unset)
> {
> if (unset)
> *(int *)opt->value = FOREACH_ACTIVE_NOT_SET;
> else if (arg)
> *(int *)opt->value = parse_active(arg);
> else
> *(int *)opt->value = FOREACH_ACTIVE;
>
> return 0;
> }
>
> And the option OPT_BOOL become a OPT_CALLBACK_F:
> OPT_CALLBACK_F(0, "active", &info.active, "true|false",
> N_("Call command depending on submodule active state"),
> PARSE_OPT_OPTARG | PARSE_OPT_NONEG,
> parse_opt_active_cb),
>
> The help git_submodule_helper_usage:
> N_("git submodule--helper foreach [--quiet] [--recursive]
> [--active[=true|false]] [--] <command>"),What I have inferred right now is that we introduce the `--active` option which will take a T/F value depending on user input. We have 3 macros to check for the value of `active`, but I don't understand the significance of changing the FOREACH_CB_INIT macro to accomodate the third option. And we use a function to parse out the active submodules.
Instead of the return statement you wrote, won't it be better to call parse_active() depending on the case? Meaning that we call parse_active() when `active=true`.
Regards, Shourya Shukla