midx-write: pass down repository to `write_midx_file[_only]`

In a previous commit, we passed the repository field to all subcommands in the `builtin/` directory. Utilize this to pass the repository field down to the `write_midx_file[_only]` functions to remove the usage of `the_repository` global variables. With this, all usage of global variables in `midx-write.c` is removed, hence, remove the `USE_THE_REPOSITORY_VARIABLE` guard from the file. Signed-off-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Karthik Nayak committed Nov 27, 2024 at 17:28 UTC 2fed09aa9b82e4710fb4049e18280df8270eb0b2
4 files changed +17 -23
builtin/multi-pack-index.c
+3 -3
@@ -120,7 +120,7 @@ static void read_packs_from_stdin(struct string_list *to)
120
121 static int cmd_multi_pack_index_write(int argc, const char **argv,
122 const char *prefix,
123 - struct repository *repo UNUSED)
123 + struct repository *repo)
124 {
125 struct option *options;
126 static struct option builtin_multi_pack_index_write_options[] = {
@@ -165,7 +165,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
165
166 read_packs_from_stdin(&packs);
167
168 - ret = write_midx_file_only(opts.object_dir, &packs,
168 + ret = write_midx_file_only(repo, opts.object_dir, &packs,
169 opts.preferred_pack,
170 opts.refs_snapshot, opts.flags);
171
@@ -176,7 +176,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
176
177 }
178
179 - ret = write_midx_file(opts.object_dir, opts.preferred_pack,
179 + ret = write_midx_file(repo, opts.object_dir, opts.preferred_pack,
180 opts.refs_snapshot, opts.flags);
181
182 free(opts.refs_snapshot);
builtin/repack.c
+1 -1
@@ -1569,7 +1569,7 @@ int cmd_repack(int argc,
1569 unsigned flags = 0;
1570 if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX_WRITE_INCREMENTAL, 0))
1571 flags |= MIDX_WRITE_INCREMENTAL;
1572 - write_midx_file(repo_get_object_directory(the_repository),
1572 + write_midx_file(the_repository, repo_get_object_directory(the_repository),
1573 NULL, NULL, flags);
1574 }
1575
midx-write.c
+9 -13
@@ -1,5 +1,3 @@
1 -#define USE_THE_REPOSITORY_VARIABLE
2 -
1 #include "git-compat-util.h"
2 #include "abspath.h"
3 #include "config.h"
@@ -1505,24 +1503,22 @@ cleanup:
1503 return result;
1504 }
1505
1508 -int write_midx_file(const char *object_dir,
1506 +int write_midx_file(struct repository *r, const char *object_dir,
1507 const char *preferred_pack_name,
1510 - const char *refs_snapshot,
1511 - unsigned flags)
1508 + const char *refs_snapshot, unsigned flags)
1509 {
1513 - return write_midx_internal(the_repository, object_dir, NULL, NULL,
1514 - preferred_pack_name, refs_snapshot, flags);
1510 + return write_midx_internal(r, object_dir, NULL, NULL,
1511 + preferred_pack_name, refs_snapshot,
1512 + flags);
1513 }
1514
1517 -int write_midx_file_only(const char *object_dir,
1515 +int write_midx_file_only(struct repository *r, const char *object_dir,
1516 struct string_list *packs_to_include,
1517 const char *preferred_pack_name,
1520 - const char *refs_snapshot,
1521 - unsigned flags)
1518 + const char *refs_snapshot, unsigned flags)
1519 {
1523 - return write_midx_internal(the_repository, object_dir, packs_to_include,
1524 - NULL, preferred_pack_name, refs_snapshot,
1525 - flags);
1520 + return write_midx_internal(r, object_dir, packs_to_include, NULL,
1521 + preferred_pack_name, refs_snapshot, flags);
1522 }
1523
1524 int expire_midx_packs(struct repository *r, const char *object_dir, unsigned flags)
midx.h
+4 -6
@@ -123,15 +123,13 @@ int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, i
123 * Variant of write_midx_file which writes a MIDX containing only the packs
124 * specified in packs_to_include.
125 */
126 -int write_midx_file(const char *object_dir,
127 - const char *preferred_pack_name,
128 - const char *refs_snapshot,
126 +int write_midx_file(struct repository *r, const char *object_dir,
127 + const char *preferred_pack_name, const char *refs_snapshot,
128 unsigned flags);
130 -int write_midx_file_only(const char *object_dir,
129 +int write_midx_file_only(struct repository *r, const char *object_dir,
130 struct string_list *packs_to_include,
131 const char *preferred_pack_name,
133 - const char *refs_snapshot,
134 - unsigned flags);
132 + const char *refs_snapshot, unsigned flags);
133 void clear_midx_file(struct repository *r);
134 int verify_midx_file(struct repository *r, const char *object_dir, unsigned flags);
135 int expire_midx_packs(struct repository *r, const char *object_dir, unsigned flags);