All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/8] Use a clearer style to issue commands to remote helpers
@ 2009-09-04  2:13 Daniel Barkalow
  2009-09-04 10:40 ` Johannes Schindelin
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Barkalow @ 2009-09-04  2:13 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

This style is overkill for some commands, but it's worthwhile to use
the same style to issue all commands, and it's useful to avoid
open-coding string lengths.

Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
---
 transport-helper.c |   21 ++++++++++++++-------
 1 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/transport-helper.c b/transport-helper.c
index 4684877..b1ea7e6 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -37,7 +37,10 @@ static struct child_process *get_helper(struct transport *transport)
 		die("Unable to run helper: git %s", helper->argv[0]);
 	data->helper = helper;
 
-	write_in_full(data->helper->in, "capabilities\n", 13);
+	strbuf_addstr(&buf, "capabilities\n");
+	write_in_full(helper->in, buf.buf, buf.len);
+	strbuf_reset(&buf);
+
 	file = fdopen(helper->out, "r");
 	while (1) {
 		if (strbuf_getline(&buf, file, '\n') == EOF)
@@ -78,11 +81,12 @@ static int fetch_with_fetch(struct transport *transport,
 		const struct ref *posn = to_fetch[i];
 		if (posn->status & REF_STATUS_UPTODATE)
 			continue;
-		write_in_full(helper->in, "fetch ", 6);
-		write_in_full(helper->in, sha1_to_hex(posn->old_sha1), 40);
-		write_in_full(helper->in, " ", 1);
-		write_in_full(helper->in, posn->name, strlen(posn->name));
-		write_in_full(helper->in, "\n", 1);
+
+		strbuf_addf(&buf, "fetch %s %s\n",
+			    sha1_to_hex(posn->old_sha1), posn->name);
+		write_in_full(helper->in, buf.buf, buf.len);
+		strbuf_reset(&buf);
+
 		if (strbuf_getline(&buf, file, '\n') == EOF)
 			exit(128); /* child died, message supplied already */
 	}
@@ -119,7 +123,10 @@ static struct ref *get_refs_list(struct transport *transport, int for_push)
 	FILE *file;
 
 	helper = get_helper(transport);
-	write_in_full(helper->in, "list\n", 5);
+
+	strbuf_addstr(&buf, "list\n");
+	write_in_full(helper->in, buf.buf, buf.len);
+	strbuf_reset(&buf);
 
 	file = fdopen(helper->out, "r");
 	while (1) {
-- 
1.6.4.2.419.gc86f8

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 2/8] Use a clearer style to issue commands to remote helpers
  2009-09-04  2:13 [PATCH 2/8] Use a clearer style to issue commands to remote helpers Daniel Barkalow
@ 2009-09-04 10:40 ` Johannes Schindelin
  0 siblings, 0 replies; 2+ messages in thread
From: Johannes Schindelin @ 2009-09-04 10:40 UTC (permalink / raw)
  To: Daniel Barkalow; +Cc: Junio C Hamano, git

Hi,

On Thu, 3 Sep 2009, Daniel Barkalow wrote:

> This style is overkill for some commands, but it's worthwhile to use
> the same style to issue all commands, and it's useful to avoid
> open-coding string lengths.

Why do I have to study the patch to find out what "this style" is?  And 
why do you not even _try_ to convince people that "it's worthwhile", say, 
by giving some example?

> 
> diff --git a/transport-helper.c b/transport-helper.c
> index 4684877..b1ea7e6 100644
> --- a/transport-helper.c
> +++ b/transport-helper.c
> @@ -37,7 +37,10 @@ static struct child_process *get_helper(struct transport *transport)
>  		die("Unable to run helper: git %s", helper->argv[0]);
>  	data->helper = helper;
>  
> -	write_in_full(data->helper->in, "capabilities\n", 13);
> +	strbuf_addstr(&buf, "capabilities\n");
> +	write_in_full(helper->in, buf.buf, buf.len);
> +	strbuf_reset(&buf);
> +

If you use that paradigm more often, why not rather introduce something 
like

	void strbuf_flush(struct strbuf *buf, int fd) {
		write_in_full(fd, buf->buf, buf->len);
		strbuf_reset(buf);
	}

instead of violating the DRY principle?

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-09-04 10:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-04  2:13 [PATCH 2/8] Use a clearer style to issue commands to remote helpers Daniel Barkalow
2009-09-04 10:40 ` Johannes Schindelin

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.