From: Derrick Stolee Date: Tue, 26 May 2026 02:54:49 GMT Subject: Re: [PATCH 2/2] restore: avoid sparse index expansion Message-ID: <7b8d12c0-21bc-4bc1-9e0e-81fbd4b3a2bd@gmail.com> In-Reply-To: On 5/24/26 7:05 PM, Junio C Hamano wrote: > "Derrick Stolee via GitGitGadget" writes: >> - 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