From: Masaya Suzuki <masayasuzuki@google.com>
To: Josh Steadmon <steadmon@google.com>,
Masaya Suzuki <masayasuzuki@google.com>,
Git Mailing List <git@vger.kernel.org>, Jeff King <peff@peff.net>
Subject: Re: [PATCH v2 1/2] Use packet_reader instead of packet_read_line
Date: Tue, 8 Jan 2019 15:27:02 -0800 [thread overview]
Message-ID: <CAJB1erXk8xTCw0McdD-J=kz3s4fnpmhEEUBdzgTbMgQ-ry0wLw@mail.gmail.com> (raw)
In-Reply-To: <20190107223324.GB54613@google.com>
On Mon, Jan 7, 2019 at 2:33 PM Josh Steadmon <steadmon@google.com> wrote:
>
> On 2018.12.29 13:19, Masaya Suzuki wrote:
> > By using and sharing a packet_reader while handling a Git pack protocol
> > request, the same reader option is used throughout the code. This makes
> > it easy to set a reader option to the request parsing code.
> >
> > Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
> > ---
> > builtin/archive.c | 19 ++++++-------
> > builtin/receive-pack.c | 60 +++++++++++++++++++++--------------------
> > fetch-pack.c | 61 +++++++++++++++++++++++-------------------
> > remote-curl.c | 22 ++++++++++-----
> > send-pack.c | 37 ++++++++++++-------------
> > upload-pack.c | 38 +++++++++++++-------------
> > 6 files changed, 129 insertions(+), 108 deletions(-)
> >
> > diff --git a/builtin/archive.c b/builtin/archive.c
> > index d2455237c..2fe1f05ca 100644
> > --- a/builtin/archive.c
> > +++ b/builtin/archive.c
> > @@ -27,10 +27,10 @@ static int run_remote_archiver(int argc, const char **argv,
> > const char *remote, const char *exec,
> > const char *name_hint)
> > {
> > - char *buf;
> > int fd[2], i, rv;
> > struct transport *transport;
> > struct remote *_remote;
> > + struct packet_reader reader;
> >
> > _remote = remote_get(remote);
> > if (!_remote->url[0])
> > @@ -53,18 +53,19 @@ static int run_remote_archiver(int argc, const char **argv,
> > packet_write_fmt(fd[1], "argument %s\n", argv[i]);
> > packet_flush(fd[1]);
> >
> > - buf = packet_read_line(fd[0], NULL);
> > - if (!buf)
> > + packet_reader_init(&reader, fd[0], NULL, 0, PACKET_READ_CHOMP_NEWLINE);
> > +
> > + if (packet_reader_read(&reader) != PACKET_READ_NORMAL)
>
> packet_read_line() can also return NULL if the packet is zero-length, so
> you may want to add a "|| reader.pktlen <= 0" to the condition here (and
> in other places where we were checking that packet_read_line() != NULL)
> to make sure the behavior doesn't change. See discussion on my previous
> attempt[1] to refactor this in builtin/archive.c.
>
> [1]: https://public-inbox.org/git/20180912053519.31085-1-steadmon@google.com/
That is interesting. In Documentation/technical/protocol-common.txt,
it says "Implementations SHOULD NOT send an empty pkt-line ("0004").".
The existing code won't distinguish "0000" and "0004", while "0004" is
actually not a valid pkt-line. I'll make this patch with no behavior
change, but I think we can make that behavior change to stop accepting
0004 as 0000, and remove the pktlen checks.
next prev parent reply other threads:[~2019-01-08 23:27 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <reply-to=20181127045301.103807-1-masayasuzuki@google.com>
2018-12-29 21:19 ` [PATCH v2 0/2] Accept error packets in any context Masaya Suzuki
2018-12-29 21:19 ` [PATCH v2 1/2] Use packet_reader instead of packet_read_line Masaya Suzuki
2019-01-07 19:01 ` Jonathan Tan
2019-01-07 22:33 ` Josh Steadmon
2019-01-08 23:27 ` Masaya Suzuki [this message]
2018-12-29 21:19 ` [PATCH v2 2/2] pack-protocol.txt: accept error packets in any context Masaya Suzuki
2019-01-07 19:41 ` Jonathan Tan
2019-01-07 22:53 ` Josh Steadmon
2019-01-03 23:05 ` [PATCH v2 0/2] Accept " Junio C Hamano
2019-01-04 0:20 ` Masaya Suzuki
2019-01-15 1:43 ` Jonathan Nieder
2019-01-15 1:49 ` Jonathan Nieder
2019-01-15 18:44 ` Junio C Hamano
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAJB1erXk8xTCw0McdD-J=kz3s4fnpmhEEUBdzgTbMgQ-ry0wLw@mail.gmail.com' \
--to=masayasuzuki@google.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
--cc=steadmon@google.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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).