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

Re: [PATCH 2/3] diff: introduce diff.submodule configuration variable

From
Jeff King <peff@peff.net>
Date
Nov 13, 2012, 05:33 UTC
Message-ID
<20121113053336.GA10995@sigill.intra.peff.net>
In-Reply-To
<1352653146-3932-3-git-send-email-artagnon@gmail.com>
On Sun, Nov 11, 2012 at 10:29:05PM +0530, Ramkumar Ramachandra wrote:
Show 13 quoted lines
> +static int parse_submodule_params(struct diff_options *options, const char *value,
> +				struct strbuf *errmsg)
> +{
> +	if (!strcmp(value, "log"))
> +		DIFF_OPT_SET(options, SUBMODULE_LOG);
> +	else if (!strcmp(value, "short"))
> +		DIFF_OPT_CLR(options, SUBMODULE_LOG);
> +	else {
> +		strbuf_addf(errmsg, _("'%s'"), value);
> +		return 1;
> +	}
> +	return 0;
> +}
I think "-1" would be the more normal error return.
Show 5 quoted lines
> @@ -223,6 +238,15 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)
>  		return 0;
>  	}
>  
> +	if (!strcmp(var, "diff.submodule")) {

Shouldn't this be in git_diff_ui_config so it does not affect scripts calling plumbing?

Show 7 quoted lines
> +		struct strbuf errmsg = STRBUF_INIT;
> +		if (parse_submodule_params(&default_diff_options, value, &errmsg))
> +			warning(_("Unknown value for 'diff.submodule' config variable: %s"),
> +				errmsg.buf);
> +		strbuf_release(&errmsg);
> +		return 0;
> +	}

Hmm. This strbuf error handling strikes me as very clunky, considering that it does not pass any useful information out of the parse function (it always just adds '$value' to the error string). Wouldn't it be simpler to just have parse_submodule_params return -1, and then let the caller warn or generate an error as appropriate?

-Peff
Previous: Ramkumar RamachandraNext: Ramkumar Ramachandra
Message 4 of 9 in “Introduce diff.submodule”
  1. 0/3 Introduce diff.submoduleRamkumar Ramachandra, Nov 11, 2012
  2. 1/3 Documentation: move diff.wordRegex from config.txt to diff-config.txtRamkumar Ramachandra, Nov 11, 2012
  3. 2/3 diff: introduce diff.submodule configuration variableRamkumar Ramachandra, Nov 11, 2012
  4. Jeff KingNov 13, 2012
  5. Ramkumar RamachandraNov 13, 2012
  6. Junio C HamanoNov 13, 2012
  7. 3/3 submodule: display summary header in boldRamkumar Ramachandra, Nov 11, 2012
  8. Jeff KingNov 13, 2012
  9. Ramkumar RamachandraNov 13, 2012

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.