dir: convert get_dtype to take index

Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Williams committed May 5, 2017 at 12:53 UTC 98f2a687b9a971fec86254537c37df00f18a6e80
1 file changed +13 -10
dir.c
+13 -10
@@ -48,7 +48,8 @@ struct cached_dir {
48 static enum path_treatment read_directory_recursive(struct dir_struct *dir,
49 const char *path, int len, struct untracked_cache_dir *untracked,
50 int check_only, const struct pathspec *pathspec);
51 -static int get_dtype(struct dirent *de, const char *path, int len);
51 +static int get_dtype(struct dirent *de, struct index_state *istate,
52 + const char *path, int len);
53
54 int fspathcmp(const char *a, const char *b)
55 {
@@ -975,7 +976,7 @@ static struct exclude *last_exclude_matching_from_list(const char *pathname,
976
977 if (x->flags & EXC_FLAG_MUSTBEDIR) {
978 if (*dtype == DT_UNKNOWN)
978 - *dtype = get_dtype(NULL, pathname, pathlen);
979 + *dtype = get_dtype(NULL, &the_index, pathname, pathlen);
980 if (*dtype != DT_DIR)
981 continue;
982 }
@@ -1459,12 +1460,13 @@ static int exclude_matches_pathspec(const char *path, int pathlen,
1460 return 0;
1461 }
1462
1462 -static int get_index_dtype(const char *path, int len)
1463 +static int get_index_dtype(struct index_state *istate,
1464 + const char *path, int len)
1465 {
1466 int pos;
1467 const struct cache_entry *ce;
1468
1467 - ce = index_file_exists(&the_index, path, len, 0);
1469 + ce = index_file_exists(istate, path, len, 0);
1470 if (ce) {
1471 if (!ce_uptodate(ce))
1472 return DT_UNKNOWN;
@@ -1478,12 +1480,12 @@ static int get_index_dtype(const char *path, int len)
1480 }
1481
1482 /* Try to look it up as a directory */
1481 - pos = index_name_pos(&the_index, path, len);
1483 + pos = index_name_pos(istate, path, len);
1484 if (pos >= 0)
1485 return DT_UNKNOWN;
1486 pos = -pos-1;
1485 - while (pos < the_index.cache_nr) {
1486 - ce = the_index.cache[pos++];
1487 + while (pos < istate->cache_nr) {
1488 + ce = istate->cache[pos++];
1489 if (strncmp(ce->name, path, len))
1490 break;
1491 if (ce->name[len] > '/')
@@ -1497,14 +1499,15 @@ static int get_index_dtype(const char *path, int len)
1499 return DT_UNKNOWN;
1500 }
1501
1500 -static int get_dtype(struct dirent *de, const char *path, int len)
1502 +static int get_dtype(struct dirent *de, struct index_state *istate,
1503 + const char *path, int len)
1504 {
1505 int dtype = de ? DTYPE(de) : DT_UNKNOWN;
1506 struct stat st;
1507
1508 if (dtype != DT_UNKNOWN)
1509 return dtype;
1507 - dtype = get_index_dtype(path, len);
1510 + dtype = get_index_dtype(istate, path, len);
1511 if (dtype != DT_UNKNOWN)
1512 return dtype;
1513 if (lstat(path, &st))
@@ -1529,7 +1532,7 @@ static enum path_treatment treat_one_path(struct dir_struct *dir,
1532 int has_path_in_index = !!index_file_exists(&the_index, path->buf, path->len, ignore_case);
1533
1534 if (dtype == DT_UNKNOWN)
1532 - dtype = get_dtype(de, path->buf, path->len);
1535 + dtype = get_dtype(de, &the_index, path->buf, path->len);
1536
1537 /* Always exclude indexed files */
1538 if (dtype != DT_DIR && has_path_in_index)