Website Summary Files Commits Branches @commit @diff @stats
path: root / ui-repolist.c
diff options
context:
space:
mode:
1 files changed, 29 insertions, 2 deletions
-rw-r--r--ui-repolist.c31
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;