convert: split start_multi_file_filter() into two separate functions
To enable future reuse of the filter.<driver>.process infrastructure, split start_multi_file_filter() into two separate parts. start_multi_file_filter() will now only contain the generic logic to manage the creation and tracking of the child process in a hashmap. start_multi_file_filter_fn() is a protocol specific initialization function that will negotiate the multi-file-filter interface version and capabilities. Signed-off-by: Ben Peart <benpeart@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ben Peart committed
May 5, 2017 at 11:27 UTC
a810ea9945d5959b6cf73d117bc0f20fde58c556
1 file changed
+34
-24
convert.c
+34
-24
@@ -565,35 +565,14 @@ static void stop_multi_file_filter(struct child_process *process)
565
finish_command(process);
566
}
567
568
-static struct cmd2process *start_multi_file_filter(struct hashmap *hashmap, const char *cmd)
568
+static int start_multi_file_filter_fn(struct cmd2process *entry)
569
{
570
int err;
571
- struct cmd2process *entry;
572
- struct child_process *process;
573
- const char *argv[] = { cmd, NULL };
571
struct string_list cap_list = STRING_LIST_INIT_NODUP;
572
char *cap_buf;
573
const char *cap_name;
577
-
578
- entry = xmalloc(sizeof(*entry));
579
- entry->cmd = cmd;
580
- entry->supported_capabilities = 0;
581
- process = &entry->process;
582
-
583
- child_process_init(process);
584
- process->argv = argv;
585
- process->use_shell = 1;
586
- process->in = -1;
587
- process->out = -1;
588
- process->clean_on_exit = 1;
589
- process->clean_on_exit_handler = stop_multi_file_filter;
590
-
591
- if (start_command(process)) {
592
- error("cannot fork to run external filter '%s'", cmd);
593
- return NULL;
594
- }
595
-
596
- hashmap_entry_init(entry, strhash(cmd));
574
+ struct child_process *process = &entry->process;
575
+ const char *cmd = entry->cmd;
576
577
sigchain_push(SIGPIPE, SIG_IGN);
578
@@ -642,6 +621,37 @@ static struct cmd2process *start_multi_file_filter(struct hashmap *hashmap, cons
621
done:
622
sigchain_pop(SIGPIPE);
623
624
+ return err;
625
+}
626
+
627
+static struct cmd2process *start_multi_file_filter(struct hashmap *hashmap, const char *cmd)
628
+{
629
+ int err;
630
+ struct cmd2process *entry;
631
+ struct child_process *process;
632
+ const char *argv[] = { cmd, NULL };
633
+
634
+ entry = xmalloc(sizeof(*entry));
635
+ entry->cmd = cmd;
636
+ entry->supported_capabilities = 0;
637
+ process = &entry->process;
638
+
639
+ child_process_init(process);
640
+ process->argv = argv;
641
+ process->use_shell = 1;
642
+ process->in = -1;
643
+ process->out = -1;
644
+ process->clean_on_exit = 1;
645
+ process->clean_on_exit_handler = stop_multi_file_filter;
646
+
647
+ if (start_command(process)) {
648
+ error("cannot fork to run external filter '%s'", cmd);
649
+ return NULL;
650
+ }
651
+
652
+ hashmap_entry_init(entry, strhash(cmd));
653
+
654
+ err = start_multi_file_filter_fn(entry);
655
if (err) {
656
error("initialization for external filter '%s' failed", cmd);
657
kill_multi_file_filter(hashmap, entry);