From: Christian Couder <chriscool@tuxfamily.org>
To: Ramkumar Ramachandra <artagnon@gmail.com>
Cc: Git List <git@vger.kernel.org>,
Jonathan Nieder <jrnieder@gmail.com>,
Junio C Hamano <gitster@pobox.com>,
Daniel Barkalow <barkalow@iabervon.org>
Subject: Re: [RFC PATCH] revert: Persist per-session opts
Date: Sun, 10 Jul 2011 10:02:06 +0200 [thread overview]
Message-ID: <201107101002.06385.chriscool@tuxfamily.org> (raw)
In-Reply-To: <1310226118-10201-2-git-send-email-artagnon@gmail.com>
Hi Ram,
On Saturday 09 July 2011 17:41:58 Ramkumar Ramachandra wrote:
> Save the replay_opts struct in .git/sequencer/opts using a simple "key
> = value" format. Parse it and populate the options structure before
> replaying.
[...]
> static void format_todo(struct strbuf *buf, struct commit_list *todo_list,
> struct replay_opts *opts)
> {
> @@ -733,6 +759,102 @@ error:
> die(_("Malformed instruction sheet: %s"), git_path(SEQ_TODO_FILE));
> }
>
> +static char *parse_opt_value(char *p, void *key, enum seq_opt_type type,
> + parse_opt_cb *cb_function) {
> + struct option opt;
> + char *val, *cur, *end;
> +
> + if (!(val = strchr(p, '=')))
> + goto error;
> + if (!*(val + 1))
> + goto error;
> + if (!(end = strchr(p, '\n')))
> + goto error;
> + val += 2;
It looks like you rely on all lines ending with \n and having a space after
the '='. It may be a little bit too fragile.
> + *end = '\0'; /* Remove trailing '\n' */
> +
> + switch (type) {
> + case SEQ_OPTION_BOOLEAN:
> + if (!strncmp(val, "true", strlen("true")))
> + *(int *)key = 1;
> + else if (!strncmp(val, "false", strlen("false")))
> + *(int *)key = 0;
> + else
> + goto error;
> + break;
> + case SEQ_OPTION_INTEGER:
> + *(int *)key = strtol(val, NULL, 10);
> + break;
> + case SEQ_OPTION_STRING:
> + *(char **)key = xstrdup(val);
> + break;
> + case SEQ_OPTION_CALLBACK:
> + opt.value = (struct replay_opts **)key;
> + while (val) {
> + if ((cur = strchr(val, '|'))) {
> + *(cur - 1) = '\0';
> + (*cb_function)(&opt, val, 0);
> + val = cur + 2;
> + } else {
> + (*cb_function)(&opt, val, 0);
> + break;
> + }
> + }
> + break;
> + default:
> + die(_("program error"));
> + }
> + return end + 1;
> +error:
> + die(_("Malformed options sheet: %s"), git_path(SEQ_OPTS_FILE));
> +}
Otherwise it looks good to me.
Thanks,
Christian.
next prev parent reply other threads:[~2011-07-10 8:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-09 15:41 [RFC PATCH] An option parser for the sequencer Ramkumar Ramachandra
2011-07-09 15:41 ` [RFC PATCH] revert: Persist per-session opts Ramkumar Ramachandra
2011-07-10 8:02 ` Christian Couder [this message]
2011-07-11 6:12 ` Ramkumar Ramachandra
2011-07-10 8:15 ` [RFC PATCH] An option parser for the sequencer Christian Couder
2011-07-11 6:11 ` Ramkumar Ramachandra
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201107101002.06385.chriscool@tuxfamily.org \
--to=chriscool@tuxfamily.org \
--cc=artagnon@gmail.com \
--cc=barkalow@iabervon.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).