@matheusbsbs / matheus-bagliano / commits / 2d14d65ce7
Fork 0

Use a clearer style to issue commands to remote helpers

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Daniel Barkalow committed Sep 3, 2009 at 22:13 UTC 2d14d65ce7b136b0fb18dcf27e5caff67829f658
1 file changed +14 -7
transport-helper.c
+14 -7
@@ -37,7 +37,10 @@ static struct child_process *get_helper(struct transport *transport)
37 die("Unable to run helper: git %s", helper->argv[0]);
38 data->helper = helper;
39
40 - write_in_full(data->helper->in, "capabilities\n", 13);
40 + strbuf_addstr(&buf, "capabilities\n");
41 + write_in_full(helper->in, buf.buf, buf.len);
42 + strbuf_reset(&buf);
43 +
44 file = fdopen(helper->out, "r");
45 while (1) {
46 if (strbuf_getline(&buf, file, '\n') == EOF)
@@ -78,11 +81,12 @@ static int fetch_with_fetch(struct transport *transport,
81 const struct ref *posn = to_fetch[i];
82 if (posn->status & REF_STATUS_UPTODATE)
83 continue;
81 - write_in_full(helper->in, "fetch ", 6);
82 - write_in_full(helper->in, sha1_to_hex(posn->old_sha1), 40);
83 - write_in_full(helper->in, " ", 1);
84 - write_in_full(helper->in, posn->name, strlen(posn->name));
85 - write_in_full(helper->in, "\n", 1);
84 +
85 + strbuf_addf(&buf, "fetch %s %s\n",
86 + sha1_to_hex(posn->old_sha1), posn->name);
87 + write_in_full(helper->in, buf.buf, buf.len);
88 + strbuf_reset(&buf);
89 +
90 if (strbuf_getline(&buf, file, '\n') == EOF)
91 exit(128); /* child died, message supplied already */
92 }
@@ -119,7 +123,10 @@ static struct ref *get_refs_list(struct transport *transport, int for_push)
123 FILE *file;
124
125 helper = get_helper(transport);
122 - write_in_full(helper->in, "list\n", 5);
126 +
127 + strbuf_addstr(&buf, "list\n");
128 + write_in_full(helper->in, buf.buf, buf.len);
129 + strbuf_reset(&buf);
130
131 file = fdopen(helper->out, "r");
132 while (1) {