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 v2 3/3] pkt-line: do not chomp newlines for sideband messages
Date: Mon, 25 Sep 2023 14:51:02 -0700 [thread overview]
Message-ID: <xmqqa5t9rkft.fsf@gitster.g> (raw)
In-Reply-To: <20230925154144.15213-3-worldhello.net@gmail.com> (Jiang Xin's message of "Mon, 25 Sep 2023 23:41:44 +0800")
Jiang Xin <worldhello.net@gmail.com> writes:
> 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 ;-)
> 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.
next prev parent reply other threads:[~2023-09-25 21:51 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
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 [this message]
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=xmqqa5t9rkft.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.