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

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

Previous: Junio C HamanoNext: Derrick Stolee via GitGitGadget
Message 6 of 9 in “restore: better integrate with sparse index”
  1. 0/2 restore: better integrate with sparse indexDerrick Stolee via GitGitGadget, May 24, 2026
  2. 1/2 t1092: test 'git restore' with sparse indexDerrick Stolee via GitGitGadget, May 24, 2026
  3. Junio C HamanoMay 24, 2026
  4. 2/2 restore: avoid sparse index expansionDerrick Stolee via GitGitGadget, May 24, 2026
  5. Junio C HamanoMay 24, 2026
  6. Derrick StoleeMay 26, 2026
  7. 0/2 restore: better integrate with sparse indexDerrick Stolee via GitGitGadget, May 26, 2026
  8. 1/2 t1092: test 'git restore' with sparse indexDerrick Stolee via GitGitGadget, May 26, 2026
  9. 2/2 restore: avoid sparse index expansionDerrick Stolee via GitGitGadget, May 26, 2026

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.