git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jiang Xin <worldhello.net@gmail.com>
Cc: Git List <git@vger.kernel.org>,
	Jonathan Tan <jonathantanmy@google.com>,
	Jiang Xin <zhiyou.jx@alibaba-inc.com>
Subject: Re: [PATCH] pkt-line: do not chomp EOL for sideband progress info
Date: Tue, 19 Sep 2023 15:38:55 -0700	[thread overview]
Message-ID: <xmqqled1eqkg.fsf@gitster.g> (raw)
In-Reply-To: <20230919071956.14015-1-worldhello.net@gmail.com> (Jiang Xin's message of "Tue, 19 Sep 2023 15:19:56 +0800")

Jiang Xin <worldhello.net@gmail.com> writes:

> From: Jiang Xin <zhiyou.jx@alibaba-inc.com>

Who knows packet_reader interface well?  Jonathan?

Thanks.


> In the protocol negotiation stage, we need to turn on the flag
> "PACKET_READ_CHOMP_NEWLINE" to chomp EOL for each packet line from
> client or server. But when receiving data and progress information
> using sideband, we will turn off the flag "PACKET_READ_CHOMP_NEWLINE"
> to prevent mangling EOLs from data and progress information.
>
> When both the server and the client support "sideband-all" capability,
> we have a dilemma that EOLs in negotiation packets should be trimmed,
> but EOLs in progress infomation should be leaved as is.
>
> Move the logic of chomping EOLs from "packet_read_with_status()" to
> "packet_reader_read()" can resolve this dilemma.
>
> Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
> ---
>  pkt-line.c | 19 ++++++++++++++++---
>  1 file changed, 16 insertions(+), 3 deletions(-)
>
> diff --git a/pkt-line.c b/pkt-line.c
> index af83a19f4d..d6d08b6aa6 100644
> --- a/pkt-line.c
> +++ b/pkt-line.c
> @@ -597,12 +597,18 @@ void packet_reader_init(struct packet_reader *reader, int fd,
>  enum packet_read_status packet_reader_read(struct packet_reader *reader)
>  {
>  	struct strbuf scratch = STRBUF_INIT;
> +	int options = reader->options;
>  
>  	if (reader->line_peeked) {
>  		reader->line_peeked = 0;
>  		return reader->status;
>  	}
>  
> +	/* Do not chomp newlines for sideband progress and error messages */
> +	if (reader->use_sideband && options & PACKET_READ_CHOMP_NEWLINE) {
> +		options &= ~PACKET_READ_CHOMP_NEWLINE;
> +	}
> +
>  	/*
>  	 * Consume all progress packets until a primary payload packet is
>  	 * received
> @@ -615,7 +621,7 @@ enum packet_read_status packet_reader_read(struct packet_reader *reader)
>  							 reader->buffer,
>  							 reader->buffer_size,
>  							 &reader->pktlen,
> -							 reader->options);
> +							 options);
>  		if (!reader->use_sideband)
>  			break;
>  		if (demultiplex_sideband(reader->me, reader->status,
> @@ -624,12 +630,19 @@ enum packet_read_status packet_reader_read(struct packet_reader *reader)
>  			break;
>  	}
>  
> -	if (reader->status == PACKET_READ_NORMAL)
> +	if (reader->status == PACKET_READ_NORMAL) {
>  		/* Skip the sideband designator if sideband is used */
>  		reader->line = reader->use_sideband ?
>  			reader->buffer + 1 : reader->buffer;
> -	else
> +
> +		if ((reader->options & PACKET_READ_CHOMP_NEWLINE) &&
> +		    reader->buffer[reader->pktlen - 1] == '\n') {
> +			reader->buffer[reader->pktlen - 1] = 0;
> +			reader->pktlen--;
> +		}
> +	} else {
>  		reader->line = NULL;
> +	}
>  
>  	return reader->status;
>  }

  reply	other threads:[~2023-09-19 22:39 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-19  7:19 [PATCH] pkt-line: do not chomp EOL for sideband progress info Jiang Xin
2023-09-19 22:38 ` Junio C Hamano [this message]
2023-09-20 21:08 ` Jonathan Tan
2023-09-25  0:25   ` Jiang Xin
2023-09-25 15:41     ` [PATCH v2 1/3] test-pkt-line: add option parser for unpack-sideband Jiang Xin
2023-09-25 15:41     ` [PATCH v2 2/3] pkt-line: memorize sideband fragment in reader Jiang Xin
2023-09-25 15:41     ` [PATCH v2 3/3] pkt-line: do not chomp newlines for sideband messages Jiang Xin
2023-09-25 21:51       ` Junio C Hamano
2023-09-26  8:48         ` Oswald Buddenhagen
2023-10-04 13:02           ` Jiang Xin
2023-10-04 20:05             ` Junio C Hamano
2023-10-04 13:18           ` [PATCH v3 0/3] Sideband demultiplexer fixes Jiang Xin
2023-10-04 13:18             ` [PATCH v3 1/3] test-pkt-line: add option parser for unpack-sideband Jiang Xin
2023-10-04 13:18             ` [PATCH v3 2/3] pkt-line: memorize sideband fragment in reader Jiang Xin
2023-10-04 13:18             ` [PATCH v3 3/3] pkt-line: do not chomp newlines for sideband messages Jiang Xin
2023-12-17 14:41             ` [PATCH v4 0/3] Sideband-all demultiplexer fixes Jiang Xin
2023-12-17 14:41               ` [PATCH v4 1/3] test-pkt-line: add option parser for unpack-sideband Jiang Xin
2023-12-17 14:41               ` [PATCH v4 2/3] pkt-line: memorize sideband fragment in reader Jiang Xin
2023-12-17 14:41               ` [PATCH v4 3/3] pkt-line: do not chomp newlines for sideband messages Jiang Xin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqled1eqkg.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=jonathantanmy@google.com \
    --cc=worldhello.net@gmail.com \
    --cc=zhiyou.jx@alibaba-inc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).