From: Junio C Hamano <gitster@pobox.com>
To: Jonathan Tan <jonathantanmy@google.com>
Cc: git@vger.kernel.org, ps@pks.im
Subject: Re: [PATCH v3 1/3] index-pack --promisor: dedup before checking links
Date: Wed, 04 Dec 2024 13:36:05 +0900 [thread overview]
Message-ID: <xmqqy10w3w0a.fsf@gitster.g> (raw)
In-Reply-To: <7ae21c921fe367d4b15cd4a299196009c15205d9.1733262662.git.jonathantanmy@google.com> (Jonathan Tan's message of "Tue, 3 Dec 2024 13:52:54 -0800")
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.
> - 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 ...
> + 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.
> + 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.
> - 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.
next prev parent reply other threads:[~2024-12-04 4:36 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-02 20:18 [PATCH 0/3] Performance improvements for repacking non-promisor objects Jonathan Tan
2024-12-02 20:18 ` [PATCH 1/3] index-pack: dedup first during outgoing link check Jonathan Tan
2024-12-02 21:24 ` Josh Steadmon
2024-12-02 20:18 ` [PATCH 2/3] index-pack: no blobs " Jonathan Tan
2024-12-03 6:00 ` Patrick Steinhardt
2024-12-03 21:40 ` Jonathan Tan
2024-12-03 22:16 ` Junio C Hamano
2024-12-02 20:18 ` [PATCH 3/3] index-pack: commit tree " Jonathan Tan
2024-12-03 3:10 ` Junio C Hamano
2024-12-03 21:42 ` Jonathan Tan
2024-12-04 0:21 ` Junio C Hamano
2024-12-09 20:29 ` Jonathan Tan
2024-12-09 23:51 ` Junio C Hamano
2024-12-02 21:25 ` [PATCH 0/3] Performance improvements for repacking non-promisor objects Josh Steadmon
2024-12-03 4:09 ` Junio C Hamano
2024-12-03 4:18 ` Junio C Hamano
2024-12-03 4:20 ` Junio C Hamano
2024-12-03 4:39 ` Junio C Hamano
2024-12-03 21:43 ` [PATCH v2 " Jonathan Tan
2024-12-03 21:43 ` [PATCH v2 1/3] index-pack --promisor: dedup before checking links Jonathan Tan
2024-12-03 21:43 ` [PATCH v2 2/3] index-pack --promisor: don't check blobs Jonathan Tan
2024-12-03 21:43 ` [PATCH v2 3/3] index-pack --promisor: also check commits' trees Jonathan Tan
2024-12-03 21:52 ` [PATCH v3 0/3] Performance improvements for repacking non-promisor objects Jonathan Tan
2024-12-03 21:52 ` [PATCH v3 1/3] index-pack --promisor: dedup before checking links Jonathan Tan
2024-12-04 4:36 ` Junio C Hamano [this message]
2024-12-03 21:52 ` [PATCH v3 2/3] index-pack --promisor: don't check blobs Jonathan Tan
2024-12-03 21:52 ` [PATCH v3 3/3] index-pack --promisor: also check commits' trees Jonathan Tan
2024-12-04 2:22 ` [PATCH v3 0/3] Performance improvements for repacking non-promisor objects Junio C Hamano
2024-12-04 4:46 ` [PATCH 4/3] index-pack: work around false positive use of uninitialized variable Junio C Hamano
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqy10w3w0a.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=jonathantanmy@google.com \
--cc=ps@pks.im \
/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.
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 NNTP newsgroup(s).