From: Brandon Williams <bmwill@google.com>
To: git@vger.kernel.org
Cc: peff@peff.net, jrnieder@gmail.com, sbeller@google.com,
gitster@pobox.com, jonathantanmy@google.com,
Brandon Williams <bmwill@google.com>
Subject: [RFC 2/7] pkt-line: add strbuf_packet_read
Date: Thu, 24 Aug 2017 15:53:23 -0700 [thread overview]
Message-ID: <20170824225328.8174-3-bmwill@google.com> (raw)
In-Reply-To: <20170824225328.8174-1-bmwill@google.com>
Add function which can be used to read the contents of a single pkt-line
into a strbuf.
Signed-off-by: Brandon Williams <bmwill@google.com>
---
pkt-line.c | 21 +++++++++++++++++++++
pkt-line.h | 1 +
2 files changed, 22 insertions(+)
diff --git a/pkt-line.c b/pkt-line.c
index cf98f371b..875524ab8 100644
--- a/pkt-line.c
+++ b/pkt-line.c
@@ -312,6 +312,27 @@ int packet_read(int fd, char **src_buf, size_t *src_len,
return len;
}
+int strbuf_packet_read(int fd_in, struct strbuf *sb_out, int options)
+{
+ int packet_len;
+ strbuf_grow(sb_out, LARGE_PACKET_DATA_MAX);
+ packet_len = packet_read(fd_in, NULL, NULL,
+ /*
+ * strbuf_grow() above always allocates one extra byte to
+ * store a '\0' at the end of the string. packet_read()
+ * writes a '\0' extra byte at the end, too. Let it know
+ * that there is already room for the extra byte.
+ */
+ sb_out->buf, LARGE_PACKET_DATA_MAX+1,
+ options);
+ if (packet_len < 0)
+ return packet_len;
+
+ sb_out->len = packet_len;
+
+ return sb_out->len;
+}
+
static char *packet_read_line_generic(int fd,
char **src, size_t *src_len,
int *dst_len)
diff --git a/pkt-line.h b/pkt-line.h
index d9e9783b1..c24c4f290 100644
--- a/pkt-line.h
+++ b/pkt-line.h
@@ -65,6 +65,7 @@ int write_packetized_from_buf(const char *src_in, size_t len, int fd_out);
int packet_read(int fd, char **src_buffer, size_t *src_len, char
*buffer, unsigned size, int options);
+int strbuf_packet_read(int fd_in, struct strbuf *sb_out, int options);
/*
* Convenience wrapper for packet_read that is not gentle, and sets the
* CHOMP_NEWLINE option. The return value is NULL for a flush packet,
--
2.14.1.342.g6490525c54-goog
next prev parent reply other threads:[~2017-08-24 22:54 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-24 22:53 [RFC 0/7] transitioning to protocol v2 Brandon Williams
2017-08-24 22:53 ` [RFC 1/7] pkt-line: add packet_write function Brandon Williams
2017-08-24 22:53 ` Brandon Williams [this message]
2017-08-24 22:53 ` [RFC 3/7] protocol: tell server that the client understands v2 Brandon Williams
2017-08-25 17:45 ` Junio C Hamano
2017-08-25 18:53 ` Brandon Williams
2017-08-25 18:55 ` Brandon Williams
2017-08-24 22:53 ` [RFC 4/7] t: fix ssh tests to cope with using '-o SendEnv=GIT_PROTOCOL' Brandon Williams
2017-08-24 22:53 ` [RFC 5/7] http: send Git-Protocol-Version header Brandon Williams
2017-08-30 10:55 ` Kevin Daudt
2017-08-24 22:53 ` [RFC 6/7] transport: teach client to recognize v2 server response Brandon Williams
2017-08-24 22:53 ` [RFC 7/7] upload-pack: ack version 2 Brandon Williams
2017-09-01 22:02 ` Bryan Turner
2017-09-01 23:20 ` Brandon Williams
2017-08-25 1:19 ` [RFC 0/7] transitioning to protocol v2 Junio C Hamano
2017-08-25 17:07 ` Stefan Beller
2017-08-25 17:14 ` Junio C Hamano
2017-08-25 17:36 ` Jeff King
2017-08-25 17:29 ` Jeff King
2017-08-25 17:35 ` Jonathan Nieder
2017-08-25 17:41 ` Jeff King
2017-08-25 18:50 ` Brandon Williams
2017-08-29 20:08 ` Jeff Hostetler
2017-08-29 21:10 ` Brandon Williams
2017-08-30 3:06 ` Jeff King
2017-08-30 13:30 ` Jeff Hostetler
2017-08-30 16:54 ` Brandon Williams
2017-08-25 17:48 ` Junio C Hamano
2017-08-30 20:38 ` Bryan Turner
2017-08-30 21:12 ` Brandon Williams
2017-09-01 23:06 ` Bryan Turner
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=20170824225328.8174-3-bmwill@google.com \
--to=bmwill@google.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jonathantanmy@google.com \
--cc=jrnieder@gmail.com \
--cc=peff@peff.net \
--cc=sbeller@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.
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.