Skip to content

Commit 6f33d8e

Browse files
KarthikNayakgitster
authored andcommitted
builtin: pass repository to sub commands
In 9b1cb50 (builtin: add a repository parameter for builtin functions, 2024-09-13) the repository was passed down to all builtin commands. This allowed the repository to be passed down to lower layers without depending on the global `the_repository` variable. Continue this work by also passing down the repository parameter from the command to sub-commands. This will help pass down the repository to other subsystems and cleanup usage of global variables like 'the_repository' and 'the_hash_algo'. Signed-off-by: Karthik Nayak <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6ea2d9d commit 6f33d8e

17 files changed

+239
-135
lines changed

builtin/bisect.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,15 +1312,17 @@ static int bisect_run(struct bisect_terms *terms, int argc, const char **argv)
13121312
return res;
13131313
}
13141314

1315-
static int cmd_bisect__reset(int argc, const char **argv, const char *prefix UNUSED)
1315+
static int cmd_bisect__reset(int argc, const char **argv, const char *prefix UNUSED,
1316+
struct repository *repo UNUSED)
13161317
{
13171318
if (argc > 1)
13181319
return error(_("'%s' requires either no argument or a commit"),
13191320
"git bisect reset");
13201321
return bisect_reset(argc ? argv[0] : NULL);
13211322
}
13221323

