From: Eric Wong <normalperson@yhbt.net>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: Jakub Narebski <jnareb@gmail.com>, git@vger.kernel.org
Subject: Re: [RFC] Git config file reader in Perl (WIP)
Date: Tue, 16 Jan 2007 01:51:51 -0800 [thread overview]
Message-ID: <20070116095150.GA31467@localdomain> (raw)
In-Reply-To: <Pine.LNX.4.63.0701151313050.22628@wbgn013.biozentrum.uni-wuerzburg.de>
Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
> Hi,
>
> On Mon, 15 Jan 2007, Eric Wong wrote:
>
> > > 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 :)
>
> A bit shorter (and gets the booleans right, plus being even easier
> towards --python extension):
Your version doesn't get arrays right, however.
Here's a Perl/Python/Ruby version below. It should be extendable for
other languages; feedback and additions appreciated:
Note that usage has been changed to --dump=(perl|python|ruby)
I may add key_suffix to lang_dump just to be consistent with pairings,
but array_start seems to handle all cases of it and it would be
redundant...
--- 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";
@@ -14,6 +15,90 @@ static int do_not_match;
static int seen;
static enum { T_RAW, T_INT, T_BOOL } type = T_RAW;
+struct lang_dump {
+ const char *name;
+ const char *decl_start;
+ const char *decl_end;
+ const char *key_prefix;
+ const char *array_start;
+ const char *array_end;
+ const char *val_prefix;
+ const char *val_suffix;
+ const char *true_val; /* should already be quoted, if needed */
+ void (*quote_key_fn)(FILE *, const char*);
+ void (*quote_val_fn)(FILE *, const char*);
+};
+static char *last_key;
+static struct lang_dump *lang;
+static struct lang_dump lang_dump_defs[] = {
+ { "perl",
+ "\%git_config = (\n", ");\n",
+ "\t",
+ " => [\n", "\t],\n",
+ "\t\t", ",\n",
+ "'true'",
+ perl_quote_print, perl_quote_print },
+ { "python",
+ "git_config = {\n", "}\n",
+ " ",
+ " : [\n", " ],\n",
+ " ", ",\n",
+ "True",
+ python_quote_print, python_quote_print },
+ { "ruby", /* Ruby is very Perl-like */
+ "git_config = {\n", "}\n",
+ " ",
+ " => [\n", " ],\n",
+ " ", ",\n",
+ "true",
+ perl_quote_print, perl_quote_print },
+};
+
+static int show_lang_config(const char *key_, const char *value_)
+{
+ if (last_key) {
+ if (strcmp(last_key, key_)) {
+ free(last_key);
+ fputs(lang->array_end, stdout);
+ goto new_key;
+ }
+ } else {
+new_key:
+ last_key = xstrdup(key_);
+ fputs(lang->key_prefix, stdout);
+ lang->quote_key_fn(stdout, key_);
+ fputs(lang->array_start, stdout);
+ }
+ fputs(lang->val_prefix, stdout);
+ if (value_)
+ lang->quote_val_fn(stdout, value_);
+ else
+ fputs(lang->true_val, stdout);
+ fputs(lang->val_suffix, stdout);
+ return 0;
+}
+
+static int show_lang_config_all(const char *lang_name)
+{
+ int i, rv;
+ for (i = ARRAY_SIZE(lang_dump_defs); --i >= 0; ) {
+ if (strcmp(lang_name, lang_dump_defs[i].name))
+ continue;
+ lang = lang_dump_defs + i;
+ fputs(lang->decl_start, stdout);
+ rv = git_config(show_lang_config);
+ if (last_key) {
+ free(last_key);
+ last_key = NULL;
+ fputs(lang->array_end, stdout);
+ fputs(lang->decl_end, stdout);
+ }
+ return rv;
+ }
+ fputs("Dumping config to '%s' is not yet supported", stderr);
+ return -1;
+}
+
static int show_all_config(const char *key_, const char *value_)
{
if (value_)
@@ -138,6 +223,8 @@ 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 (!strncmp(argv[1], "--dump=", 7))
+ return show_lang_config_all(argv[1] + 7);
else if (!strcmp(argv[1], "--global")) {
char *home = getenv("HOME");
if (home) {
--
Eric Wong
next prev parent reply other threads:[~2007-01-16 9:51 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
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 [this message]
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=20070116095150.GA31467@localdomain \
--to=normalperson@yhbt.net \
--cc=Johannes.Schindelin@gmx.de \
--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 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).