Skip to content

Commit c257bd5

Browse files
pks-tgitster
authored andcommitted
http-push: stop setting up the_repository for each reference
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>
1 parent eea83c0 commit c257bd5

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

http-push.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,6 +1725,7 @@ int cmd_main(int argc, const char **argv)
17251725
int i;
17261726
int new_refs;
17271727
struct ref *ref, *local_refs = NULL;
1728+
const char *gitdir;
17281729

17291730
CALLOC_ARRAY(repo, 1);
17301731

@@ -1787,7 +1788,7 @@ int cmd_main(int argc, const char **argv)
17871788
if (delete_branch && rs.nr != 1)
17881789
die("You must specify only one branch name when deleting a remote branch");
17891790

1790-
setup_git_directory();
1791+
gitdir = setup_git_directory();
17911792

17921793
memset(remote_dir_exists, -1, 256);
17931794

@@ -1941,7 +1942,7 @@ int cmd_main(int argc, const char **argv)
19411942
if (!push_all && !is_null_oid(&ref->old_oid))
19421943
strvec_pushf(&commit_argv, "^%s",
19431944
oid_to_hex(&ref->old_oid));
1944-
repo_init_revisions(the_repository, &revs, setup_git_directory());
1945+
repo_init_revisions(the_repository, &revs, gitdir);
19451946
setup_revisions_from_strvec(&commit_argv, &revs, NULL);
19461947
revs.edge_hint = 0; /* just in case */
19471948

0 commit comments

Comments
 (0)