git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Ben Peart <Ben.Peart@microsoft.com>
To: Junio C Hamano <gitster@pobox.com>, Ben Peart <peartben@gmail.com>
Cc: "git@vger.kernel.org" <git@vger.kernel.org>,
	"christian.couder@gmail.com" <christian.couder@gmail.com>,
	"larsxschneider@gmail.com" <larsxschneider@gmail.com>
Subject: RE: [PATCH v1 1/3] pkt-line: add packet_write_list_gently()
Date: Fri, 24 Mar 2017 12:34:25 +0000	[thread overview]
Message-ID: <BL2PR03MB32362E9532BFD2C895C1B73F43E0@BL2PR03MB323.namprd03.prod.outlook.com> (raw)
In-Reply-To: <xmqqefxpjc5b.fsf@gitster.mtv.corp.google.com>

> -----Original Message-----
> From: Junio C Hamano [mailto:gitster@pobox.com]
> Sent: Wednesday, March 22, 2017 4:21 PM
> To: Ben Peart <peartben@gmail.com>
> Cc: git@vger.kernel.org; Ben Peart <Ben.Peart@microsoft.com>;
> christian.couder@gmail.com; larsxschneider@gmail.com
> Subject: Re: [PATCH v1 1/3] pkt-line: add packet_write_list_gently()
> 
> Ben Peart <peartben@gmail.com> writes:
> 
> > Add packet_write_list_gently() which writes multiple lines in a single
> > call and then calls packet_flush_gently(). This is used later in this
> > patch series.
> 
> I can see how it would be convenient to have a function like this.
> I'd name it without _gently(), though.  We call something _gently() when we
> initially only have a function that dies hard on error and later want to have a
> variant that returns an error for the caller to handle.  You are starting
> without a dying variant (which is probably a preferable way to structure the
> API).
> 
> Also I am hesitant to take a function that does not take any "list"
> type argument and yet calls itself "write_list".  IOW, I'd expect something like
> these
> 
> 	write_list(int fd, const char **lines);
> 	write_list(int fd, struct string_list *lines);
> 
> given that name, and not "varargs, each of which is a line".  I am tempted to
> suggest
> 
> 	packet_writel(int fd, const char *line, ...);
> 
> noticing similarity with execl(), but perhaps others may be able to come up
> with better names.

Given there haven't been any better names suggested, I'll go ahead and update it to be packet_writel.

> 
> > Signed-off-by: Ben Peart <benpeart@microsoft.com>
> > ---
> >  pkt-line.c | 19 +++++++++++++++++++
> >  pkt-line.h |  1 +
> >  2 files changed, 20 insertions(+)
> >
> > diff --git a/pkt-line.c b/pkt-line.c
> > index d4b6bfe076..fccdac1352 100644
> > --- a/pkt-line.c
> > +++ b/pkt-line.c
> > @@ -171,6 +171,25 @@ int packet_write_fmt_gently(int fd, const char
> *fmt, ...)
> >  	return status;
> >  }
> >
> > +int packet_write_list_gently(int fd, const char *line, ...) {
> > +	va_list args;
> > +	int err;
> > +	va_start(args, line);
> > +	for (;;) {
> > +		if (!line)
> > +			break;
> > +		if (strlen(line) > LARGE_PACKET_DATA_MAX)
> > +			return -1;
> > +		err = packet_write_fmt_gently(fd, "%s\n", line);
> > +		if (err)
> > +			return err;
> > +		line = va_arg(args, const char*);
> > +	}
> > +	va_end(args);
> > +	return packet_flush_gently(fd);
> > +}
> > +
> >  static int packet_write_gently(const int fd_out, const char *buf,
> > size_t size)  {
> >  	static char packet_write_buffer[LARGE_PACKET_MAX];
> > diff --git a/pkt-line.h b/pkt-line.h
> > index 18eac64830..3674d04509 100644
> > --- a/pkt-line.h
> > +++ b/pkt-line.h
> > @@ -25,6 +25,7 @@ void packet_buf_flush(struct strbuf *buf);  void
> > packet_buf_write(struct strbuf *buf, const char *fmt, ...)
> > __attribute__((format (printf, 2, 3)));  int packet_flush_gently(int
> > fd);  int packet_write_fmt_gently(int fd, const char *fmt, ...)
> > __attribute__((format (printf, 2, 3)));
> > +int packet_write_list_gently(int fd, const char *line, ...);
> >  int write_packetized_from_fd(int fd_in, int fd_out);  int
> > write_packetized_from_buf(const char *src_in, size_t len, int fd_out);

  reply	other threads:[~2017-03-24 12:34 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-22 16:52 [PATCH v1 0/3] Add support for downloading blobs on demand Ben Peart
2017-03-22 16:52 ` [PATCH v1 1/3] pkt-line: add packet_write_list_gently() Ben Peart
2017-03-22 20:21   ` Junio C Hamano
2017-03-24 12:34     ` Ben Peart [this message]
2017-03-22 16:52 ` [PATCH v1 2/3] sub-process: refactor the filter process code into a reusable module Ben Peart
2017-03-23  6:16   ` Junio C Hamano
2017-03-24 12:39     ` Ben Peart
2017-03-24 16:10       ` Junio C Hamano
2017-03-24 17:15         ` Junio C Hamano
2017-03-27 22:04           ` Ben Peart
2017-03-22 16:52 ` [PATCH v1 3/3] convert: use new sub-process module for filter processes Ben Peart
2017-03-25 11:59 ` [PATCH v1 0/3] Add support for downloading blobs on demand Duy Nguyen

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=BL2PR03MB32362E9532BFD2C895C1B73F43E0@BL2PR03MB323.namprd03.prod.outlook.com \
    --to=ben.peart@microsoft.com \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=larsxschneider@gmail.com \
    --cc=peartben@gmail.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).