Skip to content

Commit b316552

Browse files
jeffhostetlergitster
authored andcommitted
name-hash: add index_dir_find()
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]>
1 parent edae91a commit b316552

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

name-hash.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,13 +685,20 @@ static int same_name(const struct cache_entry *ce, const char *name, int namelen
685685
return slow_same_name(name, namelen, ce->name, len);
686686
}
687687

688-
int index_dir_exists(struct index_state *istate, const char *name, int namelen)
688+
int index_dir_find(struct index_state *istate, const char *name, int namelen,
689+
struct strbuf *canonical_path)
689690
{
690691
struct dir_entry *dir;
691692

692693
lazy_init_name_hash(istate);
693694
expand_to_path(istate, name, namelen, 0);
694695
dir = find_dir_entry(istate, name, namelen);
696+
697+
if (canonical_path && dir && dir->nr) {
698+
strbuf_reset(canonical_path);
699+
strbuf_add(canonical_path, dir->name, dir->namelen);
700+
}
701+
695702
return dir && dir->nr;
696703
}
697704

name-hash.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
struct cache_entry;
55
struct index_state;
66

7-
int index_dir_exists(struct index_state *istate, const char *name, int namelen);
7+
8+
int index_dir_find(struct index_state *istate, const char *name, int namelen,
9+
struct strbuf *canonical_path);
10+
11+
#define index_dir_exists(i, n, l) index_dir_find((i), (n), (l), NULL)
12+
813
void adjust_dirname_case(struct index_state *istate, char *name);
914
struct cache_entry *index_file_exists(struct index_state *istate, const char *name, int namelen, int igncase);
1015

0 commit comments

Comments
 (0)