]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t/helper: stop using `the_index`
authorPatrick Steinhardt <ps@pks.im>
Thu, 18 Apr 2024 12:14:09 +0000 (14:14 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 18 Apr 2024 19:30:41 +0000 (12:30 -0700)
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>
t/helper/test-cache-tree.c
t/helper/test-dump-cache-tree.c
t/helper/test-dump-split-index.c
t/helper/test-dump-untracked-cache.c
t/helper/test-lazy-init-name-hash.c
t/helper/test-read-cache.c
t/helper/test-scrap-cache-tree.c
t/helper/test-write-cache.c

index e7236392c8132a3720f55148d6c2acbf5de01a41..dc89ecfd71ee07289ca95001dfb833deb09bf4ff 100644 (file)
@@ -1,4 +1,3 @@
-#define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
 #include "gettext.h"
 #include "hex.h"
@@ -38,29 +37,29 @@ int cmd__cache_tree(int argc, const char **argv)
        if (repo_read_index(the_repository) < 0)
                die(_("unable to read index file"));
 
-       oidcpy(&oid, &the_index.cache_tree->oid);
+       oidcpy(&oid, &the_repository->index->cache_tree->oid);
        tree = parse_tree_indirect(&oid);
        if (!tree)
                die(_("not a tree object: %s"), oid_to_hex(&oid));
 
        if (empty) {
                /* clear the cache tree & allocate a new one */
-               cache_tree_free(&the_index.cache_tree);
-               the_index.cache_tree = cache_tree();
+               cache_tree_free(&the_repository->index->cache_tree);
+               the_repository->index->cache_tree = cache_tree();
        } else if (invalidate_qty) {
                /* invalidate the specified number of unique paths */
-               float f_interval = (float)the_index.cache_nr / invalidate_qty;
+               float f_interval = (float)the_repository->index->cache_nr / invalidate_qty;
                int interval = f_interval < 1.0 ? 1 : (int)f_interval;
-               for (i = 0; i < invalidate_qty && i * interval < the_index.cache_nr; i++)
-                       cache_tree_invalidate_path(&the_index, the_index.cache[i * interval]->name);
+               for (i = 0; i < invalidate_qty && i * interval < the_repository->index->cache_nr; i++)
+                       cache_tree_invalidate_path(the_repository->index, the_repository->index->cache[i * interval]->name);
        }
 
        if (argc != 1)
                usage_with_options(test_cache_tree_usage, options);
        else if (!strcmp(argv[0], "prime"))
-               prime_cache_tree(the_repository, &the_index, tree);
+               prime_cache_tree(the_repository, the_repository->index, tree);
        else if (!strcmp(argv[0], "update"))
-               cache_tree_update(&the_index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR);
+               cache_tree_update(the_repository->index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR);
        /* use "control" subcommand to specify no-op */
        else if (!!strcmp(argv[0], "control"))
                die(_("Unhandled subcommand '%s'"), argv[0]);
index c38f546e4f096fbd3e9b6cb13ab96bb800f56504..02b0b46c3f93fae47949ac299bfaa9c1423eff2c 100644 (file)
@@ -1,4 +1,3 @@
-#define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
 #include "hash.h"
 #include "hex.h"
@@ -68,10 +67,10 @@ int cmd__dump_cache_tree(int ac UNUSED, const char **av UNUSED)
        setup_git_directory();
        if (repo_read_index(the_repository) < 0)
                die("unable to read index file");
-       istate = the_index;
+       istate = *the_repository->index;
        istate.cache_tree = another;
        cache_tree_update(&istate, WRITE_TREE_DRY_RUN);
-       ret = dump_cache_tree(the_index.cache_tree, another, "");
+       ret = dump_cache_tree(the_repository->index->cache_tree, another, "");
        cache_tree_free(&another);
 
        return ret;
index f29d18ef9490b7a0dd8fd689082a68b4cd5332b0..f472691a3ca95b14266cdc0c0f64ce26d9daa323 100644 (file)
@@ -1,4 +1,3 @@
-#define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
 #include "hex.h"
 #include "read-cache-ll.h"
@@ -19,16 +18,16 @@ int cmd__dump_split_index(int ac UNUSED, const char **av)
 
        setup_git_directory();
 
-       do_read_index(&the_index, av[1], 1);
-       printf("own %s\n", oid_to_hex(&the_index.oid));
-       si = the_index.split_index;
+       do_read_index(the_repository->index, av[1], 1);
+       printf("own %s\n", oid_to_hex(&the_repository->index->oid));
+       si = the_repository->index->split_index;
        if (!si) {
                printf("not a split index\n");
                return 0;
        }
        printf("base %s\n", oid_to_hex(&si->base_oid));
-       for (i = 0; i < the_index.cache_nr; i++) {
-               struct cache_entry *ce = the_index.cache[i];
+       for (i = 0; i < the_repository->index->cache_nr; i++) {
+               struct cache_entry *ce = the_repository->index->cache[i];
                printf("%06o %s %d\t%s\n", ce->ce_mode,
                       oid_to_hex(&ce->oid), ce_stage(ce), ce->name);
        }
index b4af9712fe5f2cfb815e22dc41a588890faecea5..9ff67c39676f9d2b0d66c9f23f433328a32f160c 100644 (file)
@@ -1,4 +1,3 @@
-#define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
 #include "dir.h"
 #include "hex.h"
@@ -56,7 +55,7 @@ int cmd__dump_untracked_cache(int ac UNUSED, const char **av UNUSED)
        setup_git_directory();
        if (repo_read_index(the_repository) < 0)
                die("unable to read index file");
-       uc = the_index.untracked;
+       uc = the_repository->index->untracked;
        if (!uc) {
                printf("no untracked cache\n");
                return 0;
index 187a115d5743f39f7b93e0bf128ead62262a12bb..5f33bb7b8f9d0527aca4257691ef6499068e55ae 100644 (file)
@@ -1,4 +1,3 @@
-#define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
 #include "environment.h"
 #include "name-hash.h"
@@ -40,22 +39,22 @@ static void dump_run(void)
 
        repo_read_index(the_repository);
        if (single) {
-               test_lazy_init_name_hash(&the_index, 0);
+               test_lazy_init_name_hash(the_repository->index, 0);
        } else {
-               int nr_threads_used = test_lazy_init_name_hash(&the_index, 1);
+               int nr_threads_used = test_lazy_init_name_hash(the_repository->index, 1);
                if (!nr_threads_used)
                        die("non-threaded code path used");
        }
 
-       hashmap_for_each_entry(&the_index.dir_hash, &iter_dir, dir,
+       hashmap_for_each_entry(&the_repository->index->dir_hash, &iter_dir, dir,
                                ent /* member name */)
                printf("dir %08x %7d %s\n", dir->ent.hash, dir->nr, dir->name);
 
-       hashmap_for_each_entry(&the_index.name_hash, &iter_cache, ce,
+       hashmap_for_each_entry(&the_repository->index->name_hash, &iter_cache, ce,
                                ent /* member name */)
                printf("name %08x %s\n", ce->ent.hash, ce->name);
 
-       discard_index(&the_index);
+       discard_index(the_repository->index);
 }
 
 /*
@@ -74,7 +73,7 @@ static uint64_t time_runs(int try_threaded)
                t0 = getnanotime();
                repo_read_index(the_repository);
                t1 = getnanotime();
-               nr_threads_used = test_lazy_init_name_hash(&the_index, try_threaded);
+               nr_threads_used = test_lazy_init_name_hash(the_repository->index, try_threaded);
                t2 = getnanotime();
 
                sum += (t2 - t1);
@@ -86,16 +85,16 @@ static uint64_t time_runs(int try_threaded)
                        printf("%f %f %d multi %d\n",
                                   ((double)(t1 - t0))/1000000000,
                                   ((double)(t2 - t1))/1000000000,
-                                  the_index.cache_nr,
+                                  the_repository->index->cache_nr,
                                   nr_threads_used);
                else
                        printf("%f %f %d single\n",
                                   ((double)(t1 - t0))/1000000000,
                                   ((double)(t2 - t1))/1000000000,
-                                  the_index.cache_nr);
+                                  the_repository->index->cache_nr);
                fflush(stdout);
 
-               discard_index(&the_index);
+               discard_index(the_repository->index);
        }
 
        avg = sum / count;
@@ -120,8 +119,8 @@ static void analyze_run(void)
        int nr;
 
        repo_read_index(the_repository);
-       cache_nr_limit = the_index.cache_nr;
-       discard_index(&the_index);
+       cache_nr_limit = the_repository->index->cache_nr;
+       discard_index(the_repository->index);
 
        nr = analyze;
        while (1) {
@@ -135,22 +134,22 @@ static void analyze_run(void)
 
                for (i = 0; i < count; i++) {
                        repo_read_index(the_repository);
-                       the_index.cache_nr = nr; /* cheap truncate of index */
+                       the_repository->index->cache_nr = nr; /* cheap truncate of index */
                        t1s = getnanotime();
-                       test_lazy_init_name_hash(&the_index, 0);
+                       test_lazy_init_name_hash(the_repository->index, 0);
                        t2s = getnanotime();
                        sum_single += (t2s - t1s);
-                       the_index.cache_nr = cache_nr_limit;
-                       discard_index(&the_index);
+                       the_repository->index->cache_nr = cache_nr_limit;
+                       discard_index(the_repository->index);
 
                        repo_read_index(the_repository);
-                       the_index.cache_nr = nr; /* cheap truncate of index */
+                       the_repository->index->cache_nr = nr; /* cheap truncate of index */
                        t1m = getnanotime();
-                       nr_threads_used = test_lazy_init_name_hash(&the_index, 1);
+                       nr_threads_used = test_lazy_init_name_hash(the_repository->index, 1);
                        t2m = getnanotime();
                        sum_multi += (t2m - t1m);
-                       the_index.cache_nr = cache_nr_limit;
-                       discard_index(&the_index);
+                       the_repository->index->cache_nr = cache_nr_limit;
+                       discard_index(the_repository->index);
 
                        if (!nr_threads_used)
                                printf("    [size %8d] [single %f]   non-threaded code path used\n",
index 1acd3623465283e4751a75bce0cbb8bf1926bcd7..458efa88a6359720f211b6d20a873b1c31837c53 100644 (file)
@@ -1,4 +1,3 @@
-#define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
 #include "config.h"
 #include "read-cache-ll.h"
@@ -27,16 +26,16 @@ int cmd__read_cache(int argc, const char **argv)
                if (name) {
                        int pos;
 
-                       refresh_index(&the_index, REFRESH_QUIET,
+                       refresh_index(the_repository->index, REFRESH_QUIET,
                                      NULL, NULL, NULL);
-                       pos = index_name_pos(&the_index, name, strlen(name));
+                       pos = index_name_pos(the_repository->index, name, strlen(name));
                        if (pos < 0)
                                die("%s not in index", name);
                        printf("%s is%s up to date\n", name,
-                              ce_uptodate(the_index.cache[pos]) ? "" : " not");
+                              ce_uptodate(the_repository->index->cache[pos]) ? "" : " not");
                        write_file(name, "%d\n", i);
                }
-               discard_index(&the_index);
+               discard_index(the_repository->index);
        }
        return 0;
 }
index 0a816a96e28b6c43a0b4927418c97bb11ba5298c..737cbe475bd6909bbec85df169ad0c4dd888b012 100644 (file)
@@ -1,4 +1,3 @@
-#define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
 #include "lockfile.h"
 #include "read-cache-ll.h"
@@ -15,9 +14,9 @@ int cmd__scrap_cache_tree(int ac UNUSED, const char **av UNUSED)
        repo_hold_locked_index(the_repository, &index_lock, LOCK_DIE_ON_ERROR);
        if (repo_read_index(the_repository) < 0)
                die("unable to read index file");
-       cache_tree_free(&the_index.cache_tree);
-       the_index.cache_tree = NULL;
-       if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK))
+       cache_tree_free(&the_repository->index->cache_tree);
+       the_repository->index->cache_tree = NULL;
+       if (write_locked_index(the_repository->index, &index_lock, COMMIT_LOCK))
                die("unable to write index file");
        return 0;
 }
index f084034d38e0328e0792d096225c31ddd91d74c7..7e3da380a955f55895ab886911aedf8f1f5ec719 100644 (file)
@@ -1,4 +1,3 @@
-#define USE_THE_INDEX_VARIABLE
 #include "test-tool.h"
 #include "lockfile.h"
 #include "read-cache-ll.h"
@@ -16,7 +15,7 @@ int cmd__write_cache(int argc, const char **argv)
        for (i = 0; i < cnt; i++) {
                repo_hold_locked_index(the_repository, &index_lock,
                                       LOCK_DIE_ON_ERROR);
-               if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK))
+               if (write_locked_index(the_repository->index, &index_lock, COMMIT_LOCK))
                        die("unable to write index file");
        }