On Thu, Mar 05, 2015 at 06:15:04PM +0100, Jan-Marek Glogowski wrote:
> 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.

What's the advantage of this over using "enable-git-config=1" and
"cgit.section" (we even support "gitweb.section" as an alias)?

> ---
>  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
> 
> _______________________________________________
> CGit mailing list
> CGit@lists.zx2c4.com
> http://lists.zx2c4.com/mailman/listinfo/cgit
_______________________________________________
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit

Reply via email to