Skip to content

Commit 9553aa0

Browse files
vdyegitster
authored andcommitted
cache.h: create 'index_name_pos_sparse()'
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 20ec2d0 (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 56d8a27 commit 9553aa0

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

cache.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,15 @@ struct cache_entry *index_file_exists(struct index_state *istate, const char *na
830830
*/
831831
int index_name_pos(struct index_state *, const char *name, int namelen);
832832

833+
/*
834+
* Like index_name_pos, returns the position of an entry of the given name in
835+
* the index if one exists, otherwise returns a negative value where the negated
836+
* value minus 1 is the position where the index entry would be inserted. Unlike
837+
* index_name_pos, however, a sparse index is not expanded to find an entry
838+
* inside a sparse directory.
839+
*/
840+
int index_name_pos_sparse(struct index_state *, const char *name, int namelen);
841+
833842
/*
834843
* Determines whether an entry with the given name exists within the
835844
* given index. The return value is 1 if an exact match is found, otherwise

read-cache.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,11 @@ int index_name_pos(struct index_state *istate, const char *name, int namelen)
620620
return index_name_stage_pos(istate, name, namelen, 0, EXPAND_SPARSE);
621621
}
622622

623+
int index_name_pos_sparse(struct index_state *istate, const char *name, int namelen)
624+
{
625+
return index_name_stage_pos(istate, name, namelen, 0, NO_EXPAND_SPARSE);
626+
}
627+
623628
int index_entry_exists(struct index_state *istate, const char *name, int namelen)
624629
{
625630
return index_name_stage_pos(istate, name, namelen, 0, NO_EXPAND_SPARSE) >= 0;

0 commit comments

Comments
 (0)