builtin/send-pack: stop using `the_repository`

Remove the_repository global variable in favor of the repository argument that gets passed in "builtin/send-pack.c". When `-h` is passed to the command outside a Git repository, the `run_builtin()` will call the `cmd_send_pack()` function with `repo` set to NULL and then early in the function, `parse_options()` call will give the options help and exit. Mentored-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Usman Akinyemi committed Mar 8, 2025 at 05:05 UTC 1c14b1aedec6e9307e0c73276b8c1c283413ea41
2 files changed +10 -4
builtin/send-pack.c
+3 -4
@@ -1,4 +1,3 @@
1 -#define USE_THE_REPOSITORY_VARIABLE
1 #include "builtin.h"
2 #include "config.h"
3 #include "hex.h"
@@ -151,7 +150,7 @@ static int send_pack_config(const char *k, const char *v,
150 int cmd_send_pack(int argc,
151 const char **argv,
152 const char *prefix,
154 - struct repository *repo UNUSED)
153 + struct repository *repo)
154 {
155 struct refspec rs = REFSPEC_INIT_PUSH;
156 const char *remote_name = NULL;
@@ -212,7 +211,7 @@ int cmd_send_pack(int argc,
211 OPT_END()
212 };
213
215 - git_config(send_pack_config, NULL);
214 + repo_config(repo, send_pack_config, NULL);
215 argc = parse_options(argc, argv, prefix, options, send_pack_usage, 0);
216 if (argc > 0) {
217 dest = argv[0];
@@ -317,7 +316,7 @@ int cmd_send_pack(int argc,
316 set_ref_status_for_push(remote_refs, args.send_mirror,
317 args.force_update);
318
320 - ret = send_pack(the_repository, &args, fd, conn, remote_refs, &extra_have);
319 + ret = send_pack(repo, &args, fd, conn, remote_refs, &extra_have);
320
321 if (helper_status)
322 print_helper_status(remote_refs);
t/t5400-send-pack.sh
+7
@@ -55,6 +55,13 @@ test_expect_success setup '
55 echo Rebase &&
56 git log'
57
58 +test_expect_success 'send-pack does not crash with -h' '
59 + test_expect_code 129 git send-pack -h >usage &&
60 + test_grep "[Uu]sage: git send-pack " usage &&
61 + test_expect_code 129 nongit git send-pack -h >usage &&
62 + test_grep "[Uu]sage: git send-pack " usage
63 +'
64 +
65 test_expect_success 'pack the source repository' '
66 git repack -a -d &&
67 git prune