public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Derrick Stolee <stolee@gmail•com>
To: Junio C Hamano <gitster@pobox•com>,
	Derrick Stolee via GitGitGadget <gitgitgadget@gmail•com>
Cc: git@vger•kernel.org
Subject: Re: [PATCH 2/2] restore: avoid sparse index expansion
Date: Mon, 25 May 2026 22:54:49 -0400	[thread overview]
Message-ID: <7b8d12c0-21bc-4bc1-9e0e-81fbd4b3a2bd@gmail.com> (raw)
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:


>> -	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


  reply	other threads:[~2026-05-26  2:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-24 17:40 [PATCH 0/2] restore: better integrate with sparse index Derrick Stolee via GitGitGadget
2026-05-24 17:40 ` [PATCH 1/2] t1092: test 'git restore' " Derrick Stolee via GitGitGadget
2026-05-24 22:51   ` Junio C Hamano
2026-05-24 17:40 ` [PATCH 2/2] restore: avoid sparse index expansion Derrick Stolee via GitGitGadget
2026-05-24 23:05   ` Junio C Hamano
2026-05-26  2:54     ` Derrick Stolee [this message]
2026-05-26 20:26 ` [PATCH v2 0/2] restore: better integrate with sparse index Derrick Stolee via GitGitGadget
2026-05-26 20:26   ` [PATCH v2 1/2] t1092: test 'git restore' " Derrick Stolee via GitGitGadget
2026-05-26 20:26   ` [PATCH v2 2/2] restore: avoid sparse index expansion Derrick Stolee via GitGitGadget

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=7b8d12c0-21bc-4bc1-9e0e-81fbd4b3a2bd@gmail.com \
    --to=stolee@gmail$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=gitgitgadget@gmail$(echo .)com \
    --cc=gitster@pobox$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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