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

Re: [PATCH 1/2] Do not output whitespace on blank lines

From
René Scharfe <l.s.r@web.de>
Date
May 29, 2016, 17:25 UTC
Message-ID
<574B25F4.8090409@web.de>
In-Reply-To
<01020154fd28aa12-f536bf3e-58df-4d1f-b903-929b429954d3-000000@eu-west-1.amazonses.com>
Am 29.05.2016 um 17:36 schrieb Dave Nicolson:
> ---

git diff marks context lines (in unified diff format) with a preceding space character. Your intent is to remove that marker for empty context lines, right? Why? How much smaller do diffs get by that (assuming output size reduction is one of the reasons)?

How compatible is it with patch, git apply and other programs that handle diffs? Interestingly in that context, POSIX [*] allows it, saying: "It is implementation-defined whether an empty unaffected line is written as an empty line or a line containing a single <space> character."

Also: missing sign-off (see Documentation/SubmittingPatches).
Show 13 quoted lines
>   diff.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/diff.c b/diff.c
> index d3734d3..459b36a 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -471,7 +471,7 @@ static void emit_line_0(struct diff_options *o, const char *set, const char *res
>   		has_trailing_carriage_return = (len > 0 && line[len-1] == '\r');
>   		if (has_trailing_carriage_return)
>   			len--;
> -		nofirst = 0;
> +		nofirst = len == 0 && (char)first == ' ' ? 1 : 0;
Why the cast from int to char?  And you also don't need the "? 1 : 0" part.
Show 6 quoted lines
>   	}
>
>   	if (len || !nofirst) {
>
> --
> https://github.com/git/git/pull/245

Your second patch adjusts tests. It would be better to combine the two in order to keep tests working with each commit.

René
[*] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/diff.html
Previous: Thomas GummererNext: Junio C Hamano
Message 4 of 5 in “Do not output whitespace on blank lines”
  1. 1/2 Do not output whitespace on blank linesDave Nicolson, May 29, 2016
  2. 2/2 Fix testsDave Nicolson, May 29, 2016
  3. Thomas GummererMay 29, 2016
  4. René ScharfeMay 29, 2016
  5. Junio C HamanoMay 30, 2016

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.