diff options
| author | Elis Eriksson <spelis.tech@gmail.com> | 2026-07-01 10:40:03 +0200 |
|---|---|---|
| committer | Elis Eriksson <spelis.tech@gmail.com> | 2026-07-01 10:40:03 +0200 |
| commit | a16b9477d951ae45ce6d8efc13d2dbc30d54dbdf (patch) | |
| tree | b7ae283e65c399e5855d9cc192eb52aa340250e1 | |
| parent | d1375449de5501fd2f65146e5a524eaa2d3f28a6 (diff) | |
| download | cgit-a16b9477d951ae45ce6d8efc13d2dbc30d54dbdf.tar cgit-a16b9477d951ae45ce6d8efc13d2dbc30d54dbdf.tar.gz cgit-a16b9477d951ae45ce6d8efc13d2dbc30d54dbdf.tar.bz2 cgit-a16b9477d951ae45ce6d8efc13d2dbc30d54dbdf.tar.lz cgit-a16b9477d951ae45ce6d8efc13d2dbc30d54dbdf.tar.xz cgit-a16b9477d951ae45ce6d8efc13d2dbc30d54dbdf.tar.zst cgit-a16b9477d951ae45ce6d8efc13d2dbc30d54dbdf.zip | |
better fallback for detecting default branch. will still default to zero if it really cant find mtime
| -rw-r--r-- | ui-repolist.c | 38 |
1 files 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 <linux/limits.h> +#include <stdio.h> +#include <string.h> #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); |
