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

Re: [PATCH v2 3/3] pkt-line: do not chomp newlines for sideband messages

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 25, 2023, 21:51 UTC
Message-ID
<xmqqa5t9rkft.fsf@gitster.g>
In-Reply-To
<20230925154144.15213-3-worldhello.net@gmail.com>
Jiang Xin <worldhello.net@gmail.com> writes:
Show 48 quoted lines
> Add new flag "PACKET_READ_USE_SIDEBAND" for "packet_read_with_status()"
> to prevent mangling newline characters in sideband messages.
>
> Helped-by: Jonathan Tan <jonathantanmy@google.com>
> Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
> ---
>  pkt-line.c             | 32 ++++++++++++++++++++++++++++++--
>  pkt-line.h             |  1 +
>  t/t0070-fundamental.sh |  2 +-
>  3 files changed, 32 insertions(+), 3 deletions(-)
>
> diff --git a/pkt-line.c b/pkt-line.c
> index 5943777a17..865ad19484 100644
> --- a/pkt-line.c
> +++ b/pkt-line.c
> @@ -462,8 +462,33 @@ enum packet_read_status packet_read_with_status(int fd, char **src_buffer,
>  	}
>  
>  	if ((options & PACKET_READ_CHOMP_NEWLINE) &&
> -	    len && buffer[len-1] == '\n')
> -		len--;
> +	    len && buffer[len-1] == '\n') {
> +		if (options & PACKET_READ_USE_SIDEBAND) {
> +			int band = *buffer & 0xff;
> +			switch (band) {
> +			case 1:
> +				/* Chomp newline for payload */
> +				len--;
> +				break;
> +			case 2:
> +				/* fallthrough */
> +			case 3:
> +				/*
> +				 * Do not chomp newline for progress and error
> +				 * message.
> +				 */
> +				break;
> +			default:
> +				/*
> +				 * Bad sideband, let's leave it to
> +				 * demultiplex_sideband() to catch this error.
> +				 */
> +				break;
> +			}
> +		} else {
> +			len--;
> +		}
> +	}

That's a mouthful and we could shorten it a lot, but is very easy to follow the logic ;-)

Show 13 quoted lines
> diff --git a/t/t0070-fundamental.sh b/t/t0070-fundamental.sh
> index a927c665d6..138c2becc1 100755
> --- a/t/t0070-fundamental.sh
> +++ b/t/t0070-fundamental.sh
> @@ -97,7 +97,7 @@ test_expect_success 'unpack-sideband with demultiplex_sideband(), no chomp newli
>  	test_cmp expect-err err
>  '
>  
> -test_expect_failure 'unpack-sideband with demultiplex_sideband(), chomp newline' '
> +test_expect_success 'unpack-sideband with demultiplex_sideband(), chomp newline' '
>  	test_when_finished "rm -f expect-out expect-err" &&
>  	test-tool pkt-line send-split-sideband >split-sideband &&
>  	test-tool pkt-line unpack-sideband \

We cannot quite see what got fixed that is outside the postimage, but it is nice that we have one fewer test_expect_failure in the end.

Will queue.  Thanks.
Previous: Jiang XinNext: Oswald Buddenhagen
Message 8 of 19 in “pkt-line: do not chomp EOL for sideband progress info”
  1. pkt-line: do not chomp EOL for sideband progress infoJiang Xin, Sep 19, 2023
  2. Junio C HamanoSep 19, 2023
  3. Jonathan TanSep 20, 2023
  4. Jiang XinSep 25, 2023
  5. 1/3 test-pkt-line: add option parser for unpack-sidebandJiang Xin, Sep 25, 2023
  6. 2/3 pkt-line: memorize sideband fragment in readerJiang Xin, Sep 25, 2023
  7. 3/3 pkt-line: do not chomp newlines for sideband messagesJiang Xin, Sep 25, 2023
  8. Junio C HamanoSep 25, 2023
  9. Oswald BuddenhagenSep 26, 2023
  10. Jiang XinOct 4, 2023
  11. Junio C HamanoOct 4, 2023
  12. 0/3 Sideband demultiplexer fixesJiang Xin, Oct 4, 2023
  13. 2/3 pkt-line: memorize sideband fragment in readerJiang Xin, Oct 4, 2023
  14. 1/3 test-pkt-line: add option parser for unpack-sidebandJiang Xin, Oct 4, 2023
  15. 3/3 pkt-line: do not chomp newlines for sideband messagesJiang Xin, Oct 4, 2023
  16. 0/3 Sideband-all demultiplexer fixesJiang Xin, Dec 17, 2023
  17. 1/3 test-pkt-line: add option parser for unpack-sidebandJiang Xin, Dec 17, 2023
  18. 2/3 pkt-line: memorize sideband fragment in readerJiang Xin, Dec 17, 2023
  19. 3/3 pkt-line: do not chomp newlines for sideband messagesJiang Xin, Dec 17, 2023

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.