All of lore.kernel.org
 help / color / mirror / Atom feed
From: Shourya Shukla <shouryashukla.oo@gmail.com>
To: Guillaume Galeazzi <guillaume.galeazzi@gmail.com>
Cc: git@vger.kernel.org, christian.couder@gmail.com,
	liu.denton@gmail.com, gitster@pobox.com
Subject: Re: [PATCH] submodule--helper.c: add only-active to foreach
Date: Tue, 12 May 2020 19:45:20 +0530	[thread overview]
Message-ID: <20200512141520.GA8133@konoha> (raw)
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.

> 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

  parent reply	other threads:[~2020-05-12 14:15 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-10  8:26 [PATCH] submodule--helper.c: add only-active to foreach Guillaume G. via GitGitGadget
2020-05-10 16:44 ` Shourya Shukla
2020-05-10 21:51   ` Guillaume Galeazzi
2020-05-10 22:42     ` Eric Sunshine
2020-05-15 16:29       ` Guillaume Galeazzi
2020-05-12 14:15     ` Shourya Shukla [this message]
2020-05-15 16:51       ` Guillaume Galeazzi
2020-05-15 17:03         ` Junio C Hamano
2020-05-15 18:53           ` Guillaume Galeazzi
2020-05-12 18:53 ` Junio C Hamano
2020-05-13  5:17   ` Guillaume Galeazzi
2020-05-13 15:35     ` Junio C Hamano
2020-05-13 20:07       ` Guillaume Galeazzi
2020-05-13 20:35         ` Junio C Hamano
2020-05-15 11:04           ` Guillaume Galeazzi
2020-05-17  6:30 ` [PATCH v2 0/3] " Guillaume G. via GitGitGadget
2020-05-17  6:30   ` [PATCH v2 1/3] submodule--helper.c: add active " Guillaume Galeazzi via GitGitGadget
2020-05-17  6:30   ` [PATCH v2 2/3] submodule--helper.c: add populated " Guillaume Galeazzi via GitGitGadget
2020-05-17  6:30   ` [PATCH v2 3/3] submodule--helper.c: add branch " Guillaume Galeazzi via GitGitGadget
2020-05-17 15:46   ` [PATCH v2 0/3] submodule--helper.c: add only-active " Junio C Hamano
2020-05-17 19:47     ` Guillaume Galeazzi
2020-08-18 15:57     ` Guillaume Galeazzi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200512141520.GA8133@konoha \
    --to=shouryashukla.oo@gmail.com \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=guillaume.galeazzi@gmail.com \
    --cc=liu.denton@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.