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>
Nguyễn Thái Ngọc Duy committed
Jun 12, 2016 at 17:53 UTC
9318c5dd140b55c0384843c57b4b24a378cd5068
1 file changed
+23
-14
transport-helper.c
+23
-14
@@ -260,6 +260,28 @@ static const char *boolean_options[] = {
260
TRANS_OPT_FOLLOWTAGS,
261
};
262
263
+static int strbuf_set_helper_option(struct helper_data *data,
264
+ struct strbuf *buf)
265
+{
266
+ int ret;
267
+
268
+ sendline(data, buf);
269
+ if (recvline(data, buf))
270
+ exit(128);
271
+
272
+ if (!strcmp(buf->buf, "ok"))
273
+ ret = 0;
274
+ else if (starts_with(buf->buf, "error"))
275
+ ret = -1;
276
+ else if (!strcmp(buf->buf, "unsupported"))
277
+ ret = 1;
278
+ else {
279
+ warning("%s unexpectedly said: '%s'", data->name, buf->buf);
280
+ ret = 1;
281
+ }
282
+ return ret;
283
+}
284
+
285
static int set_helper_option(struct transport *transport,
286
const char *name, const char *value)
287
{
@@ -291,20 +313,7 @@ static int set_helper_option(struct transport *transport,
313
quote_c_style(value, &buf, NULL, 0);
314
strbuf_addch(&buf, '\n');
315
294
- sendline(data, &buf);
295
- if (recvline(data, &buf))
296
- exit(128);
297
-
298
- if (!strcmp(buf.buf, "ok"))
299
- ret = 0;
300
- else if (starts_with(buf.buf, "error")) {
301
- ret = -1;
302
- } else if (!strcmp(buf.buf, "unsupported"))
303
- ret = 1;
304
- else {
305
- warning("%s unexpectedly said: '%s'", data->name, buf.buf);
306
- ret = 1;
307
- }
316
+ ret = strbuf_set_helper_option(data, &buf);
317
strbuf_release(&buf);
318
return ret;
319
}