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

Re: [GSoC] [PATCH v3] submodule--helper: introduce add-config subcommand

From
Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Date
Aug 5, 2021, 18:25 UTC
Message-ID
<1013ed94-ad4f-6ec8-09fb-772edea4ea05@gmail.com>
In-Reply-To
<20210801063352.50813-1-raykar.ath@gmail.com>
On 01/08/21 12:03 pm, Atharva Raykar wrote:
Show 20 quoted lines
> Add a new "add-config" subcommand to `git submodule--helper` with the
> goal of converting part of the shell code in git-submodule.sh related to
> `git submodule add` into C code. This new subcommand sets the
> configuration variables of a newly added submodule, by registering the
> url in local git config, as well as the submodule name and path in the
> .gitmodules file. It also sets 'submodule.<name>.active' to "true" if
> the submodule path has not already been covered by any pathspec
> specified in 'submodule.active'.
> 
> This is meant to be a faithful conversion from shell to C, although we
> add comments to areas that could be improved in future patches, after
> the conversion has settled.
> 
> Signed-off-by: Atharva Raykar <raykar.ath@gmail.com>
> Mentored-by: Christian Couder <christian.couder@gmail.com>
> Mentored-by: Shourya Shukla <periperidip@gmail.com>
> Based-on-patch-by: Shourya Shukla <periperidip@gmail.com>
> Based-on-patch-by: Prathamesh Chavan <pc44800@gmail.com>
> ---
>
The v3 mostly looks good to me. Just one style nit:
Show 32 quoted lines
> [ ... ]
>
> +static void configure_added_submodule(struct add_data *add_data)
> +{
> +	char *key;
> +	char *val = NULL;
> +	struct child_process add_submod = CHILD_PROCESS_INIT;
> +	struct child_process add_gitmodules = CHILD_PROCESS_INIT;
> +
> +	key = xstrfmt("submodule.%s.url", add_data->sm_name);
> +	git_config_set_gently(key, add_data->realrepo);
> +	free(key);
> +
> +	add_submod.git_cmd = 1;
> +	strvec_pushl(&add_submod.args, "add",
> +		     "--no-warn-embedded-repo", NULL);
> +	if (add_data->force)
> +		strvec_push(&add_submod.args, "--force");
> +	strvec_pushl(&add_submod.args, "--", add_data->sm_path, NULL);
> +
> +	if (run_command(&add_submod))
> +		die(_("Failed to add submodule '%s'"), add_data->sm_path);
> +
> +	if (config_submodule_in_gitmodules(add_data->sm_name, "path", add_data->sm_path) ||
> +	    config_submodule_in_gitmodules(add_data->sm_name, "url", add_data->repo))
> +		die(_("Failed to register submodule '%s'"), add_data->sm_path);
> +
> +	if (add_data->branch)
> +		if (config_submodule_in_gitmodules(add_data->sm_name,
> +						   "branch", add_data->branch))
> +			die(_("Failed to register submodule '%s'"), add_data->sm_path);
> +

As the body of if(add->branch) has a nested if in it and totally spans 3 lines, it might be a good idea to wrap it in braces like so:

         if (add_data->branch) {
                 if (config_submodule_in_gitmodules(add_data->sm_name,
                                                    "branch", add_data->branch))
                         die(_("Failed to register submodule '%s'"), add_data->sm_path);
         }
... or collapse both conditionals into a single if like so:
         if (add_data->branch &&
             config_submodule_in_gitmodules(add_data->sm_name, "branch", add_data->branch))
                 die(_("Failed to register submodule '%s'"), add_data->sm_path);
-- 
Sivaraam
Previous: Atharva RaykarNext: Kaartic Sivaraam
Message 11 of 13 in “submodule--helper: introduce add-config subcommand”
  1. Atharva RaykarJul 22, 2021
  2. Atharva RaykarJul 22, 2021
  3. Ævar Arnfjörð BjarmasonJul 22, 2021
  4. Atharva RaykarJul 22, 2021
  5. Atharva RaykarJul 22, 2021
  6. Junio C HamanoJul 23, 2021
  7. Atharva RaykarJul 24, 2021
  8. [GSoC] [PATCH v2] submodule--helper: introduce add-config subcommandAtharva Raykar, Jul 28, 2021
  9. Kaartic SivaraamJul 28, 2021
  10. [GSoC] [PATCH v3] submodule--helper: introduce add-config subcommandAtharva Raykar, Aug 1, 2021
  11. Kaartic SivaraamAug 5, 2021
  12. Kaartic SivaraamJul 29, 2021
  13. Atharva RaykarJul 30, 2021

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.