t/helper: stop using `the_index`

Convert test-helper tools to use `the_repository->index` instead of `the_index`. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Apr 18, 2024 at 14:14 UTC 319ba144076c27f3451bb73834839e9441a9c180
8 files changed +43 -51
t/helper/test-cache-tree.c
+8 -9
@@ -1,4 +1,3 @@
1 -#define USE_THE_INDEX_VARIABLE
1 #include "test-tool.h"
2 #include "gettext.h"
3 #include "hex.h"
@@ -38,29 +37,29 @@ int cmd__cache_tree(int argc, const char **argv)
37 if (repo_read_index(the_repository) < 0)
38 die(_("unable to read index file"));
39
41 - oidcpy(&oid, &the_index.cache_tree->oid);
40 + oidcpy(&oid, &the_repository->index->cache_tree->oid);
41 tree = parse_tree_indirect(&oid);
42 if (!tree)
43 die(_("not a tree object: %s"), oid_to_hex(&oid));
44
45 if (empty) {
46 /* clear the cache tree & allocate a new one */
48 - cache_tree_free(&the_index.cache_tree);
49 - the_index.cache_tree = cache_tree();
47 + cache_tree_free(&the_repository->index->cache_tree);
48 + the_repository->index->cache_tree = cache_tree();
49 } else if (invalidate_qty) {
50 /* invalidate the specified number of unique paths */
52 - float f_interval = (float)the_index.cache_nr / invalidate_qty;
51 + float f_interval = (float)the_repository->index->cache_nr / invalidate_qty;
52 int interval = f_interval < 1.0 ? 1 : (int)f_interval;
54 - for (i = 0; i < invalidate_qty && i * interval < the_index.cache_nr; i++)
55 - cache_tree_invalidate_path(&the_index, the_index.cache[i * interval]->name);
53 + for (i = 0; i < invalidate_qty && i * interval < the_repository->index->cache_nr; i++)
54 + cache_tree_invalidate_path(the_repository->index, the_repository->index->cache[i * interval]->name);
55 }
56
57 if (argc != 1)
58 usage_with_options(test_cache_tree_usage, options);
59 else if (!strcmp(argv[0], "prime"))
61 - prime_cache_tree(the_repository, &the_index, tree);
60 + prime_cache_tree(the_repository, the_repository->index, tree);
61 else if (!strcmp(argv[0], "update"))
63 - cache_tree_update(&the_index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR);
62 + cache_tree_update(the_repository->index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR);
63 /* use "control" subcommand to specify no-op */
64 else if (!!strcmp(argv[0], "control"))
65 die(_("Unhandled subcommand '%s'"), argv[0]);
t/helper/test-dump-cache-tree.c
+2 -3
@@ -1,4 +1,3 @@
1 -#define USE_THE_INDEX_VARIABLE
1 #include "test-tool.h"
2 #include "hash.h"
3 #include "hex.h"
@@ -68,10 +67,10 @@ int cmd__dump_cache_tree(int ac UNUSED, const char **av UNUSED)
67 setup_git_directory();
68 if (repo_read_index(the_repository) < 0)
69 die("unable to read index file");
71 - istate = the_index;
70 + istate = *the_repository->index;
71 istate.cache_tree = another;
72 cache_tree_update(&istate, WRITE_TREE_DRY_RUN);
74 - ret = dump_cache_tree(the_index.cache_tree, another, "");
73 + ret = dump_cache_tree(the_repository->index->cache_tree, another, "");
74 cache_tree_free(&another);
75
76 return ret;
t/helper/test-dump-split-index.c
+5 -6
@@ -1,4 +1,3 @@
1 -#define USE_THE_INDEX_VARIABLE
1 #include "test-tool.h"
2 #include "hex.h"
3 #include "read-cache-ll.h"
@@ -19,16 +18,16 @@ int cmd__dump_split_index(int ac UNUSED, const char **av)
18
19 setup_git_directory();
20
22 - do_read_index(&the_index, av[1], 1);
23 - printf("own %s\n", oid_to_hex(&the_index.oid));
24 - si = the_index.split_index;
21 + do_read_index(the_repository->index, av[1], 1);
22 + printf("own %s\n", oid_to_hex(&the_repository->index->oid));
23 + si = the_repository->index->split_index;
24 if (!si) {
25 printf("not a split index\n");
26 return 0;
27 }
28 printf("base %s\n", oid_to_hex(&si->base_oid));
30 - for (i = 0; i < the_index.cache_nr; i++) {
31 - struct cache_entry *ce = the_index.cache[i];
29 + for (i = 0; i < the_repository->index->cache_nr; i++) {
30 + struct cache_entry *ce = the_repository->index->cache[i];
31 printf("%06o %s %d\t%s\n", ce->ce_mode,
32 oid_to_hex(&ce->oid), ce_stage(ce), ce->name);
33 }
t/helper/test-dump-untracked-cache.c
+1 -2
@@ -1,4 +1,3 @@
1 -#define USE_THE_INDEX_VARIABLE
1 #include "test-tool.h"
2 #include "dir.h"
3 #include "hex.h"
@@ -56,7 +55,7 @@ int cmd__dump_untracked_cache(int ac UNUSED, const char **av UNUSED)
55 setup_git_directory();
56 if (repo_read_index(the_repository) < 0)
57 die("unable to read index file");
59 - uc = the_index.untracked;
58 + uc = the_repository->index->untracked;
59 if (!uc) {
60 printf("no untracked cache\n");
61 return 0;
t/helper/test-lazy-init-name-hash.c
+19 -20
@@ -1,4 +1,3 @@
1 -#define USE_THE_INDEX_VARIABLE
1 #include "test-tool.h"
2 #include "environment.h"
3 #include "name-hash.h"
@@ -40,22 +39,22 @@ static void dump_run(void)
39
40 repo_read_index(the_repository);
41 if (single) {
43 - test_lazy_init_name_hash(&the_index, 0);
42 + test_lazy_init_name_hash(the_repository->index, 0);
43 } else {
45 - int nr_threads_used = test_lazy_init_name_hash(&the_index, 1);
44 + int nr_threads_used = test_lazy_init_name_hash(the_repository->index, 1);
45 if (!nr_threads_used)
46 die("non-threaded code path used");
47 }
48
50 - hashmap_for_each_entry(&the_index.dir_hash, &iter_dir, dir,
49 + hashmap_for_each_entry(&the_repository->index->dir_hash, &iter_dir, dir,
50 ent /* member name */)
51 printf("dir %08x %7d %s\n", dir->ent.hash, dir->nr, dir->name);
52
54 - hashmap_for_each_entry(&the_index.name_hash, &iter_cache, ce,
53 + hashmap_for_each_entry(&the_repository->index->name_hash, &iter_cache, ce,
54 ent /* member name */)
55 printf("name %08x %s\n", ce->ent.hash, ce->name);
56
58 - discard_index(&the_index);
57 + discard_index(the_repository->index);
58 }
59
60 /*
@@ -74,7 +73,7 @@ static uint64_t time_runs(int try_threaded)
73 t0 = getnanotime();
74 repo_read_index(the_repository);
75 t1 = getnanotime();
77 - nr_threads_used = test_lazy_init_name_hash(&the_index, try_threaded);
76 + nr_threads_used = test_lazy_init_name_hash(the_repository->index, try_threaded);
77 t2 = getnanotime();
78
79 sum += (t2 - t1);
@@ -86,16 +85,16 @@ static uint64_t time_runs(int try_threaded)
85 printf("%f %f %d multi %d\n",
86 ((double)(t1 - t0))/1000000000,
87 ((double)(t2 - t1))/1000000000,
89 - the_index.cache_nr,
88 + the_repository->index->cache_nr,
89 nr_threads_used);
90 else
91 printf("%f %f %d single\n",
92 ((double)(t1 - t0))/1000000000,
93 ((double)(t2 - t1))/1000000000,
95 - the_index.cache_nr);
94 + the_repository->index->cache_nr);
95 fflush(stdout);
96
98 - discard_index(&the_index);
97 + discard_index(the_repository->index);
98 }
99
100 avg = sum / count;
@@ -120,8 +119,8 @@ static void analyze_run(void)
119 int nr;
120
121 repo_read_index(the_repository);
123 - cache_nr_limit = the_index.cache_nr;
124 - discard_index(&the_index);
122 + cache_nr_limit = the_repository->index->cache_nr;
123 + discard_index(the_repository->index);
124
125 nr = analyze;
126 while (1) {
@@ -135,22 +134,22 @@ static void analyze_run(void)
134
135 for (i = 0; i < count; i++) {
136 repo_read_index(the_repository);
138 - the_index.cache_nr = nr; /* cheap truncate of index */
137 + the_repository->index->cache_nr = nr; /* cheap truncate of index */
138 t1s = getnanotime();
140 - test_lazy_init_name_hash(&the_index, 0);
139 + test_lazy_init_name_hash(the_repository->index, 0);
140 t2s = getnanotime();
141 sum_single += (t2s - t1s);
143 - the_index.cache_nr = cache_nr_limit;
144 - discard_index(&the_index);
142 + the_repository->index->cache_nr = cache_nr_limit;
143 + discard_index(the_repository->index);
144
145 repo_read_index(the_repository);
147 - the_index.cache_nr = nr; /* cheap truncate of index */
146 + the_repository->index->cache_nr = nr; /* cheap truncate of index */
147 t1m = getnanotime();
149 - nr_threads_used = test_lazy_init_name_hash(&the_index, 1);
148 + nr_threads_used = test_lazy_init_name_hash(the_repository->index, 1);
149 t2m = getnanotime();
150 sum_multi += (t2m - t1m);
152 - the_index.cache_nr = cache_nr_limit;
153 - discard_index(&the_index);
151 + the_repository->index->cache_nr = cache_nr_limit;
152 + discard_index(the_repository->index);
153
154 if (!nr_threads_used)
155 printf(" [size %8d] [single %f] non-threaded code path used\n",
t/helper/test-read-cache.c
+4 -5
@@ -1,4 +1,3 @@
1 -#define USE_THE_INDEX_VARIABLE
1 #include "test-tool.h"
2 #include "config.h"
3 #include "read-cache-ll.h"
@@ -27,16 +26,16 @@ int cmd__read_cache(int argc, const char **argv)
26 if (name) {
27 int pos;
28
30 - refresh_index(&the_index, REFRESH_QUIET,
29 + refresh_index(the_repository->index, REFRESH_QUIET,
30 NULL, NULL, NULL);
32 - pos = index_name_pos(&the_index, name, strlen(name));
31 + pos = index_name_pos(the_repository->index, name, strlen(name));
32 if (pos < 0)
33 die("%s not in index", name);
34 printf("%s is%s up to date\n", name,
36 - ce_uptodate(the_index.cache[pos]) ? "" : " not");
35 + ce_uptodate(the_repository->index->cache[pos]) ? "" : " not");
36 write_file(name, "%d\n", i);
37 }
39 - discard_index(&the_index);
38 + discard_index(the_repository->index);
39 }
40 return 0;
41 }
t/helper/test-scrap-cache-tree.c
+3 -4
@@ -1,4 +1,3 @@
1 -#define USE_THE_INDEX_VARIABLE
1 #include "test-tool.h"
2 #include "lockfile.h"
3 #include "read-cache-ll.h"
@@ -15,9 +14,9 @@ int cmd__scrap_cache_tree(int ac UNUSED, const char **av UNUSED)
14 repo_hold_locked_index(the_repository, &index_lock, LOCK_DIE_ON_ERROR);
15 if (repo_read_index(the_repository) < 0)
16 die("unable to read index file");
18 - cache_tree_free(&the_index.cache_tree);
19 - the_index.cache_tree = NULL;
20 - if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK))
17 + cache_tree_free(&the_repository->index->cache_tree);
18 + the_repository->index->cache_tree = NULL;
19 + if (write_locked_index(the_repository->index, &index_lock, COMMIT_LOCK))
20 die("unable to write index file");
21 return 0;
22 }
t/helper/test-write-cache.c
+1 -2
@@ -1,4 +1,3 @@
1 -#define USE_THE_INDEX_VARIABLE
1 #include "test-tool.h"
2 #include "lockfile.h"
3 #include "read-cache-ll.h"
@@ -16,7 +15,7 @@ int cmd__write_cache(int argc, const char **argv)
15 for (i = 0; i < cnt; i++) {
16 repo_hold_locked_index(the_repository, &index_lock,
17 LOCK_DIE_ON_ERROR);
19 - if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK))
18 + if (write_locked_index(the_repository->index, &index_lock, COMMIT_LOCK))
19 die("unable to write index file");
20 }
21