1323-
static int cmd_bisect__terms(int argc, const char **argv, const char *prefix UNUSED)
1324+
static int cmd_bisect__terms(int argc, const char **argv, const char *prefix UNUSED,
1325+
struct repository *repo UNUSED)
13241326
{
13251327
int res;
13261328
struct bisect_terms terms = { 0 };
@@ -1333,7 +1335,8 @@ static int cmd_bisect__terms(int argc, const char **argv, const char *prefix UNU
13331335
return res;
13341336
}
13351337

1336-
static int cmd_bisect__start(int argc, const char **argv, const char *prefix UNUSED)
1338+
static int cmd_bisect__start(int argc, const char **argv, const char *prefix UNUSED,
1339+
struct repository *repo UNUSED)
13371340
{
13381341
int res;
13391342
struct bisect_terms terms = { 0 };
@@ -1344,7 +1347,8 @@ static int cmd_bisect__start(int argc, const char **argv, const char *prefix UNU
13441347
return res;
13451348
}
13461349

1347-
static int cmd_bisect__next(int argc, const char **argv UNUSED, const char *prefix)
1350+
static int cmd_bisect__next(int argc, const char **argv UNUSED, const char *prefix,
1351+
struct repository *repo UNUSED)
13481352
{
13491353
int res;
13501354
struct bisect_terms terms = { 0 };
@@ -1358,12 +1362,15 @@ static int cmd_bisect__next(int argc, const char **argv UNUSED, const char *pref
13581362
return res;
13591363
}
13601364

1361-
static int cmd_bisect__log(int argc UNUSED, const char **argv UNUSED, const char *prefix UNUSED)
1365+
static int cmd_bisect__log(int argc UNUSED, const char **argv UNUSED,
1366+
const char *prefix UNUSED,
1367+
struct repository *repo UNUSED)
13621368
{
13631369
return bisect_log();
13641370
}
13651371

1366-
static int cmd_bisect__replay(int argc, const char **argv, const char *prefix UNUSED)
1372+
static int cmd_bisect__replay(int argc, const char **argv, const char *prefix UNUSED,
1373+
struct repository *repo UNUSED)
13671374
{
13681375
int res;
13691376
struct bisect_terms terms = { 0 };
@@ -1376,7 +1383,8 @@ static int cmd_bisect__replay(int argc, const char **argv, const char *prefix UN
13761383
return res;
13771384
}
13781385

1379-
static int cmd_bisect__skip(int argc, const char **argv, const char *prefix UNUSED)
1386+
static int cmd_bisect__skip(int argc, const char **argv, const char *prefix UNUSED,
1387+
struct repository *repo UNUSED)
13801388
{
13811389
int res;
13821390
struct bisect_terms terms = { 0 };
@@ -1388,7 +1396,8 @@ static int cmd_bisect__skip(int argc, const char **argv, const char *prefix UNUS
13881396
return res;
13891397
}
13901398

1391-
static int cmd_bisect__visualize(int argc, const char **argv, const char *prefix UNUSED)
1399+
static int cmd_bisect__visualize(int argc, const char **argv, const char *prefix UNUSED,
1400+
struct repository *repo UNUSED)
13921401
{
13931402
int res;
13941403
struct bisect_terms terms = { 0 };
@@ -1399,7 +1408,8 @@ static int cmd_bisect__visualize(int argc, const char **argv, const char *prefix
13991408
return res;
14001409
}
14011410

1402-
static int cmd_bisect__run(int argc, const char **argv, const char *prefix UNUSED)
1411+
static int cmd_bisect__run(int argc, const char **argv, const char *prefix UNUSED,
1412+
struct repository *repo UNUSED)
14031413
{
14041414
int res;
14051415
struct bisect_terms terms = { 0 };
@@ -1415,7 +1425,7 @@ static int cmd_bisect__run(int argc, const char **argv, const char *prefix UNUSE
14151425
int cmd_bisect(int argc,
14161426
const char **argv,
14171427
const char *prefix,
1418-
struct repository *repo UNUSED)
1428+
struct repository *repo)
14191429
{
14201430
int res = 0;
14211431
parse_opt_subcommand_fn *fn = NULL;
@@ -1451,7 +1461,7 @@ int cmd_bisect(int argc,
14511461
} else {
14521462
argc--;
14531463
argv++;
1454-
res = fn(argc, argv, prefix);
1464+
res = fn(argc, argv, prefix, repo);
14551465
}
14561466

14571467
return is_bisect_success(res) ? 0 : -res;

builtin/bundle.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ static int parse_options_cmd_bundle(int argc,
6767
return argc;
6868
}
6969

70-
static int cmd_bundle_create(int argc, const char **argv, const char *prefix) {
70+
static int cmd_bundle_create(int argc, const char **argv, const char *prefix,
71+
struct repository *repo UNUSED) {
7172
struct strvec pack_opts = STRVEC_INIT;
7273
int version = -1;
7374
int ret;
@@ -123,7 +124,8 @@ static int open_bundle(const char *path, struct bundle_header *header,
123124
return read_bundle_header(path, header);
124125
}
125126

126-
static int cmd_bundle_verify(int argc, const char **argv, const char *prefix) {
127+
static int cmd_bundle_verify(int argc, const char **argv, const char *prefix,
128+
struct repository *repo UNUSED) {
127129
struct bundle_header header = BUNDLE_HEADER_INIT;
128130
int bundle_fd = -1;
129131
int quiet = 0;
@@ -164,7 +166,8 @@ static int cmd_bundle_verify(int argc, const char **argv, const char *prefix) {
164166
return ret;
165167
}
166168

167-
static int cmd_bundle_list_heads(int argc, const char **argv, const char *prefix) {
169+
static int cmd_bundle_list_heads(int argc, const char **argv, const char *prefix,
170+
struct repository *repo UNUSED) {
168171
struct bundle_header header = BUNDLE_HEADER_INIT;
169172
int bundle_fd = -1;
170173
int ret;
@@ -189,7 +192,8 @@ static int cmd_bundle_list_heads(int argc, const char **argv, const char *prefix
189192
return ret;
190193
}
191194

192-
static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix) {
195+
static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix,
196+
struct repository *repo UNUSED) {
193197
struct bundle_header header = BUNDLE_HEADER_INIT;
194198
int bundle_fd = -1;
195199
int ret;
@@ -231,7 +235,7 @@ static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix)
231235
int cmd_bundle(int argc,
232236
const char **argv,
233237
const char *prefix,
234-
struct repository *repo UNUSED)
238+
struct repository *repo)
235239
{
236240
parse_opt_subcommand_fn *fn = NULL;
237241
struct option options[] = {
@@ -247,5 +251,5 @@ int cmd_bundle(int argc,
247251

248252
packet_trace_identity("bundle");
249253

250-
return !!fn(argc, argv, prefix);
254+
return !!fn(argc, argv, prefix, repo);
251255
}

builtin/commit-graph.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ static struct option *add_common_options(struct option *to)
6262
return parse_options_concat(common_opts, to);
6363
}
6464

65-
static int graph_verify(int argc, const char **argv, const char *prefix)
65+
static int graph_verify(int argc, const char **argv, const char *prefix,
66+
struct repository *repo UNUSED)
6667
{
6768
struct commit_graph *graph = NULL;
6869
struct object_directory *odb = NULL;
@@ -214,7 +215,8 @@ static int git_commit_graph_write_config(const char *var, const char *value,
214215
return 0;
215216
}
216217

217-
static int graph_write(int argc, const char **argv, const char *prefix)
218+
static int graph_write(int argc, const char **argv, const char *prefix,
219+
struct repository *repo UNUSED)
218220
{
219221
struct string_list pack_indexes = STRING_LIST_INIT_DUP;
220222
struct strbuf buf = STRBUF_INIT;
@@ -333,7 +335,7 @@ static int graph_write(int argc, const char **argv, const char *prefix)
333335
int cmd_commit_graph(int argc,
334336
const char **argv,
335337
const char *prefix,
336-
struct repository *repo UNUSED)
338+
struct repository *repo)
337339
{
338340
parse_opt_subcommand_fn *fn = NULL;
339341
struct option builtin_commit_graph_options[] = {
@@ -352,5 +354,5 @@ int cmd_commit_graph(int argc,
352354
builtin_commit_graph_usage, 0);
353355
FREE_AND_NULL(options);
354356

355-
return fn(argc, argv, prefix);
357+
return fn(argc, argv, prefix, repo);
356358
}

builtin/config.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,8 @@ static void display_options_init(struct config_display_options *opts)
826826
}
827827
}
828828

829-
static int cmd_config_list(int argc, const char **argv, const char *prefix)
829+
static int cmd_config_list(int argc, const char **argv, const char *prefix,
830+
struct repository *repo UNUSED)
830831
{
831832
struct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT;
832833
struct config_display_options display_opts = CONFIG_DISPLAY_OPTIONS_INIT;
@@ -861,7 +862,8 @@ static int cmd_config_list(int argc, const char **argv, const char *prefix)
861862
return 0;
862863
}
863864

864-
static int cmd_config_get(int argc, const char **argv, const char *prefix)
865+
static int cmd_config_get(int argc, const char **argv, const char *prefix,
866+
struct repository *repo UNUSED)
865867
{
866868
struct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT;
867869
struct config_display_options display_opts = CONFIG_DISPLAY_OPTIONS_INIT;
@@ -915,7 +917,8 @@ static int cmd_config_get(int argc, const char **argv, const char *prefix)
915917
return ret;
916918
}
917919

918-
static int cmd_config_set(int argc, const char **argv, const char *prefix)
920+
static int cmd_config_set(int argc, const char **argv, const char *prefix,
921+
struct repository *repo UNUSED)
919922
{
920923
struct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT;
921924
const char *value_pattern = NULL, *comment_arg = NULL;
@@ -973,7 +976,8 @@ static int cmd_config_set(int argc, const char **argv, const char *prefix)
973976
return ret;
974977
}
975978

976-
static int cmd_config_unset(int argc, const char **argv, const char *prefix)
979+
static int cmd_config_unset(int argc, const char **argv, const char *prefix,
980+
struct repository *repo UNUSED)
977981
{
978982
struct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT;
979983
const char *value_pattern = NULL;
@@ -1010,7 +1014,8 @@ static int cmd_config_unset(int argc, const char **argv, const char *prefix)
10101014
return ret;
10111015
}
10121016

1013-
static int cmd_config_rename_section(int argc, const char **argv, const char *prefix)
1017+
static int cmd_config_rename_section(int argc, const char **argv, const char *prefix,
1018+
struct repository *repo UNUSED)
10141019
{
10151020
struct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT;
10161021
struct option opts[] = {
@@ -1039,7 +1044,8 @@ static int cmd_config_rename_section(int argc, const char **argv, const char *pr
10391044
return ret;
10401045
}
10411046

1042-
static int cmd_config_remove_section(int argc, const char **argv, const char *prefix)
1047+
static int cmd_config_remove_section(int argc, const char **argv, const char *prefix,
1048+
struct repository *repo UNUSED)
10431049
{
10441050
struct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT;
10451051
struct option opts[] = {
@@ -1099,7 +1105,8 @@ static int show_editor(struct config_location_options *opts)
10991105
return 0;
11001106
}
11011107

1102-
static int cmd_config_edit(int argc, const char **argv, const char *prefix)
1108+
static int cmd_config_edit(int argc, const char **argv, const char *prefix,
1109+
struct repository *repo UNUSED)
11031110
{
11041111
struct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT;
11051112
struct option opts[] = {
@@ -1395,7 +1402,7 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix)
13951402
int cmd_config(int argc,
13961403
const char **argv,
13971404
const char *prefix,
1398-
struct repository *repo UNUSED)
1405+
struct repository *repo)
13991406
{
14001407
parse_opt_subcommand_fn *subcommand = NULL;
14011408
struct option subcommand_opts[] = {
@@ -1422,7 +1429,7 @@ int cmd_config(int argc,
14221429
if (subcommand) {
14231430
argc = parse_options(argc, argv, prefix, subcommand_opts, builtin_config_usage,
14241431
PARSE_OPT_SUBCOMMAND_OPTIONAL|PARSE_OPT_KEEP_UNKNOWN_OPT);
1425-
return subcommand(argc, argv, prefix);
1432+
return subcommand(argc, argv, prefix, repo);
14261433
}
14271434

14281435
return cmd_config_actions(argc, argv, prefix);

builtin/gc.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,7 +1561,8 @@ static int task_option_parse(const struct option *opt UNUSED,
15611561
return 0;
15621562
}
15631563

1564-
static int maintenance_run(int argc, const char **argv, const char *prefix)
1564+
static int maintenance_run(int argc, const char **argv, const char *prefix,
1565+
struct repository *repo UNUSED)
15651566
{
15661567
int i;
15671568
struct maintenance_run_opts opts = MAINTENANCE_RUN_OPTS_INIT;
@@ -1623,7 +1624,8 @@ static char const * const builtin_maintenance_register_usage[] = {
16231624
NULL
16241625
};
16251626

1626-
static int maintenance_register(int argc, const char **argv, const char *prefix)
1627+
static int maintenance_register(int argc, const char **argv, const char *prefix,
1628+
struct repository *repo UNUSED)
16271629
{
16281630
char *config_file = NULL;
16291631
struct option options[] = {
@@ -1687,7 +1689,8 @@ static char const * const builtin_maintenance_unregister_usage[] = {
16871689
NULL
16881690
};
16891691

1690-
static int maintenance_unregister(int argc, const char **argv, const char *prefix)
1692+
static int maintenance_unregister(int argc, const char **argv, const char *prefix,
1693+
struct repository *repo UNUSED)
16911694
{
16921695
int force = 0;
16931696
char *config_file = NULL;
@@ -2917,7 +2920,8 @@ static const char *const builtin_maintenance_start_usage[] = {
29172920
NULL
29182921
};
29192922

2920-
static int maintenance_start(int argc, const char **argv, const char *prefix)
2923+
static int maintenance_start(int argc, const char **argv, const char *prefix,
2924+
struct repository *repo)
29212925
{
29222926
struct maintenance_start_opts opts = { 0 };
29232927
struct option options[] = {
@@ -2940,7 +2944,7 @@ static int maintenance_start(int argc, const char **argv, const char *prefix)
29402944
if (update_background_schedule(&opts, 1))
29412945
die(_("failed to set up maintenance schedule"));
29422946

2943-
if (maintenance_register(ARRAY_SIZE(register_args)-1, register_args, NULL))
2947+
if (maintenance_register(ARRAY_SIZE(register_args)-1, register_args, NULL, repo))
29442948
warning(_("failed to add repo to global config"));
29452949
return 0;
29462950
}
@@ -2950,7 +2954,8 @@ static const char *const builtin_maintenance_stop_usage[] = {
29502954
NULL
29512955
};
29522956

2953-
static int maintenance_stop(int argc, const char **argv, const char *prefix)
2957+
static int maintenance_stop(int argc, const char **argv, const char *prefix,
2958+
struct repository *repo UNUSED)
29542959
{
29552960
struct option options[] = {
29562961
OPT_END()
@@ -2970,7 +2975,7 @@ static const char * const builtin_maintenance_usage[] = {
29702975
int cmd_maintenance(int argc,
29712976
const char **argv,
29722977
const char *prefix,
2973-
struct repository *repo UNUSED)
2978+
struct repository *repo)
29742979
{
29752980
parse_opt_subcommand_fn *fn = NULL;
29762981
struct option builtin_maintenance_options[] = {
@@ -2984,5 +2989,5 @@ int cmd_maintenance(int argc,
29842989

29852990
argc = parse_options(argc, argv, prefix, builtin_maintenance_options,
29862991
builtin_maintenance_usage, 0);
2987-
return fn(argc, argv, prefix);
2992+
return fn(argc, argv, prefix, repo);
29882993
}

builtin/hook.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ static const char * const builtin_hook_run_usage[] = {
1919
NULL
2020
};
2121

22-
static int run(int argc, const char **argv, const char *prefix)
22+
static int run(int argc, const char **argv, const char *prefix,
23+
struct repository *repo UNUSED)
2324
{
2425
int i;
2526
struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
@@ -70,7 +71,7 @@ static int run(int argc, const char **argv, const char *prefix)
7071
int cmd_hook(int argc,
7172
const char **argv,
7273
const char *prefix,
73-
struct repository *repo UNUSED)
74+
struct repository *repo)
7475
{
7576
parse_opt_subcommand_fn *fn = NULL;
7677
struct option builtin_hook_options[] = {
@@ -81,5 +82,5 @@ int cmd_hook(int argc,
8182
argc = parse_options(argc, argv, NULL, builtin_hook_options,
8283
builtin_hook_usage, 0);
8384

84-
return fn(argc, argv, prefix);
85+
return fn(argc, argv, prefix, repo);
8586
}

0 commit comments

Comments
 (0)