dir: stop using the index compatibility macros
In order to make it clearer where the_index is being referenced, stop using the index compatibility macros in dir.c. This is to make it easier to identify the functions which need to be convert to taking in a 'struct index_state' as a parameter. The end goal would be to eliminate the need to reference global index state in dir.c. 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
12cd0bf9b0291bb9a688c197a413d19f3c54710e
1 file changed
+21
-20
dir.c
+21
-20
@@ -7,6 +7,7 @@
7
* Copyright (C) Linus Torvalds, 2005-2006
8
* Junio Hamano, 2005-2006
9
*/
10
+#define NO_THE_INDEX_COMPATIBILITY_MACROS
11
#include "cache.h"
12
#include "dir.h"
13
#include "attr.h"
@@ -596,12 +597,12 @@ static void *read_skip_worktree_file_from_index(const char *path, size_t *size,
597
void *data;
598
599
len = strlen(path);
599
- pos = cache_name_pos(path, len);
600
+ pos = index_name_pos(&the_index, path, len);
601
if (pos < 0)
602
return NULL;
602
- if (!ce_skip_worktree(active_cache[pos]))
603
+ if (!ce_skip_worktree(the_index.cache[pos]))
604
return NULL;
604
- data = read_sha1_file(active_cache[pos]->oid.hash, &type, &sz);
605
+ data = read_sha1_file(the_index.cache[pos]->oid.hash, &type, &sz);
606
if (!data || type != OBJ_BLOB) {
607
free(data);
608
return NULL;
@@ -609,7 +610,7 @@ static void *read_skip_worktree_file_from_index(const char *path, size_t *size,
610
*size = xsize_t(sz);
611
if (sha1_stat) {
612
memset(&sha1_stat->stat, 0, sizeof(sha1_stat->stat));
612
- hashcpy(sha1_stat->sha1, active_cache[pos]->oid.hash);
613
+ hashcpy(sha1_stat->sha1, the_index.cache[pos]->oid.hash);
614
}
615
return data;
616
}
@@ -785,12 +786,12 @@ static int add_excludes(const char *fname, const char *base, int baselen,
786
!match_stat_data_racy(&the_index, &sha1_stat->stat, &st))
787
; /* no content change, ss->sha1 still good */
788
else if (check_index &&
788
- (pos = cache_name_pos(fname, strlen(fname))) >= 0 &&
789
- !ce_stage(active_cache[pos]) &&
790
- ce_uptodate(active_cache[pos]) &&
789
+ (pos = index_name_pos(&the_index, fname, strlen(fname))) >= 0 &&
790
+ !ce_stage(the_index.cache[pos]) &&
791
+ ce_uptodate(the_index.cache[pos]) &&
792
!would_convert_to_git(fname))
793
hashcpy(sha1_stat->sha1,
793
- active_cache[pos]->oid.hash);
794
+ the_index.cache[pos]->oid.hash);
795
else
796
hash_sha1_file(buf, size, "blob", sha1_stat->sha1);
797
fill_stat_data(&sha1_stat->stat, &st);
@@ -1235,7 +1236,7 @@ static struct dir_entry *dir_entry_new(const char *pathname, int len)
1236
1237
static struct dir_entry *dir_add_name(struct dir_struct *dir, const char *pathname, int len)
1238
{
1238
- if (cache_file_exists(pathname, len, ignore_case))
1239
+ if (index_file_exists(&the_index, pathname, len, ignore_case))
1240
return NULL;
1241
1242
ALLOC_GROW(dir->entries, dir->nr+1, dir->alloc);
@@ -1244,7 +1245,7 @@ static struct dir_entry *dir_add_name(struct dir_struct *dir, const char *pathna
1245
1246
struct dir_entry *dir_add_ignored(struct dir_struct *dir, const char *pathname, int len)
1247
{
1247
- if (!cache_name_is_other(pathname, len))
1248
+ if (!index_name_is_other(&the_index, pathname, len))
1249
return NULL;
1250
1251
ALLOC_GROW(dir->ignored, dir->ignored_nr+1, dir->ignored_alloc);
@@ -1266,10 +1267,10 @@ static enum exist_status directory_exists_in_index_icase(const char *dirname, in
1267
{
1268
struct cache_entry *ce;
1269
1269
- if (cache_dir_exists(dirname, len))
1270
+ if (index_dir_exists(&the_index, dirname, len))
1271
return index_directory;
1272
1272
- ce = cache_file_exists(dirname, len, ignore_case);
1273
+ ce = index_file_exists(&the_index, dirname, len, ignore_case);
1274
if (ce && S_ISGITLINK(ce->ce_mode))
1275
return index_gitdir;
1276
@@ -1290,11 +1291,11 @@ static enum exist_status directory_exists_in_index(const char *dirname, int len)
1291
if (ignore_case)
1292
return directory_exists_in_index_icase(dirname, len);
1293
1293
- pos = cache_name_pos(dirname, len);
1294
+ pos = index_name_pos(&the_index, dirname, len);
1295
if (pos < 0)
1296
pos = -pos-1;
1296
- while (pos < active_nr) {
1297
- const struct cache_entry *ce = active_cache[pos++];
1297
+ while (pos < the_index.cache_nr) {
1298
+ const struct cache_entry *ce = the_index.cache[pos++];
1299
unsigned char endchar;
1300
1301
if (strncmp(ce->name, dirname, len))
@@ -1460,7 +1461,7 @@ static int get_index_dtype(const char *path, int len)
1461
int pos;
1462
const struct cache_entry *ce;
1463
1463
- ce = cache_file_exists(path, len, 0);
1464
+ ce = index_file_exists(&the_index, path, len, 0);
1465
if (ce) {
1466
if (!ce_uptodate(ce))
1467
return DT_UNKNOWN;
@@ -1474,12 +1475,12 @@ static int get_index_dtype(const char *path, int len)
1475
}
1476
1477
/* Try to look it up as a directory */
1477
- pos = cache_name_pos(path, len);
1478
+ pos = index_name_pos(&the_index, path, len);
1479
if (pos >= 0)
1480
return DT_UNKNOWN;
1481
pos = -pos-1;
1481
- while (pos < active_nr) {
1482
- ce = active_cache[pos++];
1482
+ while (pos < the_index.cache_nr) {
1483
+ ce = the_index.cache[pos++];
1484
if (strncmp(ce->name, path, len))
1485
break;
1486
if (ce->name[len] > '/')
@@ -1522,7 +1523,7 @@ static enum path_treatment treat_one_path(struct dir_struct *dir,
1523
int dtype, struct dirent *de)
1524
{
1525
int exclude;
1525
- int has_path_in_index = !!cache_file_exists(path->buf, path->len, ignore_case);
1526
+ int has_path_in_index = !!index_file_exists(&the_index, path->buf, path->len, ignore_case);
1527
1528
if (dtype == DT_UNKNOWN)
1529
dtype = get_dtype(de, path->buf, path->len);