List for cgit developers and users
 help / color / mirror / Atom feed
* [PATCH] Support .git/category files
@ 2015-03-05 17:15 glogow
  2015-03-05 17:38 ` john
  2015-03-05 17:41 ` cgit
  0 siblings, 2 replies; 5+ messages in thread
From: glogow @ 2015-03-05 17:15 UTC (permalink / 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



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] Support .git/category files
  2015-03-05 17:15 [PATCH] Support .git/category files glogow
@ 2015-03-05 17:38 ` john
  2015-03-05 17:50   ` glogow
  2015-03-05 17:41 ` cgit
  1 sibling, 1 reply; 5+ messages in thread
From: john @ 2015-03-05 17:38 UTC (permalink / raw)


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 at lists.zx2c4.com
> http://lists.zx2c4.com/mailman/listinfo/cgit


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] Support .git/category files
  2015-03-05 17:15 [PATCH] Support .git/category files glogow
  2015-03-05 17:38 ` john
@ 2015-03-05 17:41 ` cgit
  1 sibling, 0 replies; 5+ messages in thread
From: cgit @ 2015-03-05 17:41 UTC (permalink / raw)


On Thu, 05 Mar 2015 at 18:15:04, 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.
> ---
>  cgit.c      |  2 +-
>  cgit.h      |  1 +
>  scan-tree.c | 20 +++++++++++++++++++-
>  shared.c    |  1 +
>  4 files changed, 22 insertions(+), 2 deletions(-)
> [...]

There already are at least two ways to achieve the same thing (using the
Git configuration variables gitweb.category or cgit.section and
repository-specific cgitrc files). Do we really need another
alternative? Is this just for GitWeb compatibility or does this have any
advantages over the existing options?


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] Support .git/category files
  2015-03-05 17:38 ` john
@ 2015-03-05 17:50   ` glogow
  2015-03-05 18:01     ` john
  0 siblings, 1 reply; 5+ messages in thread
From: glogow @ 2015-03-05 17:50 UTC (permalink / raw)


Am 05.03.2015 um 18:38 schrieb John Keeping:
> What's the advantage of this over using "enable-git-config=1" and
> "cgit.section" (we even support "gitweb.section" as an alias)?

Well - I have 100+ repositories, which already have the "category" file.
There is no "advantage" over any other method.

Am 05.03.2015 um 18:41 schrieb Lukas Fleischer:>
> There already are at least two ways to achieve the same thing (using
> the Git configuration variables gitweb.category or cgit.section and
> repository-specific cgitrc files). Do we really need another
> alternative? Is this just for GitWeb compatibility or does this have
> any advantages over the existing options?

Yes - it's "just" GitWeb compatibility, like - I guess - the
"description" file support just the few lines before my path.

JMG


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] Support .git/category files
  2015-03-05 17:50   ` glogow
@ 2015-03-05 18:01     ` john
  0 siblings, 0 replies; 5+ messages in thread
From: john @ 2015-03-05 18:01 UTC (permalink / raw)


On Thu, Mar 05, 2015 at 06:50:47PM +0100, Jan-Marek Glogowski wrote:
> Am 05.03.2015 um 18:38 schrieb John Keeping:
> > What's the advantage of this over using "enable-git-config=1" and
> > "cgit.section" (we even support "gitweb.section" as an alias)?
> 
> Well - I have 100+ repositories, which already have the "category" file.
> There is no "advantage" over any other method.
> 
> Am 05.03.2015 um 18:41 schrieb Lukas Fleischer:>
> > There already are at least two ways to achieve the same thing (using
> > the Git configuration variables gitweb.category or cgit.section and
> > repository-specific cgitrc files). Do we really need another
> > alternative? Is this just for GitWeb compatibility or does this have
> > any advantages over the existing options?
> 
> Yes - it's "just" GitWeb compatibility, like - I guess - the
> "description" file support just the few lines before my path.

The "description" file is a bit different though - it's in the default
repository template that ships with Git and is used by the sample hooks
that ship there.

I'm not sure "category" is similar enough, particularly when you can do:

	for repo in $repositories
	do
		git -C "$repo" config gitweb.category "$(cat "$repo"/category)" &&
		rm -f "$repo"/category
	done

and still have a configuration that works with both Gitweb and CGit.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-03-05 18:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-05 17:15 [PATCH] Support .git/category files glogow
2015-03-05 17:38 ` john
2015-03-05 17:50   ` glogow
2015-03-05 18:01     ` john
2015-03-05 17:41 ` cgit

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).