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

[PATCH v3 3/4] cache.h: create 'index_name_pos_sparse()'

From
Victoria Dye via GitGitGadget <gitgitgadget@gmail.com>
Date
Aug 8, 2022, 19:07 UTC
Message-ID
<d0bdec63286e320a12cca3f0bb8a780ae451caf2.1659985672.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1312.v3.git.1659985672.gitgitgadget@gmail.com>
From: Victoria Dye <vdye@github.com>

Add 'index_name_pos_sparse()', which behaves the same as 'index_name_pos()', except that it does not expand a sparse index to search for an entry inside a sparse directory.

'index_entry_exists()' was originally implemented in 20ec2d034c (reset: make sparse-aware (except --mixed), 2021-11-29) as an alternative to 'index_name_pos()' to allow callers to search for an index entry without expanding a sparse index. However, that particular use case only required knowing whether the requested entry existed, so 'index_entry_exists()' does not return the index positioning information provided by 'index_name_pos()'.

This patch implements 'index_name_pos_sparse()' to accommodate callers that need the positioning information of 'index_name_pos()', but do not want to expand the index.

Signed-off-by: Victoria Dye <vdye@github.com>
---
 cache.h      | 9 +++++++++
 read-cache.c | 5 +++++
 2 files changed, 14 insertions(+)
diff --git a/cache.h b/cache.h
index 4aa1bd079d5..4fa3be26393 100644
--- a/cache.h
+++ b/cache.h
@@ -830,6 +830,15 @@ struct cache_entry *index_file_exists(struct index_state *istate, const char *na
  */
 int index_name_pos(struct index_state *, const char *name, int namelen);
 
+/*
+ * Like index_name_pos, returns the position of an entry of the given name in
+ * the index if one exists, otherwise returns a negative value where the negated
+ * value minus 1 is the position where the index entry would be inserted. Unlike
+ * index_name_pos, however, a sparse index is not expanded to find an entry
+ * inside a sparse directory.
+ */
+int index_name_pos_sparse(struct index_state *, const char *name, int namelen);
+
 /*
  * Determines whether an entry with the given name exists within the
  * given index. The return value is 1 if an exact match is found, otherwise
diff --git a/read-cache.c b/read-cache.c
index 4de207752dc..b09128b1884 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -620,6 +620,11 @@ int index_name_pos(struct index_state *istate, const char *name, int namelen)
 	return index_name_stage_pos(istate, name, namelen, 0, EXPAND_SPARSE);
 }
 
+int index_name_pos_sparse(struct index_state *istate, const char *name, int namelen)
+{
+	return index_name_stage_pos(istate, name, namelen, 0, NO_EXPAND_SPARSE);
+}
+
 int index_entry_exists(struct index_state *istate, const char *name, int namelen)
 {
 	return index_name_stage_pos(istate, name, namelen, 0, NO_EXPAND_SPARSE) >= 0;
-- 
gitgitgadget
Previous: Victoria Dye via GitGitGadgetNext: Victoria Dye via GitGitGadget
Message 20 of 23 in “reset/checkout: fix miscellaneous sparse index bugs”
  1. 0/4 reset/checkout: fix miscellaneous sparse index bugsVictoria Dye via GitGitGadget, Aug 4, 2022
  2. 1/4 checkout: fix nested sparse directory diff in sparse indexVictoria Dye via GitGitGadget, Aug 4, 2022
  3. Derrick StoleeAug 5, 2022
  4. 3/4 cache.h: replace 'index_entry_exists()' with 'index_name_pos_sparse()'Victoria Dye via GitGitGadget, Aug 4, 2022
  5. Junio C HamanoAug 4, 2022
  6. Junio C HamanoAug 6, 2022
  7. 2/4 oneway_diff: handle removed sparse directoriesVictoria Dye via GitGitGadget, Aug 4, 2022
  8. 4/4 unpack-trees: handle missing sparse directoriesVictoria Dye via GitGitGadget, Aug 4, 2022
  9. Junio C HamanoAug 4, 2022
  10. Victoria DyeAug 5, 2022
  11. Junio C HamanoAug 5, 2022
  12. 0/4 reset/checkout: fix miscellaneous sparse index bugsVictoria Dye via GitGitGadget, Aug 7, 2022
  13. 2/4 oneway_diff: handle removed sparse directoriesVictoria Dye via GitGitGadget, Aug 7, 2022
  14. 1/4 checkout: fix nested sparse directory diff in sparse indexVictoria Dye via GitGitGadget, Aug 7, 2022
  15. 3/4 cache.h: create 'index_name_pos_sparse()'Victoria Dye via GitGitGadget, Aug 7, 2022
  16. 4/4 unpack-trees: unpack new trees as sparse directoriesVictoria Dye via GitGitGadget, Aug 7, 2022
  17. 0/4 reset/checkout: fix miscellaneous sparse index bugsVictoria Dye via GitGitGadget, Aug 8, 2022
  18. 1/4 checkout: fix nested sparse directory diff in sparse indexVictoria Dye via GitGitGadget, Aug 8, 2022
  19. 2/4 oneway_diff: handle removed sparse directoriesVictoria Dye via GitGitGadget, Aug 8, 2022
  20. 3/4 cache.h: create 'index_name_pos_sparse()'Victoria Dye via GitGitGadget, Aug 8, 2022
  21. 4/4 unpack-trees: unpack new trees as sparse directoriesVictoria Dye via GitGitGadget, Aug 8, 2022
  22. Junio C HamanoAug 8, 2022
  23. Derrick StoleeAug 9, 2022

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.