transport-helper.c: refactor set_helper_option()
For now we can handle two types, string and boolean, in set_helper_option(). Later on we'll add string_list support, which does not fit well. The new function strbuf_set_helper_option() can be reused for a separate function that handles string-list. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
b5f62ebea5
commit
9318c5dd14
@ -260,6 +260,28 @@ static const char *boolean_options[] = {
|
|||||||
TRANS_OPT_FOLLOWTAGS,
|
TRANS_OPT_FOLLOWTAGS,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int strbuf_set_helper_option(struct helper_data *data,
|
||||||
|
struct strbuf *buf)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
sendline(data, buf);
|
||||||
|
if (recvline(data, buf))
|
||||||
|
exit(128);
|
||||||
|
|
||||||
|
if (!strcmp(buf->buf, "ok"))
|
||||||
|
ret = 0;
|
||||||
|
else if (starts_with(buf->buf, "error"))
|
||||||
|
ret = -1;
|
||||||
|
else if (!strcmp(buf->buf, "unsupported"))
|
||||||
|
ret = 1;
|
||||||
|
else {
|
||||||
|
warning("%s unexpectedly said: '%s'", data->name, buf->buf);
|
||||||
|
ret = 1;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static int set_helper_option(struct transport *transport,
|
static int set_helper_option(struct transport *transport,
|
||||||
const char *name, const char *value)
|
const char *name, const char *value)
|
||||||
{
|
{
|
||||||
@ -291,20 +313,7 @@ static int set_helper_option(struct transport *transport,
|
|||||||
quote_c_style(value, &buf, NULL, 0);
|
quote_c_style(value, &buf, NULL, 0);
|
||||||
strbuf_addch(&buf, '\n');
|
strbuf_addch(&buf, '\n');
|
||||||
|
|
||||||
sendline(data, &buf);
|
ret = strbuf_set_helper_option(data, &buf);
|
||||||
if (recvline(data, &buf))
|
|
||||||
exit(128);
|
|
||||||
|
|
||||||
if (!strcmp(buf.buf, "ok"))
|
|
||||||
ret = 0;
|
|
||||||
else if (starts_with(buf.buf, "error")) {
|
|
||||||
ret = -1;
|
|
||||||
} else if (!strcmp(buf.buf, "unsupported"))
|
|
||||||
ret = 1;
|
|
||||||
else {
|
|
||||||
warning("%s unexpectedly said: '%s'", data->name, buf.buf);
|
|
||||||
ret = 1;
|
|
||||||
}
|
|
||||||
strbuf_release(&buf);
|
strbuf_release(&buf);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user