diff options
| Commit | d82d775c8ade39ec686e566908e3460c97697d23 (patch) | |
|---|---|---|
| Author | 2026-10-04 17:22:08 +0300 | |
| Committer | 2026-10-04 17:22:08 +0300 | |
| Files | 831b492be902a0d8732d40af1175aeb60c4ef4c8 /ui-repolist.c | |
| cgit-d82d775c8ade39ec686e566908e3460c97697d23.tar cgit-d82d775c8ade39ec686e566908e3460c97697d23.tar.gz cgit-d82d775c8ade39ec686e566908e3460c97697d23.zip | ||
| Parent | 043152ca6bf882f89bae8d06034ba2711cf07209 (diff) | |
ui-repolist: Read HEAD file when deciding on the default branch HEAD sy/customisations
1 files changed, 29 insertions, 2 deletions
| -rw-r--r-- | ui-repolist.c | 31 |
diff --git a/ui-repolist.c b/ui-repolist.c index 87fc40c..57110ee 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -32,6 +32,33 @@ static time_t read_agefile(const char *path) return result; } +static void add_repo_defbranch(const struct cgit_repo *repo, struct strbuf *result_path) { + struct strbuf path = STRBUF_INIT; + struct stat s; + char *ref, *refname; + size_t ref_size; + + if (repo->defbranch) { + strbuf_addf(result_path, "%s", repo->defbranch); + goto add_repo_defbranch_end; + } + + strbuf_addf(&path, "%s/HEAD", repo->path); + if (stat(path.buf, &s) != 0 || read_first_line(path.buf, &ref, &ref_size) != 0) { + strbuf_addf(result_path, "%s", "master"); + goto add_repo_defbranch_end; + } + + if (!skip_prefix(ref, "ref: refs/heads/", &refname) && !skip_prefix(ref, "refs/heads/", &refname)) + strbuf_addf(result_path, "%s", "master"); + else + strbuf_addf(result_path, "%s", refname); + +add_repo_defbranch_end: + free(ref); + strbuf_release(&path); +} + static int get_repo_modtime(const struct cgit_repo *repo, time_t *mtime) { struct strbuf path = STRBUF_INIT; @@ -52,8 +79,8 @@ static int get_repo_modtime(const struct cgit_repo *repo, time_t *mtime) } strbuf_reset(&path); - strbuf_addf(&path, "%s/refs/heads/%s", repo->path, - repo->defbranch ? repo->defbranch : "master"); + strbuf_addf(&path, "%s/refs/heads/", repo->path); + add_repo_defbranch(repo, &path); if (stat(path.buf, &s) == 0) { *mtime = s.st_mtime; r->mtime = *mtime; |
