From: glogow at fbihome.de (Jan-Marek Glogowski)
Subject: [PATCH] Support .git/category files
Date: Thu, 5 Mar 2015 18:15:04 +0100 [thread overview]
Message-ID: <1425575704-15107-1-git-send-email-glogow@fbihome.de> (raw)
Gitweb reads .git/category to set a repository section for
grouping. This handles the file in the same way a .git/description
file is handled.
The file section takes precedence over the ctx.cfg.section_from_path
setting.
---
cgit.c | 2 +-
cgit.h | 1 +
scan-tree.c | 20 +++++++++++++++++++-
shared.c | 1 +
4 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/cgit.c b/cgit.c
index 0ad8171..239f709 100644
--- a/cgit.c
+++ b/cgit.c
@@ -377,7 +377,7 @@ static void prepare_context(void)
ctx.cfg.root_desc = "a fast webinterface for the git dscm";
ctx.cfg.scan_hidden_path = 0;
ctx.cfg.script_name = CGIT_SCRIPT_NAME;
- ctx.cfg.section = "";
+ ctx.cfg.section = cgit_default_repo_section;
ctx.cfg.repository_sort = "name";
ctx.cfg.section_sort = 1;
ctx.cfg.summary_branches = 10;
diff --git a/cgit.h b/cgit.h
index 16f8092..ea9aef9 100644
--- a/cgit.h
+++ b/cgit.h
@@ -318,6 +318,7 @@ extern struct cgit_context ctx;
extern const struct cgit_snapshot_format cgit_snapshot_formats[];
extern char *cgit_default_repo_desc;
+extern char *cgit_default_repo_section;
extern struct cgit_repo *cgit_add_repo(const char *url);
extern struct cgit_repo *cgit_get_repoinfo(const char *url);
extern void cgit_repo_config_cb(const char *name, const char *value);
diff --git a/scan-tree.c b/scan-tree.c
index e900ad9..c7ba509 100644
--- a/scan-tree.c
+++ b/scan-tree.c
@@ -149,7 +149,25 @@ static void add_repo(const char *base, struct strbuf *path, repo_config_fn fn)
strbuf_setlen(path, pathlen);
}
- if (ctx.cfg.section_from_path) {
+ if (repo->section == cgit_default_repo_section || !repo->section) {
+ strbuf_addstr(path, "category");
+ if (!stat(path->buf, &st) &&
+ !readfile(path->buf, &repo->section, &size)) {
+ // trim category, as gitweb does
+ while (size > 0 && isspace((unsigned char)repo->section[size - 1]))
+ size--;
+ if (size == 0) {
+ free(repo->section);
+ repo->section = cgit_default_repo_section;
+ }
+ else
+ repo->section[size] = '\0';
+ }
+ strbuf_setlen(path, pathlen);
+ }
+
+ if (ctx.cfg.section_from_path
+ && (repo->section == cgit_default_repo_section || !repo->section)) {
n = ctx.cfg.section_from_path;
if (n > 0) {
slash = rel.buf - 1;
diff --git a/shared.c b/shared.c
index ae17d78..4b21da2 100644
--- a/shared.c
+++ b/shared.c
@@ -34,6 +34,7 @@ int chk_non_negative(int result, char *msg)
}
char *cgit_default_repo_desc = "[no description]";
+char *cgit_default_repo_section = "";
struct cgit_repo *cgit_add_repo(const char *url)
{
struct cgit_repo *ret;
--
1.9.1
next reply other threads:[~2015-03-05 17:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-05 17:15 glogow [this message]
2015-03-05 17:38 ` john
2015-03-05 17:50 ` glogow
2015-03-05 18:01 ` john
2015-03-05 17:41 ` cgit
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1425575704-15107-1-git-send-email-glogow@fbihome.de \
--to=cgit@lists.zx2c4.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).