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

Re: [PATCH v1 1/2] submodule: port submodule subcommand 'sync' from shell to C

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 9, 2018, 20:57 UTC
Message-ID
<xmqqpo6i4uns.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20180109175703.4793-2-pc44800@gmail.com>
Prathamesh Chavan <pc44800@gmail.com> writes:
Show 13 quoted lines
> +static int print_default_remote(int argc, const char **argv, const char *prefix)
> +{
> +	const char *remote;
> +
> +	if (argc != 1)
> +		die(_("submodule--helper print-default-remote takes no arguments"));
> +
> +	remote = get_default_remote();
> +	if (remote)
> +		printf("%s\n", remote);
> +
> +	return 0;
> +}

This is called directly from main and return immediately after printing, so a small leak of remote does not matter, I guess.

Show 17 quoted lines
> +static void sync_submodule(const char *path, const char *prefix,
> +			   unsigned int flags)
> +{
> +	const struct submodule *sub;
> +	char *remote_key = NULL;
> +	char *sub_origin_url, *super_config_url, *displaypath;
> +	struct strbuf sb = STRBUF_INIT;
> +	struct child_process cp = CHILD_PROCESS_INIT;
> +	char *sub_config_path = NULL;
> +
> +	if (!is_submodule_active(the_repository, path))
> +		return;
> +
> +	sub = submodule_from_path(&null_oid, path);
> +
> +	if (sub && sub->url) {
> +		if (starts_with_dot_dot_slash(sub->url) || starts_with_dot_slash(sub->url)) {

Not a big deal, but other codepaths seem to fold this pattern into two lines, i.e.

		if (starts_with_dot_dot_slash(sub->url) ||
		    starts_with_dot_slash(sub->url)) {
> +			sub_origin_url = relative_url(remote_url, sub->url, up_path);
> +			super_config_url = relative_url(remote_url, sub->url, NULL);
On this side, these two are allocated memory that need to be freed.
> +		} else {
> +			sub_origin_url = xstrdup(sub->url);
> +			super_config_url = xstrdup(sub->url);
This side as well.
> +		}
> +	} else {
> +		sub_origin_url = "";
> +		super_config_url = "";

But not these. You have free() of these two at the end of this function, which will break things.

Previous: Prathamesh ChavanNext: Prathamesh Chavan
Message 3 of 19 in “Incremental rewrite of git-submodules”
  1. 0/2 Incremental rewrite of git-submodulesPrathamesh Chavan, Jan 9, 2018
  2. 1/2 submodule: port submodule subcommand 'sync' from shell to CPrathamesh Chavan, Jan 9, 2018
  3. Junio C HamanoJan 9, 2018
  4. 2/2 submodule: port submodule subcommand 'deinit' from shell to CPrathamesh Chavan, Jan 9, 2018
  5. Junio C HamanoJan 9, 2018
  6. Prathamesh ChavanJan 10, 2018
  7. Junio C HamanoJan 10, 2018
  8. Stefan BellerJan 9, 2018
  9. Brandon WilliamsJan 9, 2018
  10. 0/2 Incremental rewrite of git-submodulesPrathamesh Chavan, Jan 11, 2018
  11. 2/2 submodule: port submodule subcommand 'deinit' from shell to CPrathamesh Chavan, Jan 11, 2018
  12. Junio C HamanoJan 11, 2018
  13. 1/2 submodule: port submodule subcommand 'sync' from shell to CPrathamesh Chavan, Jan 11, 2018
  14. Junio C HamanoJan 11, 2018
  15. Junio C HamanoJan 11, 2018
  16. 0/2 Incremental rewrite of git-submodulesPrathamesh Chavan, Jan 14, 2018
  17. 1/2 submodule: port submodule subcommand 'sync' from shell to CPrathamesh Chavan, Jan 14, 2018
  18. 2/2 submodule: port submodule subcommand 'deinit' from shell to CPrathamesh Chavan, Jan 14, 2018
  19. Junio C HamanoJan 16, 2018

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.