Skip to content

Commit 2d14d65

Browse files
iabervongitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c9e388b commit 2d14d65

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

transport-helper.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ static struct child_process *get_helper(struct transport *transport)
3737
die("Unable to run helper: git %s", helper->argv[0]);
3838
data->helper = helper;
3939

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+
4144
file = fdopen(helper->out, "r");
4245
while (1) {
4346
if (strbuf_getline(&buf, file, '\n') == EOF)
@@ -78,11 +81,12 @@ static int fetch_with_fetch(struct transport *transport,
7881
const struct ref *posn = to_fetch[i];
7982
if (posn->status & REF_STATUS_UPTODATE)
8083
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+
8690
if (strbuf_getline(&buf, file, '\n') == EOF)
8791
exit(128); /* child died, message supplied already */
8892
}
@@ -119,7 +123,10 @@ static struct ref *get_refs_list(struct transport *transport, int for_push)
119123
FILE *file;
120124

121125
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);
123130

124131
file = fdopen(helper->out, "r");
125132
while (1) {

0 commit comments

Comments
 (0)