git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC] Git config file reader in Perl (WIP)

From
EWEric Wong <normalperson@yhbt.net>
Date
Jan 15, 2007, 11:26 UTC
Message-ID
<20070115112635.GA5134@localdomain>
In-Reply-To
<200701151132.00971.jnareb@gmail.com>
Jakub Narebski <jnareb@gmail.com> wrote:
Show 22 quoted lines
> Eric Wong wrote:
> > Jakub Narebski <jnareb@gmail.com> wrote:
> >> Eric Wong wrote:
> >>> Jakub Narebski <jnareb@gmail.com> wrote:
> >>>> To make gitweb faster I thought about adding to it, or to Git.pm,
> >>>> simple nonvalidation config file reader. Nonvalidating means that
> >>>> it would accept some input which git-repo-config considers invalid.
> >>> 
> >>> How about something like git-for-each-ref that dumps the entire output
> >>> of a config file into an eval()-able string?  That way we don't have to
> >>> deal with corner-cases and subtle differences between C and Perl
> >>> implementations.
> >> 
> >> The idea is (at least for gitweb) to avoid cost of fork. And I think
> >> if the format gets documented properly, there should be no differences
> >> in config file parsing.
> > 
> > If the Perl output is redirected to a file (say .git/config.perl) and
> > only regenerated when .git/config changes, `do(".git/config.perl")' will
> > likely be faster since all the parsing will be done by Perl itself.
> 
> Would you write "git repo-config --perl", then? ;-)

The below patch should be a start (only tested on my fairly standard .git/config). A --python option should be easy, too :)

> Besides, I'd rather avoid the need for /tmp/gitweb, and I think usually
> gitweb do not have (and should not have) write access to repository.

Good point. Having to maintain a .git/config.perl in the repository would be a pain from an administrative standpoint; but on the other hand .git/config is not often regenerated.

I don't think giving gitweb write access to a repo is a good idea; either. Perhaps it would be updated via hook like the HTTP stuff. IMHO, there is nothing wrong with gitweb writing to /tmp; however.

diff --git a/builtin-repo-config.c b/builtin-repo-config.c
index 9063311..a9ef358 100644
--- a/builtin-repo-config.c
+++ b/builtin-repo-config.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "quote.h"
 
 static const char git_config_set_usage[] =
 "git-repo-config [ --global ] [ --bool | --int ] [--get | --get-all | --get-regexp | --replace-all | --add | --unset | --unset-all] name [value [value_regex]] | --rename-section old_name new_name | --list";
@@ -13,6 +14,7 @@ static int do_all;
 static int do_not_match;
 static int seen;
 static enum { T_RAW, T_INT, T_BOOL } type = T_RAW;
+static char *last_key;
 
 static int show_all_config(const char *key_, const char *value_)
 {
@@ -23,6 +25,30 @@ static int show_all_config(const char *key_, const char *value_)
 	return 0;
 }
 
+static int show_perl_config(const char *key_, const char *value_)
+{
+	if (last_key) {
+		if (strcmp(last_key, key_)) {
+			free(last_key);
+			last_key = xstrdup(key_);
+			fputs("\t],\n\t", stdout);
+			perl_quote_print(stdout, key_);
+			fputs(" => [\n", stdout);
+		}
+	} else {
+		last_key = xstrdup(key_);
+		fputc('\t', stdout);
+		perl_quote_print(stdout, key_);
+		fputs(" => [\n", stdout);
+	}
+	if (value_) {
+		fputs("\t\t", stdout);
+		perl_quote_print(stdout, value_);
+		fputs(",\n", stdout);
+	}
+	return 0;
+}
+
 static int show_config(const char* key_, const char* value_)
 {
 	char value[256];
@@ -138,6 +164,17 @@ int cmd_repo_config(int argc, const char **argv, const char *prefix)
 			type = T_BOOL;
 		else if (!strcmp(argv[1], "--list") || !strcmp(argv[1], "-l"))
 			return git_config(show_all_config);
+		else if (!strcmp(argv[1], "--perl")) {
+			int rv;
+			puts("\%git_config = (");
+			rv = git_config(show_perl_config);
+			if (last_key) {
+				puts("\t]\n);\n");
+				free(last_key);
+				last_key = NULL;
+			}
+			return rv;
+		}
 		else if (!strcmp(argv[1], "--global")) {
 			char *home = getenv("HOME");
 			if (home) {
-- 
Eric Wong
Previous: Jakub NarebskiNext: Johannes Schindelin
Message 7 of 54 in “[RFC] Git config file reader in Perl (WIP)”
  1. Jakub NarebskiJan 15, 2007
  2. Eric WongJan 15, 2007
  3. Jakub NarebskiJan 15, 2007
  4. Eric WongJan 15, 2007
  5. Shawn O. PearceJan 15, 2007
  6. Jakub NarebskiJan 15, 2007
  7. Eric WongJan 15, 2007
  8. Johannes SchindelinJan 15, 2007
  9. Nikolai WeibullJan 15, 2007
  10. Johannes SchindelinJan 15, 2007
  11. Nikolai WeibullJan 15, 2007
  12. Jakub NarebskiJan 15, 2007
  13. Junio C HamanoJan 16, 2007
  14. Johannes SchindelinJan 16, 2007
  15. Jakub NarebskiJan 16, 2007
  16. Nikolai WeibullJan 16, 2007
  17. Jakub NarebskiJan 16, 2007
  18. Johannes SchindelinJan 16, 2007
  19. Jakub NarebskiJan 16, 2007
  20. Johannes SchindelinJan 17, 2007
  21. Jakub NarebskiJan 17, 2007
  22. Johannes SchindelinJan 17, 2007
  23. Jakub NarebskiJan 17, 2007
  24. Johannes SchindelinJan 17, 2007
  25. Jakub NarebskiJan 17, 2007
  26. Jakub NarebskiJan 19, 2007
  27. Jakub NarebskiJan 19, 2007
  28. Johannes SchindelinJan 19, 2007
  29. Jakub NarebskiJan 19, 2007
  30. Johannes SchindelinJan 20, 2007
  31. Jakub NarebskiJan 20, 2007
  32. Junio C HamanoJan 20, 2007
  33. config_set_multivar(): disallow newlines in keysJohannes Schindelin, Jan 20, 2007
  34. Junio C HamanoJan 20, 2007
  35. Alex RiesenJan 22, 2007
  36. Johannes SchindelinJan 22, 2007
  37. Alex RiesenJan 22, 2007
  38. Johannes SchindelinJan 22, 2007
  39. Alex RiesenJan 22, 2007
  40. Johannes SchindelinJan 23, 2007
  41. Alex RiesenJan 23, 2007
  42. Documentation/config.txt: Document config file syntax betterJakub Narebski, Jan 20, 2007
  43. Documentation/config.txt: Document config file syntax betterJakub Narebski, Jan 22, 2007
  44. 2/1 Documentation/config.txt: Correct info about subsection nameJakub Narebski, Jan 24, 2007
  45. Johannes SchindelinJan 16, 2007
  46. Nikolai WeibullJan 17, 2007
  47. Jakub NarebskiJan 17, 2007
  48. Nikolai WeibullJan 17, 2007
  49. Jakub NarebskiJan 17, 2007
  50. Johannes SchindelinJan 18, 2007
  51. Eric WongJan 16, 2007
  52. Eric WongJan 16, 2007
  53. Johannes SchindelinJan 16, 2007
  54. Eric WongJan 16, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.