From 8a7aa400143f3e95b3ecd18f19e21b526d6a419d Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 31 Oct 2026 19:47:34 -1000 Subject: Read the description file without repo.desc Only a scanned repository fell back to its description file, so one listed in cgitrc without repo.desc showed "[no description]" however its file read. repo.desc may follow repo.path, so the file is read where a page shows the description, which also spares every other request the reads. --- source/shared.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'source/shared.c') diff --git a/source/shared.c b/source/shared.c index 1cfe4b0..c189b11 100644 --- a/source/shared.c +++ b/source/shared.c @@ -14,6 +14,11 @@ #define MAX_FIRST_LINE_READ (1024 * 64) +// Git writes this line into the description file of every repository it +// creates, so a repository still carrying it gets cgit's own default instead. +static const char *default_git_desc = + "Unnamed repository; edit this file 'description' to name the repository."; + struct cgit_repolist cgit_repolist; struct cgit_context ctx; char cgit_default_repo_desc[] = "[no description]"; @@ -325,6 +330,22 @@ char *cgit_strdup_first_line(const char *text) return line; } +void cgit_read_repo_desc(struct cgit_repo *repo) +{ + struct strbuf path = STRBUF_INIT; + char *desc = NULL; + + if (repo->desc != cgit_default_repo_desc || !repo->path || repo->desc_read) + return; + repo->desc_read = 1; + strbuf_addf(&path, "%s/description", repo->path); + if (!cgit_read_first_line(path.buf, &desc) && strcmp(desc, default_git_desc)) + repo->desc = desc; + else + free(desc); + strbuf_release(&path); +} + /* * The lead-byte ranges fold in the overlong, surrogate and out-of-range * cases, so 0 is the only error signal a caller needs. -- cgit 2.12.1