Skip to content

Commit ebbd743

Browse files
sunshinecogitster
authored andcommitted
employ new explicit "exists in index?" API
Each caller of index_name_exists() knows whether it is looking for a directory or a file, and can avoid the unnecessary indirection of index_name_exists() by instead calling index_dir_exists() or index_file_exists() directly. Invoking the appropriate search function explicitly will allow a subsequent patch to relieve callers of the artificial burden of having to add a trailing '/' to the pathname given to index_dir_exists(). Signed-off-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent db5360f commit ebbd743

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

dir.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ static struct dir_entry *dir_entry_new(const char *pathname, int len)
860860

861861
static struct dir_entry *dir_add_name(struct dir_struct *dir, const char *pathname, int len)
862862
{
863-
if (cache_name_exists(pathname, len, ignore_case))
863+
if (cache_file_exists(pathname, len, ignore_case))
864864
return NULL;
865865

866866
ALLOC_GROW(dir->entries, dir->nr+1, dir->alloc);
@@ -885,11 +885,11 @@ enum exist_status {
885885
/*
886886
* Do not use the alphabetically sorted index to look up
887887
* the directory name; instead, use the case insensitive
888-
* name hash.
888+
* directory hash.
889889
*/
890890
static enum exist_status directory_exists_in_index_icase(const char *dirname, int len)
891891
{
892-
const struct cache_entry *ce = cache_name_exists(dirname, len + 1, ignore_case);
892+
const struct cache_entry *ce = cache_dir_exists(dirname, len + 1);
893893
unsigned char endchar;
894894

895895
if (!ce)
@@ -1071,7 +1071,7 @@ static int get_index_dtype(const char *path, int len)
10711071
int pos;
10721072
const struct cache_entry *ce;
10731073

1074-
ce = cache_name_exists(path, len, 0);
1074+
ce = cache_file_exists(path, len, 0);
10751075
if (ce) {
10761076
if (!ce_uptodate(ce))
10771077
return DT_UNKNOWN;
@@ -1131,7 +1131,7 @@ static enum path_treatment treat_one_path(struct dir_struct *dir,
11311131
int dtype, struct dirent *de)
11321132
{
11331133
int exclude;
1134-
int has_path_in_index = !!cache_name_exists(path->buf, path->len, ignore_case);
1134+
int has_path_in_index = !!cache_file_exists(path->buf, path->len, ignore_case);
11351135

11361136
if (dtype == DT_UNKNOWN)
11371137
dtype = get_dtype(de, path->buf, path->len);

read-cache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
643643
if (*ptr == '/') {
644644
struct cache_entry *foundce;
645645
++ptr;
646-
foundce = index_name_exists(istate, ce->name, ptr - ce->name, ignore_case);
646+
foundce = index_dir_exists(istate, ce->name, ptr - ce->name);
647647
if (foundce) {
648648
memcpy((void *)startPtr, foundce->name + (startPtr - ce->name), ptr - startPtr);
649649
startPtr = ptr;
@@ -652,7 +652,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
652652
}
653653
}
654654

655-
alias = index_name_exists(istate, ce->name, ce_namelen(ce), ignore_case);
655+
alias = index_file_exists(istate, ce->name, ce_namelen(ce), ignore_case);
656656
if (alias && !ce_stage(alias) && !ie_match_stat(istate, alias, st, ce_option)) {
657657
/* Nothing changed, really */
658658
free(ce);

unpack-trees.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,7 @@ static int icase_exists(struct unpack_trees_options *o, const char *name, int le
13571357
{
13581358
const struct cache_entry *src;
13591359

1360-
src = index_name_exists(o->src_index, name, len, 1);
1360+
src = index_file_exists(o->src_index, name, len, 1);
13611361
return src && !ie_match_stat(o->src_index, src, st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE);
13621362
}
13631363

@@ -1403,7 +1403,7 @@ static int check_ok_to_remove(const char *name, int len, int dtype,
14031403
* delete this path, which is in a subdirectory that
14041404
* is being replaced with a blob.
14051405
*/
1406-
result = index_name_exists(&o->result, name, len, 0);
1406+
result = index_file_exists(&o->result, name, len, 0);
14071407
if (result) {
14081408
if (result->ce_flags & CE_REMOVE)
14091409
return 0;

0 commit comments

Comments
 (0)