From 97abaab5f6390ccb3e55c8b63c9087be7b1fc1d7 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Fri, 17 May 2024 10:19:09 +0200 Subject: refs: drop `git_default_branch_name()` The `git_default_branch_name()` function is a thin wrapper around `repo_default_branch_name()` with two differences: - We implicitly rely on `the_repository`. - We cache the default branch name. None of the callsites of `git_default_branch_name()` are hot code paths though, so the caching of the branch name is not really required. Refactor the callsites to use `repo_default_branch_name()` instead and drop `git_default_branch_name()`, thus getting rid of one more case where we rely on `the_repository`. Signed-off-by: Patrick Steinhardt Signed-off-by: Junio C Hamano --- setup.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'setup.c') diff --git a/setup.c b/setup.c index fec6bfd5fa..481b57d523 100644 --- a/setup.c +++ b/setup.c @@ -2046,6 +2046,7 @@ void create_reference_database(unsigned int ref_storage_format, const char *initial_branch, int quiet) { struct strbuf err = STRBUF_INIT; + char *to_free = NULL; int reinit = is_reinit(); repo_set_ref_storage_format(the_repository, ref_storage_format); @@ -2060,7 +2061,8 @@ void create_reference_database(unsigned int ref_storage_format, char *ref; if (!initial_branch) - initial_branch = git_default_branch_name(quiet); + initial_branch = to_free = + repo_default_branch_name(the_repository, quiet); ref = xstrfmt("refs/heads/%s", initial_branch); if (check_refname_format(ref, 0) < 0) @@ -2077,6 +2079,7 @@ void create_reference_database(unsigned int ref_storage_format, initial_branch); strbuf_release(&err); + free(to_free); } static int create_default_files(const char *template_path, -- cgit v1.3-5-g9baa