diff mbox series

[v4,07/12] unpack-trees: be careful around sparse directory entries

Message ID e28df7f9395da33f24d6b75fa30081074ac6b801.1621598382.git.gitgitgadget@gmail.com (mailing list archive)
State New, archived
Headers show
Series Sparse-index: integrate with status | expand

Commit Message

Derrick Stolee May 21, 2021, 11:59 a.m. UTC
From: Derrick Stolee <dstolee@microsoft.com>

The methods traverse_by_cache_tree() and unpack_nondirectories() have
similar behavior in trying to demonstrate the difference between and
index and a tree, with some differences about how they walk the index.

Each of these is expecting every cache entry to correspond to a file
path. We need to skip over the sparse directory entries in the case of a
sparse-index. Those entries are discovered in the portion that looks for
subtrees among the cache entries by scanning the paths for slashes.

Skipping these sparse directory entries will have a measurable effect
when we relax 'git status' to work with sparse-indexes: without this
change these methods would call call_unpack_fn() which in turn calls
oneway_diff() and then shows these sparse directory entries as added or
modified files.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
---
 unpack-trees.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Derrick Stolee May 28, 2021, 11:36 a.m. UTC | #1
On 5/21/2021 7:59 AM, Derrick Stolee via GitGitGadget wrote:
> From: Derrick Stolee <dstolee@microsoft.com>
> 
> The methods traverse_by_cache_tree() and unpack_nondirectories() have
> similar behavior in trying to demonstrate the difference between and
> index and a tree, with some differences about how they walk the index.

As I have been working on further sparse-index integrations,
specifically with 'git checkout', I have found an issue with this
patch that doesn't show itself in the current t1092 test script,
but appears later as more complicated scenarios appear.

I am pursuing the correct fix (that will also make 'git checkout'
work better) but it might be a week or two before I can send a v5
with that fix.

Thanks,
-Stolee
diff mbox series

Patch

diff --git a/unpack-trees.c b/unpack-trees.c
index ef6a2b1c951c..22634d98e72b 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -802,6 +802,9 @@  static int traverse_by_cache_tree(int pos, int nr_entries, int nr_names,
 
 		src[0] = o->src_index->cache[pos + i];
 
+		if (S_ISSPARSEDIR(src[0]->ce_mode))
+			continue;
+
 		len = ce_namelen(src[0]);
 		new_ce_len = cache_entry_size(len);
 
@@ -1074,6 +1077,9 @@  static int unpack_nondirectories(int n, unsigned long mask,
 	if (mask == dirmask && !src[0])
 		return 0;
 
+	if (src[0] && S_ISSPARSEDIR(src[0]->ce_mode))
+		return 0;
+
 	/*
 	 * Ok, we've filled in up to any potential index entry in src[0],
 	 * now do the rest.