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

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

Previous: Guillaume GaleazziNext: Guillaume Galeazzi
Message 6 of 22 in “submodule--helper.c: add only-active to foreach”
  1. submodule--helper.c: add only-active to foreachGuillaume G. via GitGitGadget, May 10, 2020
  2. Shourya ShuklaMay 10, 2020
  3. Guillaume GaleazziMay 10, 2020
  4. Eric SunshineMay 10, 2020
  5. Guillaume GaleazziMay 15, 2020
  6. Shourya ShuklaMay 12, 2020
  7. Guillaume GaleazziMay 15, 2020
  8. Junio C HamanoMay 15, 2020
  9. Guillaume GaleazziMay 15, 2020
  10. Junio C HamanoMay 12, 2020
  11. Guillaume GaleazziMay 13, 2020
  12. Junio C HamanoMay 13, 2020
  13. Guillaume GaleazziMay 13, 2020
  14. Junio C HamanoMay 13, 2020
  15. Guillaume GaleazziMay 15, 2020
  16. 0/3 submodule--helper.c: add only-active to foreachGuillaume G. via GitGitGadget, May 17, 2020
  17. 1/3 submodule--helper.c: add active to foreachGuillaume Galeazzi via GitGitGadget, May 17, 2020
  18. 3/3 submodule--helper.c: add branch to foreachGuillaume Galeazzi via GitGitGadget, May 17, 2020
  19. 2/3 submodule--helper.c: add populated to foreachGuillaume Galeazzi via GitGitGadget, May 17, 2020
  20. Junio C HamanoMay 17, 2020
  21. Guillaume GaleazziMay 17, 2020
  22. Guillaume GaleazziAug 18, 2020

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.