Re: [PATCH 2/2] restore: avoid sparse index expansion
- From
Derrick Stolee <stolee@gmail.com>
- Date
- May 26, 2026, 02:54 UTC
- Message-ID
- <7b8d12c0-21bc-4bc1-9e0e-81fbd4b3a2bd@gmail.com>
- In-Reply-To
- <xmqqtsrwh0hx.fsf@gitster.g>
On 5/24/26 7:05 PM, Junio C Hamano wrote:
> "Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 49 quoted lines
>> - if (S_ISDIR(mode))
>> + if (S_ISDIR(mode)) {
>> + /*
>> + * If this directory exists as a sparse directory entry in
>> + * the index, we can handle it at the tree level without
>> + * descending into individual files.
>> + */
>> + if (the_repository->index->sparse_index) {
>
> I wonder if this deep nesting is a sign that the newly added code
> from here to ...
>
>> + struct strbuf dirpath = STRBUF_INIT;
>> +
>> + strbuf_addbuf(&dirpath, base);
>> + strbuf_addstr(&dirpath, pathname);
>> + strbuf_addch(&dirpath, '/');
>> +
>> + pos = index_name_pos_sparse(the_repository->index,
>> + dirpath.buf, dirpath.len);
>> + if (pos >= 0) {
>> + struct cache_entry *old =
>> + the_repository->index->cache[pos];
>> + if (S_ISSPARSEDIR(old->ce_mode)) {
>> + if (oideq(oid, &old->oid)) {
>> + strbuf_release(&dirpath);
>> + return 0;
>> + }
>> + if (!overlay_mode) {
>> + /*
>> + * In non-overlay mode (e.g.,
>> + * restore --staged), we can
>> + * replace the sparse dir OID
>> + * directly since files not in
>> + * the source tree should be
>> + * removed anyway.
>> + */
>> + oidcpy(&old->oid, oid);
>> + old->ce_flags |= CE_UPDATE;
>> + strbuf_release(&dirpath);
>> + return 0;
>> + }
>> + }
>> + }
>> + strbuf_release(&dirpath);
>> + }
>
> ... here may become easier to understand if it is made into a small
> helper function with a descriptive name.Good idea. I'll try that and send a v2.
Thanks, -Stolee