diff options
author | Junio C Hamano <gitster@pobox.com> | 2017-08-11 13:27:05 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-08-11 13:27:05 -0700 |
commit | 9a8ff899cea20d88f6e1e7282b1ea64d964fc2e5 (patch) | |
tree | cc8b3059b063e9393f4119d7c033040251306dad /convert.c | |
parent | a449130a003934cb40738a2bf8c1a653afcd2e22 (diff) | |
parent | fa64a2fdbeedd98c5f24d1662bcc470a8449abcf (diff) | |
download | git-9a8ff899cea20d88f6e1e7282b1ea64d964fc2e5.tar.gz |
Merge branch 'jt/subprocess-handshake'
Code cleanup.
* jt/subprocess-handshake:
sub-process: refactor handshake to common function
Documentation: migrate sub-process docs to header
Diffstat (limited to 'convert.c')
-rw-r--r-- | convert.c | 75 |
1 files changed, 7 insertions, 68 deletions
@@ -513,78 +513,17 @@ static struct hashmap subprocess_map; static int start_multi_file_filter_fn(struct subprocess_entry *subprocess) { - int err, i; - struct cmd2process *entry = (struct cmd2process *)subprocess; - struct string_list cap_list = STRING_LIST_INIT_NODUP; - char *cap_buf; - const char *cap_name; - struct child_process *process = &subprocess->process; - const char *cmd = subprocess->cmd; - - static const struct { - const char *name; - unsigned int cap; - } known_caps[] = { + static int versions[] = {2, 0}; + static struct subprocess_capability capabilities[] = { { "clean", CAP_CLEAN }, { "smudge", CAP_SMUDGE }, { "delay", CAP_DELAY }, + { NULL, 0 } }; - - sigchain_push(SIGPIPE, SIG_IGN); - - err = packet_writel(process->in, "git-filter-client", "version=2", NULL); - if (err) - goto done; - - err = strcmp(packet_read_line(process->out, NULL), "git-filter-server"); - if (err) { - error("external filter '%s' does not support filter protocol version 2", cmd); - goto done; - } - err = strcmp(packet_read_line(process->out, NULL), "version=2"); - if (err) - goto done; - err = packet_read_line(process->out, NULL) != NULL; - if (err) - goto done; - - for (i = 0; i < ARRAY_SIZE(known_caps); ++i) { - err = packet_write_fmt_gently( - process->in, "capability=%s\n", known_caps[i].name); - if (err) - goto done; - } - err = packet_flush_gently(process->in); - if (err) - goto done; - - for (;;) { - cap_buf = packet_read_line(process->out, NULL); - if (!cap_buf) - break; - string_list_split_in_place(&cap_list, cap_buf, '=', 1); - - if (cap_list.nr != 2 || strcmp(cap_list.items[0].string, "capability")) - continue; - - cap_name = cap_list.items[1].string; - i = ARRAY_SIZE(known_caps) - 1; - while (i >= 0 && strcmp(cap_name, known_caps[i].name)) - i--; - - if (i >= 0) - entry->supported_capabilities |= known_caps[i].cap; - else - warning("external filter '%s' requested unsupported filter capability '%s'", - cmd, cap_name); - - string_list_clear(&cap_list, 0); - } - -done: - sigchain_pop(SIGPIPE); - - return err; + struct cmd2process *entry = (struct cmd2process *)subprocess; + return subprocess_handshake(subprocess, "git-filter", versions, NULL, + capabilities, + &entry->supported_capabilities); } static void handle_filter_error(const struct strbuf *filter_status, |