All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Wong <normalperson@yhbt.net>
To: Jakub Narebski <jnareb@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [RFC] Git config file reader in Perl (WIP)
Date: Mon, 15 Jan 2007 03:26:35 -0800	[thread overview]
Message-ID: <20070115112635.GA5134@localdomain> (raw)
In-Reply-To: <200701151132.00971.jnareb@gmail.com>

Jakub Narebski <jnareb@gmail.com> wrote:
> 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

  reply	other threads:[~2007-01-15 17:20 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-15  0:44 [RFC] Git config file reader in Perl (WIP) Jakub Narebski
2007-01-15  7:08 ` Eric Wong
2007-01-15  9:03   ` Jakub Narebski
2007-01-15  9:56     ` Eric Wong
2007-01-15 10:01       ` Shawn O. Pearce
2007-01-15 10:32       ` Jakub Narebski
2007-01-15 11:26         ` Eric Wong [this message]
2007-01-15 12:15           ` Johannes Schindelin
2007-01-15 15:34             ` Nikolai Weibull
2007-01-15 15:44               ` Johannes Schindelin
2007-01-15 16:22                 ` Nikolai Weibull
2007-01-15 16:00               ` Jakub Narebski
2007-01-16 10:45               ` Junio C Hamano
2007-01-16 11:12                 ` Johannes Schindelin
2007-01-16 14:14                   ` Jakub Narebski
2007-01-16 22:17                     ` Nikolai Weibull
2007-01-16 22:37                       ` Jakub Narebski
2007-01-16 22:56                         ` Johannes Schindelin
2007-01-16 23:24                           ` Jakub Narebski
2007-01-17  8:51                             ` Johannes Schindelin
2007-01-17  9:48                               ` Jakub Narebski
2007-01-17 10:44                                 ` Johannes Schindelin
2007-01-17 12:11                                   ` Jakub Narebski
2007-01-17 12:37                                     ` Johannes Schindelin
2007-01-17 14:00                                       ` Jakub Narebski
2007-01-19 12:10                                         ` Jakub Narebski
2007-01-19 12:25                                           ` Jakub Narebski
2007-01-19 13:20                                           ` Johannes Schindelin
2007-01-19 22:44                                             ` Jakub Narebski
2007-01-20  0:08                                               ` Johannes Schindelin
2007-01-20  0:59                                                 ` Jakub Narebski
2007-01-20  0:19                                               ` Junio C Hamano
2007-01-20  1:25                                                 ` [PATCH] config_set_multivar(): disallow newlines in keys Johannes Schindelin
2007-01-20  1:40                                                   ` Junio C Hamano
2007-01-22 15:06                                                   ` Alex Riesen
2007-01-22 15:21                                                     ` Johannes Schindelin
2007-01-22 15:33                                                       ` Alex Riesen
2007-01-22 15:44                                                         ` Johannes Schindelin
2007-01-22 16:09                                                           ` Alex Riesen
2007-01-23 11:26                                                             ` Johannes Schindelin
2007-01-23 12:47                                                               ` Alex Riesen
2007-01-20 14:03                                                 ` [PATCH] Documentation/config.txt: Document config file syntax better Jakub Narebski
2007-01-22 15:25                                                   ` Jakub Narebski
2007-01-24 14:14                                                     ` [PATCH 2/1] Documentation/config.txt: Correct info about subsection name Jakub Narebski
2007-01-16 22:42                       ` [RFC] Git config file reader in Perl (WIP) Johannes Schindelin
2007-01-17 18:08                         ` Nikolai Weibull
2007-01-17 19:22                           ` Jakub Narebski
2007-01-17 20:01                             ` Nikolai Weibull
2007-01-17 19:25                           ` Jakub Narebski
2007-01-18  0:50                           ` Johannes Schindelin
2007-01-16 19:09                   ` Eric Wong
2007-01-16  9:51             ` Eric Wong
2007-01-16 10:47               ` Johannes Schindelin
2007-01-16 19:53                 ` Eric Wong

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=20070115112635.GA5134@localdomain \
    --to=normalperson@yhbt.net \
    --cc=git@vger.kernel.org \
    --cc=jnareb@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.