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

Re: [PATCH 1/3] diff --stat: allow custom diffstat output width.

From
Junio C Hamano <junkio@cox.net>
Date
Sep 29, 2006, 05:26 UTC
Message-ID
<7vr6xvp7jm.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<Pine.LNX.4.64.0609281458420.3952@g5.osdl.org>
Linus Torvalds <torvalds@osdl.org> writes:
Show 31 quoted lines
> I could have made it a more obvious "stupid" parser, I just think it's 
> better to do it this way.
>
> +	else if (!strncmp(arg, "--stat", 6)) {
> +		char *end;
> +		int width = options->stat_width;
> +		int name_width = options->stat_name_width;
> +		arg += 6;
> +		end = arg;
> +
> +		switch (*arg) {
> +		case '-':
> +			if (!strncmp(arg, "-width=", 7))
> +				width = strtoul(arg + 7, &end, 10);
> +			else if (!strncmp(arg, "-name-width=", 12))
> +				name_width = strtoul(arg + 12, &end, 10);
> +			break;
> +
> +		case '=':
> +			width = strtoul(arg+1, &end, 10);
> +			if (*end == ',')
> +				name_width = strtoul(end+1, &end, 10);
> +		}
> +
> +		/* Important! This checks all the error cases! */
> +		if (*end)
> +			return 0;
>  		options->output_format |= DIFF_FORMAT_DIFFSTAT;
> +		options->stat_name_width = name_width;
> +		options->stat_width = width;
>  	}

This is simply too clever; -pedantic does not like assignment of arg to end (constness -- and strtoul takes pointer to non-const char *, so making the type of end const char * is not an answer either).

And I do not like casting constness away: end = (char *) arg.
Hmmmm.
Previous: Junio C HamanoNext: Linus Torvalds
Message 7 of 12 in “diff --stat: allow custom diffstat output width.”
  1. 1/3 diff --stat: allow custom diffstat output width.Junio C Hamano, Sep 27, 2006
  2. David RientjesSep 27, 2006
  3. Linus TorvaldsSep 28, 2006
  4. Junio C HamanoSep 28, 2006
  5. Linus TorvaldsSep 28, 2006
  6. Junio C HamanoSep 29, 2006
  7. Junio C HamanoSep 29, 2006
  8. Linus TorvaldsSep 29, 2006
  9. Junio C HamanoSep 29, 2006
  10. Linus TorvaldsSep 29, 2006
  11. Adrian BunkSep 28, 2006
  12. Johannes SchindelinSep 28, 2006

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.