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 <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Eric Sunshine committed
Sep 17, 2013 at 03:06 UTC
ebbd7439b1b7cce0e8c68fe3e220d71cc58dd980
3 files changed
+9
-9
dir.c
+5
-5
@@ -860,7 +860,7 @@ static struct dir_entry *dir_entry_new(const char *pathname, int len)
860
861
static struct dir_entry *dir_add_name(struct dir_struct *dir, const char *pathname, int len)
862
{
863
- if (cache_name_exists(pathname, len, ignore_case))
863
+ if (cache_file_exists(pathname, len, ignore_case))
864
return NULL;
865
866
ALLOC_GROW(dir->entries, dir->nr+1, dir->alloc);
@@ -885,11 +885,11 @@ enum exist_status {
885
/*
886
* Do not use the alphabetically sorted index to look up
887
* the directory name; instead, use the case insensitive
888
- * name hash.
888
+ * directory hash.
889
*/
890
static enum exist_status directory_exists_in_index_icase(const char *dirname, int len)
891
{
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);
893
unsigned char endchar;
894
895
if (!ce)
@@ -1071,7 +1071,7 @@ static int get_index_dtype(const char *path, int len)
1071
int pos;
1072
const struct cache_entry *ce;
1073
1074
- ce = cache_name_exists(path, len, 0);
1074
+ ce = cache_file_exists(path, len, 0);
1075
if (ce) {
1076
if (!ce_uptodate(ce))
1077
return DT_UNKNOWN;
@@ -1131,7 +1131,7 @@ static enum path_treatment treat_one_path(struct dir_struct *dir,
1131
int dtype, struct dirent *de)
1132
{
1133
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);
1135
1136
if (dtype == DT_UNKNOWN)
1137
dtype = get_dtype(de, path->buf, path->len);
read-cache.c
+2
-2
@@ -643,7 +643,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
643
if (*ptr == '/') {
644
struct cache_entry *foundce;
645
++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);
647
if (foundce) {
648
memcpy((void *)startPtr, foundce->name + (startPtr - ce->name), ptr - startPtr);
649
startPtr = ptr;
@@ -652,7 +652,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
652
}
653
}
654
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);
656
if (alias && !ce_stage(alias) && !ie_match_stat(istate, alias, st, ce_option)) {
657
/* Nothing changed, really */
658
free(ce);
unpack-trees.c
+2
-2
@@ -1357,7 +1357,7 @@ static int icase_exists(struct unpack_trees_options *o, const char *name, int le
1357
{
1358
const struct cache_entry *src;
1359
1360
- src = index_name_exists(o->src_index, name, len, 1);
1360
+ src = index_file_exists(o->src_index, name, len, 1);
1361
return src && !ie_match_stat(o->src_index, src, st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE);
1362
}
1363
@@ -1403,7 +1403,7 @@ static int check_ok_to_remove(const char *name, int len, int dtype,
1403
* delete this path, which is in a subdirectory that
1404
* is being replaced with a blob.
1405
*/
1406
- result = index_name_exists(&o->result, name, len, 0);
1406
+ result = index_file_exists(&o->result, name, len, 0);
1407
if (result) {
1408
if (result->ce_flags & CE_REMOVE)
1409
return 0;