]> git.ipfire.org Git - thirdparty/git.git/commitdiff
http-push: stop setting up `the_repository` for each reference
authorPatrick Steinhardt <ps@pks.im>
Wed, 19 Nov 2025 07:50:57 +0000 (08:50 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 25 Nov 2025 20:16:00 +0000 (12:16 -0800)
When pushing references via HTTP we call `repo_init_revisions()` in a
loop for each reference that we're about to push. As third argument we
pass the result of `setup_git_directory()`, which causes us to
reinitialize the repository every single time.

This is an obvious waste of compute, as the repository that we're
working in will never change across any of the initializations. The only
reason that we do this is to retrieve the directory of the repository.
Furthermore, this is about to create issues in a subsequent commit,
where reinitializing the repository will cause a `BUG()`.

Address this by storing the Git directory in a variable instead so that
we don't have to call the function repeatedly.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
http-push.c

index a1c01e3b9b93a3e2be1311521fc69c2568748cd6..a48ca2379965677358958b43c03216aa7159dbb2 100644 (file)
@@ -1725,6 +1725,7 @@ int cmd_main(int argc, const char **argv)
        int i;
        int new_refs;
        struct ref *ref, *local_refs = NULL;
+       const char *gitdir;
 
        CALLOC_ARRAY(repo, 1);
 
@@ -1787,7 +1788,7 @@ int cmd_main(int argc, const char **argv)
        if (delete_branch && rs.nr != 1)
                die("You must specify only one branch name when deleting a remote branch");
 
-       setup_git_directory();
+       gitdir = setup_git_directory();
 
        memset(remote_dir_exists, -1, 256);
 
@@ -1941,7 +1942,7 @@ int cmd_main(int argc, const char **argv)
                if (!push_all && !is_null_oid(&ref->old_oid))
                        strvec_pushf(&commit_argv, "^%s",
                                     oid_to_hex(&ref->old_oid));
-               repo_init_revisions(the_repository, &revs, setup_git_directory());
+               repo_init_revisions(the_repository, &revs, gitdir);
                setup_revisions_from_strvec(&commit_argv, &revs, NULL);
                revs.edge_hint = 0; /* just in case */