From b4a43dfa1eed8722eda8877eb7f64c9314c1e7d9 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 31 Oct 2026 13:36:01 -0700 Subject: Hand back the fallback branch rather than a copy --- source/cgit.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'source/cgit.c') diff --git a/source/cgit.c b/source/cgit.c index c1c9fbc..d6fc0bc 100644 --- a/source/cgit.c +++ b/source/cgit.c @@ -926,22 +926,13 @@ static int find_current_ref(const struct reference *ref, void *data) static char *find_default_branch(struct cgit_repo *repo) { - struct refmatch match; - char *ref; + struct refmatch match = { .wanted = repo->defbranch }; - match.wanted = repo->defbranch; - match.first = NULL; - match.found = 0; refs_for_each_branch_ref(get_main_ref_store(the_repository), find_current_ref, &match); - if (match.found) - ref = match.wanted; - else - ref = match.first; - if (ref) - ref = xstrdup(ref); + if (!match.found) + return match.first; free(match.first); - - return ref; + return xstrdup(match.wanted); } static char *guess_defbranch(void) -- cgit