patch: cgit_add_repo_with_default_branch
Sven Göthel
sgothel at jausoft.com
Thu Jun 4 11:44:38 UTC 2026
patch: cgit_add_repo_with_default_branch
- <https://jausoft.com/cgit/cgit.git/log/?h=cgit_add_repo_with_default_branch>
- and attached
Currently, if defbranch is not `master` and no manual config performed,
repo age is undefined.
This patch reads the default branch from git HEAD if not configured via cgitrc
and uses it in all commands like repo-list age, selected at log etc.
add_repo is called from scan_path early when gathering and caching server
repositories.
~Sven
-------------- next part --------------
From 5ccffc927460e651da10a6b0be2e9786129355bb Mon Sep 17 00:00:00 2001
From: Sven Göthel <sgothel at jausoft.com>
Date: Sat, 30 May 2026 00:56:55 +0200
Subject: cgit: add_repo: Assign default branch from git HEAD to
repo->defbranch if undefined
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Currently, if defbranch is not `master` and no manual config performed,
repo age is undefined.
This patch reads the default branch from git HEAD if not configured via cgitrc
and uses it in all commands like repo-list age, selected at log etc.
add_repo is called from scan_path early when gathering and caching server repositories.
Signed-off-by: Sven Göthel <sgothel at jausoft.com>
diff --git a/scan-tree.c b/scan-tree.c
index c120efe..b701d00 100644
--- a/scan-tree.c
+++ b/scan-tree.c
@@ -79,6 +79,32 @@ static char *xstrrchr(char *s, char *from, int c)
return from < s ? NULL : from;
}
+static char *read_git_head_branch(const char *repo_path) {
+ struct strbuf path = STRBUF_INIT;
+ size_t size;
+ char *line = NULL;
+
+ strbuf_addf(&path, "%s/HEAD", repo_path);
+
+ if (read_first_line(path.buf, &line, &size)) {
+ strbuf_release(&path);
+ free(line);
+ return NULL;
+ }
+ strbuf_release(&path);
+
+ const char *refname;
+ char *result = NULL;
+
+ if (!line || !skip_prefix(line, "ref: refs/heads/", &refname)) {
+ free(line);
+ return NULL;
+ }
+ result = xstrdup(refname);
+ free(line);
+ return result;
+}
+
static void add_repo(const char *base, struct strbuf *path)
{
struct stat st;
@@ -180,6 +206,9 @@ static void add_repo(const char *base, struct strbuf *path)
if (!stat(path->buf, &st))
parse_configfile(path->buf, &scan_tree_repo_config);
+ if (!repo->defbranch)
+ repo->defbranch = read_git_head_branch(repo->path);
+
strbuf_release(&rel);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20260604/5cb43d61/attachment.sig>
More information about the CGit
mailing list