git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Guillaume Galeazzi <guillaume.galeazzi@gmail.com>
To: Shourya Shukla <shouryashukla.oo@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: Fri, 15 May 2020 18:51:57 +0200	[thread overview]
Message-ID: <b45268b1-de5f-051c-f956-8a17c067f4c6@gmail.com> (raw)
In-Reply-To: <20200512141520.GA8133@konoha>

Le 12.05.2020 à 16:15, Shourya Shukla a écrit :
> On 10/05 11:51, Guillaume Galeazzi wrote:
> 
> 
>> 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?

After a cross check, yes it is the correct place to initialise the new 
active_only member of foreach_cb. But it will be changed to use 
designated initializers.

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

Yes it is okay, a `#define SOMETHING WHATEVER` will just inform the c 
preprocessor to replace the `SOMETHING` by `WHATEVER`. The only thing 
the final c compiler will see is `WHATEVER`. In our case a integer value.

Goal here was to avoid magic number, but after looking to the code it 
seem accepted that true is 1 and false is 0. To comply with that, in 
next version it will be replace it with:

	if (FOREACH_BOOL_FILTER_NOT_SET != info->active_only) {
		is_active = is_submodule_active(the_repository, path);
		if (is_active != info->active_only)
			return;
	}

> 
>> 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
As suggested on other mail of this patch, it will be removed and take 
the shortcut `--no-active`.

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

The change on `FOREACH_CB_INIT` are to keep original behaviour of the 
command if new flags are not given.

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

The code to parse command T/F will be removed.

Regards,

Guillaume

  reply	other threads:[~2020-05-15 16:52 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
2020-05-15 16:51       ` Guillaume Galeazzi [this message]
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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=b45268b1-de5f-051c-f956-8a17c067f4c6@gmail.com \
    --to=guillaume.galeazzi@gmail.com \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=liu.denton@gmail.com \
    --cc=shouryashukla.oo@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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).