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

Re: [RFC PATCH] revert: Persist per-session opts

From
Christian Couder <chriscool@tuxfamily.org>
Date
Jul 10, 2011, 08:02 UTC
Message-ID
<201107101002.06385.chriscool@tuxfamily.org>
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.
[...]
Show 19 quoted lines
>  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.

Show 37 quoted lines
> +	*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.

Previous: Ramkumar RamachandraNext: Ramkumar Ramachandra
Message 3 of 6 in “An option parser for the sequencer”
  1. An option parser for the sequencerRamkumar Ramachandra, Jul 9, 2011
  2. revert: Persist per-session optsRamkumar Ramachandra, Jul 9, 2011
  3. Christian CouderJul 10, 2011
  4. Ramkumar RamachandraJul 11, 2011
  5. Christian CouderJul 10, 2011
  6. Ramkumar RamachandraJul 11, 2011

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.