From a16b9477d951ae45ce6d8efc13d2dbc30d54dbdf Mon Sep 17 00:00:00 2001 From: Elis Eriksson Date: Wed, 1 Jul 2026 10:40:03 +0200 Subject: better fallback for detecting default branch. will still default to zero if it really cant find mtime --- ui-repolist.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/ui-repolist.c b/ui-repolist.c index 59a4fbb..77e6387 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -6,12 +6,15 @@ * (see COPYING for full license text) */ +#include +#include +#include #define USE_THE_REPOSITORY_VARIABLE -#include "ui-repolist.h" #include "cgit.h" #include "html.h" #include "lang.h" +#include "ui-repolist.h" #include "ui-shared.h" static time_t read_agefile(const char *path) { @@ -34,6 +37,36 @@ static time_t read_agefile(const char *path) { return result; } +time_t get_default_branch(const char *gitdir) { + char head_path[PATH_MAX]; + char ref_path[PATH_MAX]; + FILE *f; + char buf[256]; + struct stat s; + + snprintf(head_path, sizeof(head_path), "%sHEAD", gitdir); + + f = fopen(head_path, "r"); + if (!f) + return 0; + + if (!fgets(buf, sizeof(buf), f)) + return 0; + + fclose(f); + + if (strncmp("ref: ", buf, 5) != 0) + return 0; + char *ref = buf + 5; + ref[strcspn(ref, "\n")] = '\0'; + + snprintf(ref_path, sizeof(ref_path), "%s%s", gitdir, ref); + if (stat(ref_path, &s) == 0) { + return s.st_mtime; + } + return 0; +} + static int get_repo_modtime(const struct cgit_repo *repo, time_t *mtime) { struct strbuf path = STRBUF_INIT; struct stat s; @@ -68,9 +101,8 @@ static int get_repo_modtime(const struct cgit_repo *repo, time_t *mtime) { r->mtime = *mtime; goto end; } + *mtime = get_default_branch(r->path); - *mtime = 0; - r->mtime = *mtime; end: strbuf_release(&path); return (r->mtime != 0); -- cgit v1.3-7-ge9ab