summaryrefslogtreecommitdiff
path: root/transport-helper.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2016-06-12 17:53:44 +0700
committerJunio C Hamano <gitster@pobox.com>2016-06-13 14:38:16 -0700
commit9318c5dd140b55c0384843c57b4b24a378cd5068 (patch)
tree4dfd27d2eb0ee1385b8ae82a0f51099c0282b75c /transport-helper.c
parentb5f62ebea55a07dbd9f68f33f5efbd0437946220 (diff)
downloadgit-9318c5dd140b55c0384843c57b4b24a378cd5068.tar.gz
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>
Diffstat (limited to 'transport-helper.c')
-rw-r--r--transport-helper.c37
1 files changed, 23 insertions, 14 deletions
diff --git a/transport-helper.c b/transport-helper.c
index a6bff8b308..27a34e9d4e 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -260,6 +260,28 @@ static const char *boolean_options[] = {
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,
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);
strbuf_addch(&buf, '\n');
- 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;
- }
+ ret = strbuf_set_helper_option(data, &buf);
strbuf_release(&buf);
return ret;
}