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

Re: [PATCH] gpg-interface: Strip CR chars for Windows gpg2

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 12, 2017, 01:51 UTC
Message-ID
<xmqqr2t4cli2.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20171111160657.11016-1-jerzy.kozera@gmail.com>
Jerzy Kozera <jerzy.kozera@gmail.com> writes:
Show 12 quoted lines
> +/* Strip CR from the line endings, in case we are on Windows. */
> +static void strip_cr(struct strbuf *buffer, size_t bottom) {
> +	size_t i, j;
> +	for (i = j = bottom; i < buffer->len; i++)
> +		if (buffer->buf[i] != '\r') {
> +			if (i != j)
> +				buffer->buf[j] = buffer->buf[i];
> +			j++;
> +		}
> +	strbuf_setlen(buffer, j);
> +}
> +

While the approach of turning CRLF into LF as a workaround is a good one, I do not see this loop doing that; instead it is removing CR anywhere on the line unconditionally.

It might not make a difference in practice to rely on the assumption that nobody sane would place a lone CR in the middle of a line, but it feels dirty.

Because I know this was lifted from an existing code, I think it may be better to take this patch as-is, but the code screams loudly that it wants a clean-up patch to fix that immediately on top of it.

Thanks.
Previous: Jerzy KozeraNext: Junio C Hamano
Message 2 of 4 in “gpg-interface: Strip CR chars for Windows gpg2”
  1. gpg-interface: Strip CR chars for Windows gpg2Jerzy Kozera, Nov 11, 2017
  2. Junio C HamanoNov 12, 2017
  3. Junio C HamanoNov 12, 2017
  4. Junio C HamanoNov 12, 2017

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.