git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Eric Sunshine <sunshine@sunshineco.com>
To: Prathamesh Chavan <pc44800@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>,
	Christian Couder <christian.couder@gmail.com>,
	Git List <git@vger.kernel.org>,
	hanwen@google.com, Stefan Beller <sbeller@google.com>
Subject: Re: [PATCH v7 2/3] submodule--helper: introduce for_each_listed_submodule()
Date: Fri, 6 Oct 2017 17:56:04 -0400	[thread overview]
Message-ID: <CAPig+cT31XM9nW7sytukbQQ_O_15np6oepazKJaoNuHey+kiBA@mail.gmail.com> (raw)
In-Reply-To: <20171006132415.2876-3-pc44800@gmail.com>

Same disclaimer as in my review of patch 1/3: I didn't see a URL in
the cover letter pointing at discussions of earlier iterations, so
below comments may be at odds with what went on previously...

On Fri, Oct 6, 2017 at 9:24 AM, Prathamesh Chavan <pc44800@gmail.com> wrote:
> Introduce function for_each_listed_submodule() and replace a loop
> in module_init() with a call to it.
>
> The new function will also be used in other parts of the
> system in later patches.
>
> Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
> ---
> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> @@ -14,6 +14,11 @@
>  #include "refs.h"
>  #include "connect.h"
>
> +#define OPT_QUIET (1 << 0)
> +
> +typedef void (*each_submodule_fn)(const struct cache_entry *list_item,
> +                                 void *cb_data);

What is the reason for having the definition of 'each_submodule_fn' so
far removed textually from its first reference by
for_each_listed_submodule() below?

>  static char *get_default_remote(void)
>  {
>         char *dest = NULL, *ret;
> @@ -348,7 +353,23 @@ static int module_list(int argc, const char **argv, const char *prefix)
>         return 0;
>  }
>
> -static void init_submodule(const char *path, const char *prefix, int quiet)
> +static void for_each_listed_submodule(const struct module_list *list,
> +                                     each_submodule_fn fn, void *cb_data)
> +{
> +       int i;
> +       for (i = 0; i < list->nr; i++)
> +               fn(list->entries[i], cb_data);
> +}

I'm very curious about the justification for introducing a for-each
function for what amounts to the simplest sort of loop possible: a
canonical for-loop with a one-line body. I could easily understand the
desire for such a function if either the loop conditions or the body
of the loop, or both, were complex, but this does not seem to be the
case. Even the callers of this new function, in this patch and in 3/3,
are as simple as possible: one-liners (simple function calls).

Although this sort of for-each function can, at times, be helpful,
there are costs: extra boilerplate and increased complexity for
clients since it requires callback functions and (optionally) callback
data. The separation of logic into a callback function can make code
more difficult to reason about than when it is simply the body of a
for-loop.

So, unless the plan for the future is that this for-each function will
have considerable additional functionality baked into it, I'm having a
difficult time understanding why this change is desirable.

> +struct init_cb {
> +       const char *prefix;
> +       unsigned int flags;
> +};
> +
> +#define INIT_CB_INIT { NULL, 0 }

Why are these definitions so far removed from init_submodule_cb() below?

