Diff options
Diffstat (limited to 'source/shared.c')
| -rw-r--r-- | source/shared.c | 21 |
1 file changed, 21 insertions, 0 deletions
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. |
