Skip to content

Commit 319ba14

Browse files
pks-tgitster
authored andcommitted
t/helper: stop using the_index
Convert test-helper tools to use `the_repository->index` instead of `the_index`. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 21306a0 commit 319ba14

8 files changed

+43
-51
lines changed

t/helper/test-cache-tree.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#define USE_THE_INDEX_VARIABLE
21
#include "test-tool.h"
32
#include "gettext.h"
43
#include "hex.h"
@@ -38,29 +37,29 @@ int cmd__cache_tree(int argc, const char **argv)
3837
if (repo_read_index(the_repository) < 0)
3938
die(_("unable to read index file"));
4039

41-
oidcpy(&oid, &the_index.cache_tree->oid);
40+
oidcpy(&oid, &the_repository->index->cache_tree->oid);
4241
tree = parse_tree_indirect(&oid);
4342
if (!tree)
4443
die(_("not a tree object: %s"), oid_to_hex(&oid));
4544

4645
if (empty) {
4746
/* 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();
5049
} else if (invalidate_qty) {
5150
/* 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;
5352
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);
5655
}
5756

5857
if (argc != 1)
5958
usage_with_options(test_cache_tree_usage, options);
6059
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);
6261
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);
6463
/* use "control" subcommand to specify no-op */
6564
else if (!!strcmp(argv[0], "control"))
6665
die(_("Unhandled subcommand '%s'"), argv[0]);

t/helper/test-dump-cache-tree.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#define USE_THE_INDEX_VARIABLE
21
#include "test-tool.h"
32
#include "hash.h"
43
#include "hex.h"
@@ -68,10 +67,10 @@ int cmd__dump_cache_tree(int ac UNUSED, const char **av UNUSED)
6867
setup_git_directory();
6968
if (repo_read_index(the_repository) < 0)
7069
die("unable to read index file");
71-
istate = the_index;
70+
istate = *the_repository->index;
7271
istate.cache_tree = another;
7372
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, "");
7574
cache_tree_free(&another);
7675

7776
return ret;

t/helper/test-dump-split-index.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#define USE_THE_INDEX_VARIABLE
21
#include "test-tool.h"
32
#include "hex.h"
43
#include "read-cache-ll.h"
@@ -19,16 +18,16 @@ int cmd__dump_split_index(int ac UNUSED, const char **av)
1918

2019
setup_git_directory();
2120

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;
2524
if (!si) {
2625
printf("not a split index\n");
2726
return 0;
2827
}
2928
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];
3231
printf("%06o %s %d\t%s\n", ce->ce_mode,
3332
oid_to_hex(&ce->oid), ce_stage(ce), ce->name);
3433
}

t/helper/test-dump-untracked-cache.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#define USE_THE_INDEX_VARIABLE
21
#include "test-tool.h"
32
#include "dir.h"
43
#include "hex.h"
@@ -56,7 +55,7 @@ int cmd__dump_untracked_cache(int ac UNUSED, const char **av UNUSED)
5655
setup_git_directory();
5756
if (repo_read_index(the_repository) < 0)
5857
die("unable to read index file");
59-
uc = the_index.untracked;
58+
uc = the_repository->index->untracked;
6059
if (!uc) {
6160
printf("no untracked cache\n");
6261
return 0;

t/helper/test-lazy-init-name-hash.c

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#define USE_THE_INDEX_VARIABLE
21
#include "test-tool.h"
32
#include "environment.h"
43
#include "name-hash.h"
@@ -40,22 +39,22 @@ static void dump_run(void)
4039

4140
repo_read_index(the_repository);
4241
if (single) {
43-
test_lazy_init_name_hash(&the_index, 0);
42+
test_lazy_init_name_hash(the_repository->index, 0);
4443
} 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);
4645
if (!nr_threads_used)
4746
die("non-threaded code path used");
4847
}
4948

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,
5150
ent /* member name */)
5251
printf("dir %08x %7d %s\n", dir->ent.hash, dir->nr, dir->name);
5352

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,
5554
ent /* member name */)
5655
printf("name %08x %s\n", ce->ent.hash, ce->name);
5756

