]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/send-pack: stop using `the_repository`
authorUsman Akinyemi <usmanakinyemi202@gmail.com>
Fri, 7 Mar 2025 23:35:03 +0000 (05:05 +0530)
committerJunio C Hamano <gitster@pobox.com>
Sat, 8 Mar 2025 00:52:01 +0000 (16:52 -0800)
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>
builtin/send-pack.c
t/t5400-send-pack.sh

index 8d461008e2e860a3de91a69412d66dcbde4d7b96..c6e0e9d0518634869b5770fca3e0b30fff8a6703 100644 (file)
@@ -1,4 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "hex.h"
@@ -151,7 +150,7 @@ static int send_pack_config(const char *k, const char *v,
 int cmd_send_pack(int argc,
                  const char **argv,
                  const char *prefix,
-                 struct repository *repo UNUSED)
+                 struct repository *repo)
 {
        struct refspec rs = REFSPEC_INIT_PUSH;
        const char *remote_name = NULL;
@@ -212,7 +211,7 @@ int cmd_send_pack(int argc,
                OPT_END()
        };
 
-       git_config(send_pack_config, NULL);
+       repo_config(repo, send_pack_config, NULL);
        argc = parse_options(argc, argv, prefix, options, send_pack_usage, 0);
        if (argc > 0) {
                dest = argv[0];
@@ -317,7 +316,7 @@ int cmd_send_pack(int argc,
        set_ref_status_for_push(remote_refs, args.send_mirror,
                args.force_update);
 
-       ret = send_pack(the_repository, &args, fd, conn, remote_refs, &extra_have);
+       ret = send_pack(repo, &args, fd, conn, remote_refs, &extra_have);
 
        if (helper_status)
                print_helper_status(remote_refs);
index 3f81f16e1335ce6e7f3c8e8d164e140e26049e6f..8f018d2f235cf9a40ca77bc774058c0cdac15147 100755 (executable)
@@ -55,6 +55,13 @@ test_expect_success setup '
        echo Rebase &&
        git log'
 
+test_expect_success 'send-pack does not crash with -h' '
+       test_expect_code 129 git send-pack -h >usage &&
+       test_grep "[Uu]sage: git send-pack " usage &&
+       test_expect_code 129 nongit git send-pack -h >usage &&
+       test_grep "[Uu]sage: git send-pack " usage
+'
+
 test_expect_success 'pack the source repository' '
        git repack -a -d &&
        git prune