> +static void init_submodule(const char *path, const char *prefix,
> +                          unsigned int flags)
>  {
>         const struct submodule *sub;
>         struct strbuf sb = STRBUF_INIT;
> @@ -410,7 +431,7 @@ static void init_submodule(const char *path, const char *prefix, int quiet)
>                 if (git_config_set_gently(sb.buf, url))
>                         die(_("Failed to register url for submodule path '%s'"),
>                             displaypath);
> -               if (!quiet)
> +               if (!(flags & OPT_QUIET))

This change of having init_submodule() accept a 'flags' argument,
rather than a single boolean, increases reviewer burden, since the
reviewer is forced to puzzle out how this change relates to the stated
intention of the patch since it is not mentioned at all by the commit
message.

It's also conceptually unrelated to the introduction of a for-each
function, thus should be instead be done by a separate preparatory
patch.

>                         fprintf(stderr,
>                                 _("Submodule '%s' (%s) registered for path '%s'\n"),
>                                 sub->name, url, displaypath);
> @@ -437,12 +458,18 @@ static void init_submodule(const char *path, const char *prefix, int quiet)
>         free(upd);
>  }
>
> +static void init_submodule_cb(const struct cache_entry *list_item, void *cb_data)
> +{
> +       struct init_cb *info = cb_data;
> +       init_submodule(list_item->name, info->prefix, info->flags);
> +}
> +
>  static int module_init(int argc, const char **argv, const char *prefix)
>  {
> +       struct init_cb info = INIT_CB_INIT;
>         struct pathspec pathspec;
>         struct module_list list = MODULE_LIST_INIT;
>         int quiet = 0;
> -       int i;
>
>         struct option module_init_options[] = {
>                 OPT__QUIET(&quiet, N_("Suppress output for initializing a submodule")),
> @@ -467,8 +494,11 @@ static int module_init(int argc, const char **argv, const char *prefix)
>         if (!argc && git_config_get_value_multi("submodule.active"))
>                 module_list_active(&list);
>
> -       for (i = 0; i < list.nr; i++)
> -               init_submodule(list.entries[i]->name, prefix, quiet);
> +       info.prefix = prefix;
> +       if (quiet)
> +               info.flags |= OPT_QUIET;
> +
> +       for_each_listed_submodule(&list, init_submodule_cb, &info);
>
>         return 0;
>  }
> --
> 2.14.2

  reply	other threads:[~2017-10-06 21:56 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-21 16:15 [GSoC][PATCH 1/4] submodule--helper: introduce get_submodule_displaypath() Prathamesh Chavan
2017-08-21 16:15 ` [GSoC][PATCH 2/4] submodule--helper: introduce for_each_submodule_list() Prathamesh Chavan
2017-08-22 22:37   ` Junio C Hamano
2017-08-21 16:15 ` [GSoC][PATCH 3/4] submodule: port set_name_rev() from shell to C Prathamesh Chavan
2017-08-21 16:47   ` Heiko Voigt
2017-08-21 17:24     ` Prathamesh Chavan
2017-08-21 16:15 ` [GSoC][PATCH 4/4] submodule: port submodule subcommand 'status' " Prathamesh Chavan
2017-08-22 22:29 ` [GSoC][PATCH 1/4] submodule--helper: introduce get_submodule_displaypath() Junio C Hamano
2017-08-23 18:15   ` [GSoC][PATCH v2 0/4] submodule: Incremental rewrite of git-submodules Prathamesh Chavan
2017-08-23 18:15     ` [GSoC][PATCH v2 1/4] submodule--helper: introduce get_submodule_displaypath() Prathamesh Chavan
2017-08-23 18:15     ` [GSoC][PATCH v2 2/4] submodule--helper: introduce for_each_submodule() Prathamesh Chavan
2017-08-23 19:13       ` Junio C Hamano
2017-08-23 19:31         ` Stefan Beller
2017-08-23 19:52           ` Junio C Hamano
2017-08-24 19:50             ` [GSoC][PATCH v3 0/4] Incremental rewrite of git-submodules Prathamesh Chavan
2017-08-24 19:50               ` [GSoC][PATCH v3 1/4] submodule--helper: introduce get_submodule_displaypath() Prathamesh Chavan
2017-08-24 19:50               ` [GSoC][PATCH v3 2/4] submodule--helper: introduce for_each_listed_submodule() Prathamesh Chavan
2017-08-24 19:50               ` [GSoC][PATCH v3 3/4] submodule: port set_name_rev() from shell to C Prathamesh Chavan
2017-08-24 19:50               ` [GSoC][PATCH v3 4/4] submodule: port submodule subcommand 'status' " Prathamesh Chavan
2017-08-25 18:51               ` [GSoC][PATCH v3 0/4] Incremental rewrite of git-submodules Junio C Hamano
2017-08-25 19:15                 ` Stefan Beller
2017-08-25 20:32                   ` Junio C Hamano
2017-08-27 11:50                 ` Prathamesh Chavan
2017-08-28 11:55                 ` [GSoC][PATCH v4 " Prathamesh Chavan
2017-08-28 11:55                   ` [GSoC][PATCH v4 1/4] submodule--helper: introduce get_submodule_displaypath() Prathamesh Chavan
2017-09-21 15:06                     ` Han-Wen Nienhuys
2017-08-28 11:55                   ` [GSoC][PATCH v4 2/4] submodule--helper: introduce for_each_listed_submodule() Prathamesh Chavan
2017-08-28 11:55                   ` [GSoC][PATCH v4 3/4] submodule: port set_name_rev() from shell to C Prathamesh Chavan
2017-09-21 15:31                     ` Han-Wen Nienhuys
2017-08-28 11:55                   ` [GSoC][PATCH v4 4/4] submodule: port submodule subcommand 'status' " Prathamesh Chavan
2017-09-21 16:10                     ` Han-Wen Nienhuys
2017-09-24 12:08                       ` [PATCH v5 0/4] Incremental rewrite of git-submodules Prathamesh Chavan
2017-09-24 12:08                         ` [PATCH v5 1/4] submodule--helper: introduce get_submodule_displaypath() Prathamesh Chavan
2017-09-25  3:35                           ` Junio C Hamano
2017-09-24 12:08                         ` [PATCH v5 2/4] submodule--helper: introduce for_each_listed_submodule() Prathamesh Chavan
2017-09-25  3:43                           ` Junio C Hamano
2017-09-24 12:08                         ` [PATCH v5 3/4] submodule: port set_name_rev() from shell to C Prathamesh Chavan
2017-09-25  3:51                           ` Junio C Hamano
2017-09-25  3:55                             ` Junio C Hamano
2017-09-24 12:08                         ` [PATCH v5 4/4] submodule: port submodule subcommand 'status' " Prathamesh Chavan
2017-09-25  5:06                           ` Junio C Hamano
2017-09-29  9:44                             ` [PATCH v6 0/3] Incremental rewrite of git-submodules Prathamesh Chavan
2017-09-29  9:44                               ` [PATCH v6 1/3] submodule--helper: introduce get_submodule_displaypath() Prathamesh Chavan
2017-10-02  0:44                                 ` Junio C Hamano
2017-09-29  9:44                               ` [PATCH v6 2/3] submodule--helper: introduce for_each_listed_submodule() Prathamesh Chavan
2017-10-02  0:55                                 ` Junio C Hamano
2017-09-29  9:44                               ` [PATCH v6 3/3] submodule: port submodule subcommand 'status' from shell to C Prathamesh Chavan
2017-10-02  1:08                                 ` Junio C Hamano
2017-10-06 13:24                                   ` [PATCH v7 0/3] Incremental rewrite of git-submodules Prathamesh Chavan
2017-10-06 13:24                                     ` [PATCH v7 1/3] submodule--helper: introduce get_submodule_displaypath() Prathamesh Chavan
2017-10-06 21:12                                       ` Eric Sunshine
2017-10-06 13:24                                     ` [PATCH v7 2/3] submodule--helper: introduce for_each_listed_submodule() Prathamesh Chavan
2017-10-06 21:56                                       ` Eric Sunshine [this message]
2017-10-06 13:24                                     ` [PATCH v7 3/3] submodule: port submodule subcommand 'status' from shell to C Prathamesh Chavan
2017-10-07  8:51                                     ` [PATCH v7 0/3] Incremental rewrite of git-submodules Junio C Hamano
2017-10-07  9:35                                       ` Eric Sunshine
2017-10-02  0:39                               ` [PATCH v6 " Junio C Hamano
2017-08-23 18:15     ` [GSoC][PATCH v2 3/4] submodule: port set_name_rev() from shell to C Prathamesh Chavan
2017-08-23 18:15     ` [GSoC][PATCH v2 4/4] submodule: port submodule subcommand 'status' " Prathamesh Chavan

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=CAPig+cT31XM9nW7sytukbQQ_O_15np6oepazKJaoNuHey+kiBA@mail.gmail.com \
    --to=sunshine@sunshineco.com \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=hanwen@google.com \
    --cc=pc44800@gmail.com \
    --cc=sbeller@google.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).