Skip to content

Commit

Permalink
name-hash: add index_dir_find()
Browse files Browse the repository at this point in the history
index_dir_exists() returns a boolean to indicate if there is a
case-insensitive match in the directory name-hash, but does not
provide the caller with the exact spelling of that match.

Create index_dir_find() to do the case-insensitive search *and*
optionally return the spelling of the matched directory prefix in a
provided strbuf.

To avoid code duplication, convert index_dir_exists() to be a trivial
wrapper around the new index_dir_find().

Signed-off-by: Jeff Hostetler <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
jeffhostetler authored and gitster committed Feb 26, 2024
1 parent edae91a commit b316552
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 8 additions & 1 deletion name-hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -685,13 +685,20 @@ static int same_name(const struct cache_entry *ce, const char *name, int namelen
return slow_same_name(name, namelen, ce->name, len);
}

int index_dir_exists(struct index_state *istate, const char *name, int namelen)
int index_dir_find(struct index_state *istate, const char *name, int namelen,
struct strbuf *canonical_path)
{
struct dir_entry *dir;

lazy_init_name_hash(istate);
expand_to_path(istate, name, namelen, 0);
dir = find_dir_entry(istate, name, namelen);

if (canonical_path && dir && dir->nr) {
strbuf_reset(canonical_path);
strbuf_add(canonical_path, dir->name, dir->namelen);
}

return dir && dir->nr;
}

Expand Down
7 changes: 6 additions & 1 deletion name-hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
struct cache_entry;
struct index_state;

int index_dir_exists(struct index_state *istate, const char *name, int namelen);

int index_dir_find(struct index_state *istate, const char *name, int namelen,
struct strbuf *canonical_path);

#define index_dir_exists(i, n, l) index_dir_find((i), (n), (l), NULL)

void adjust_dirname_case(struct index_state *istate, char *name);
struct cache_entry *index_file_exists(struct index_state *istate, const char *name, int namelen, int igncase);

Expand Down

0 comments on commit b316552

Please sign in to comment.