]> git.ipfire.org Git - thirdparty/git.git/commitdiff
cache.h: create 'index_name_pos_sparse()'
authorVictoria Dye <vdye@github.com>
Mon, 8 Aug 2022 19:07:51 +0000 (19:07 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 8 Aug 2022 20:21:50 +0000 (13:21 -0700)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
cache.h
read-cache.c

diff --git a/cache.h b/cache.h
index ac5ab4ef9d341088d2b7a0aa5052e982197cf574..33fc8337c6aaef7942bd8b0c5b59637b115a9e44 100644 (file)
--- 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
index 76f372ff9175eaf3a4a47cc97fb8b475393fbc64..06e5b06e63d234c26f674760c846f8a14c6af54b 100644 (file)
@@ -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;