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

Re: [PATCH v3 1/3] index-pack --promisor: dedup before checking links

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 4, 2024, 04:36 UTC
Message-ID
<xmqqy10w3w0a.fsf@gitster.g>
In-Reply-To
<7ae21c921fe367d4b15cd4a299196009c15205d9.1733262662.git.jonathantanmy@google.com>
Jonathan Tan <jonathantanmy@google.com> writes:
> @@ -1781,26 +1775,41 @@ static void repack_local_links(void)
>  	struct object_id *oid;
>  	char *base_name;

We may want to give a meaningless NULL initialization to this variable, due to false positive from a compliler.

Show 5 quoted lines
> -	if (!oidset_size(&local_links))
> +	if (!oidset_size(&outgoing_links))
>  		return;
>  
> -	base_name = mkpathdup("%s/pack/pack", repo_get_object_directory(the_repository));

It used to be that it was really obvious that base_name is always initialized. But now due to micro-optimization ...

Show 13 quoted lines
> +	oidset_iter_init(&outgoing_links, &iter);
> +	while ((oid = oidset_iter_next(&iter))) {
> +		struct object_info info = OBJECT_INFO_INIT;
> +		if (oid_object_info_extended(the_repository, oid, &info, 0))
> +			/* Missing; assume it is a promisor object */
> +			continue;
> +		if (info.whence == OI_PACKED && info.u.packed.pack->pack_promisor)
> +			continue;
> ...
> +		if (!cmd.args.nr) {
> +			base_name = mkpathdup(
> +				"%s/pack/pack",
> +				repo_get_object_directory(the_repository));
... we lazily allocate only after we know we will run a command.
Show 10 quoted lines
> +			strvec_push(&cmd.args, "pack-objects");
> +			strvec_push(&cmd.args,
> +				    "--exclude-promisor-objects-best-effort");
> +			strvec_push(&cmd.args, base_name);
> +			cmd.git_cmd = 1;
> +			cmd.in = -1;
> +			cmd.out = -1;
> +			if (start_command(&cmd))
> +				die(_("could not start pack-objects to repack local links"));
> +		}

We know outgoing_links is not empty, so we know we will enter the while() loop at least once, but it may be possible that all the objects in the outgoing_links oidset end up to be missing or packed in a promisor pack, hitting continue and never running the command.

Show 9 quoted lines
> -	oidset_iter_init(&local_links, &iter);
> -	while ((oid = oidset_iter_next(&iter))) {
>  		if (write_in_full(cmd.in, oid_to_hex(oid), the_hash_algo->hexsz) < 0 ||
>  		    write_in_full(cmd.in, "\n", 1) < 0)
>  			die(_("failed to feed local object to pack-objects"));
>  	}
> +
> +	if (!cmd.args.nr)
> +		return;

But then we have this early return, so from human-reader's point of view, we will never hit free(base_name) at the end of this function.

But GCC used in the macOS build does not seem to realize it.
https://github.com/git/git/actions/runs/12152173257/job/33888089229#step:4:380

It may be safer to give a meaningless NULL as the initial value of the variable.

Thanks.
Previous: Jonathan TanNext: Jonathan Tan
Message 25 of 29 in “Performance improvements for repacking non-promisor objects”
  1. 0/3 Performance improvements for repacking non-promisor objectsJonathan Tan, Dec 2, 2024
  2. 1/3 index-pack: dedup first during outgoing link checkJonathan Tan, Dec 2, 2024
  3. Josh SteadmonDec 2, 2024
  4. 2/3 index-pack: no blobs during outgoing link checkJonathan Tan, Dec 2, 2024
  5. Patrick SteinhardtDec 3, 2024
  6. Jonathan TanDec 3, 2024
  7. Junio C HamanoDec 3, 2024
  8. 3/3 index-pack: commit tree during outgoing link checkJonathan Tan, Dec 2, 2024
  9. Junio C HamanoDec 3, 2024
  10. Jonathan TanDec 3, 2024
  11. Junio C HamanoDec 4, 2024
  12. Jonathan TanDec 9, 2024
  13. Junio C HamanoDec 9, 2024
  14. Josh SteadmonDec 2, 2024
  15. Junio C HamanoDec 3, 2024
  16. Junio C HamanoDec 3, 2024
  17. Junio C HamanoDec 3, 2024
  18. Junio C HamanoDec 3, 2024
  19. 0/3 Performance improvements for repacking non-promisor objectsJonathan Tan, Dec 3, 2024
  20. 1/3 index-pack --promisor: dedup before checking linksJonathan Tan, Dec 3, 2024
  21. 2/3 index-pack --promisor: don't check blobsJonathan Tan, Dec 3, 2024
  22. 3/3 index-pack --promisor: also check commits' treesJonathan Tan, Dec 3, 2024
  23. 0/3 Performance improvements for repacking non-promisor objectsJonathan Tan, Dec 3, 2024
  24. 1/3 index-pack --promisor: dedup before checking linksJonathan Tan, Dec 3, 2024
  25. Junio C HamanoDec 4, 2024
  26. 2/3 index-pack --promisor: don't check blobsJonathan Tan, Dec 3, 2024
  27. 3/3 index-pack --promisor: also check commits' treesJonathan Tan, Dec 3, 2024
  28. Junio C HamanoDec 4, 2024
  29. 4/3 index-pack: work around false positive use of uninitialized variableJunio C Hamano, Dec 4, 2024

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.