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. > 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. > 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? > 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. > 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? > 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