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

Re: [PATCH] ls-files: conditionally leave index sparse

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 26, 2025, 19:00 UTC
Message-ID
<xmqqh5xtkiwt.fsf@gitster.g>
In-Reply-To
<pull.1955.git.1755274373717.gitgitgadget@gmail.com>
"Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 11 quoted lines
>  	for (i = 0; i < repo->index->cache_nr; i++) {
>  		const struct cache_entry *ce = repo->index->cache[i];
>  		struct stat st;
>  		int stat_err;
>  
> +		if (S_ISSPARSEDIR(ce->ce_mode) && !show_sparse_dirs) {
> +			/*
> +			 * This is the first time we've hit a sparse dir,
> +			 * so expansion will leave the first 'i' entries
> +			 * alone.
> +			 */
In other words,
 (1) we know that the original index entries are sorted
 (2) we are looking at a single directory entry that is sparse, say
     "D/", and ensure_full_index() will expand it (and other later
     entries in the current index).
 (3) we assume that the contents of "D/" will never sort before the
     original location where "D/" used to sit, iow, we do not have
     to rewind to the beginning of index->cache[] array and skip
     what we have already processed.

Having bitten by the index sort order number of times, I just wanted to make sure everybody's assumption is on the same page.

> +			ensure_full_index(repo->index);
> +			ce = repo->index->cache[i];

and there is no need to say "again" (redo this round of the loop) here, as grabbing ce was the only thing the loop did, and we just replaced the entry for the originally folded "D/" with one for the first subpath in "D/". Sounds sensible.

Previous: Elijah Newren
Message 6 of 6 in “ls-files: conditionally leave index sparse”
  1. ls-files: conditionally leave index sparseDerrick Stolee via GitGitGadget, Aug 15, 2025
  2. Derrick StoleeAug 26, 2025
  3. Derrick StoleeAug 27, 2025
  4. Junio C HamanoAug 28, 2025
  5. Elijah NewrenAug 26, 2025
  6. Junio C HamanoAug 26, 2025

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.