58-
discard_index(&the_index);
57+
discard_index(the_repository->index);
5958
}
6059

6160
/*
@@ -74,7 +73,7 @@ static uint64_t time_runs(int try_threaded)
7473
t0 = getnanotime();
7574
repo_read_index(the_repository);
7675
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);
7877
t2 = getnanotime();
7978

8079
sum += (t2 - t1);
@@ -86,16 +85,16 @@ static uint64_t time_runs(int try_threaded)
8685
printf("%f %f %d multi %d\n",
8786
((double)(t1 - t0))/1000000000,
8887
((double)(t2 - t1))/1000000000,
89-
the_index.cache_nr,
88+
the_repository->index->cache_nr,
9089
nr_threads_used);
9190
else
9291
printf("%f %f %d single\n",
9392
((double)(t1 - t0))/1000000000,
9493
((double)(t2 - t1))/1000000000,
95-
the_index.cache_nr);
94+
the_repository->index->cache_nr);
9695
fflush(stdout);
9796

98-
discard_index(&the_index);
97+
discard_index(the_repository->index);
9998
}
10099

101100
avg = sum / count;
@@ -120,8 +119,8 @@ static void analyze_run(void)
120119
int nr;
121120

122121
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);
125124

126125
nr = analyze;
127126
while (1) {
@@ -135,22 +134,22 @@ static void analyze_run(void)
135134

136135
for (i = 0; i < count; i++) {
137136
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 */
139138
t1s = getnanotime();
140-
test_lazy_init_name_hash(&the_index, 0);
139+
test_lazy_init_name_hash(the_repository->index, 0);
141140
t2s = getnanotime();
142141
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);
145144

146145
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 */
148147
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);
150149
t2m = getnanotime();
151150
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);
154153

155154
if (!nr_threads_used)
156155
printf(" [size %8d] [single %f] non-threaded code path used\n",

t/helper/test-read-cache.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#define USE_THE_INDEX_VARIABLE
21
#include "test-tool.h"
32
#include "config.h"
43
#include "read-cache-ll.h"
@@ -27,16 +26,16 @@ int cmd__read_cache(int argc, const char **argv)
2726
if (name) {
2827
int pos;
2928

30-
refresh_index(&the_index, REFRESH_QUIET,
29+
refresh_index(the_repository->index, REFRESH_QUIET,
3130
NULL, NULL, NULL);
32-
pos = index_name_pos(&the_index, name, strlen(name));
31+
pos = index_name_pos(the_repository->index, name, strlen(name));
3332
if (pos < 0)
3433
die("%s not in index", name);
3534
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");
3736
write_file(name, "%d\n", i);
3837
}
39-
discard_index(&the_index);
38+
discard_index(the_repository->index);
4039
}
4140
return 0;
4241
}

t/helper/test-scrap-cache-tree.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#define USE_THE_INDEX_VARIABLE
21
#include "test-tool.h"
32
#include "lockfile.h"
43
#include "read-cache-ll.h"
@@ -15,9 +14,9 @@ int cmd__scrap_cache_tree(int ac UNUSED, const char **av UNUSED)
1514
repo_hold_locked_index(the_repository, &index_lock, LOCK_DIE_ON_ERROR);
1615
if (repo_read_index(the_repository) < 0)
1716
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))
2120
die("unable to write index file");
2221
return 0;
2322
}

t/helper/test-write-cache.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#define USE_THE_INDEX_VARIABLE
21
#include "test-tool.h"
32
#include "lockfile.h"
43
#include "read-cache-ll.h"
@@ -16,7 +15,7 @@ int cmd__write_cache(int argc, const char **argv)
1615
for (i = 0; i < cnt; i++) {
1716
repo_hold_locked_index(the_repository, &index_lock,
1817
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))
2019
die("unable to write index file");
2120
}
2221

0 commit comments

Comments
 (0)