Skip to content

Commit a810ea9

Browse files
benpeartgitster
authored andcommitted
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>
1 parent 7e93684 commit a810ea9

1 file changed

Lines changed: 34 additions & 24 deletions

File tree

convert.c

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -565,35 +565,14 @@ static void stop_multi_file_filter(struct child_process *process)
565565
finish_command(process);
566566
}
567567

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)
569569
{
570570
int err;
571-
struct cmd2process *entry;
572-
struct child_process *process;
573-
const char *argv[] = { cmd, NULL };
574571
struct string_list cap_list = STRING_LIST_INIT_NODUP;
575572
char *cap_buf;
576573
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;
597576

598577
sigchain_push(SIGPIPE, SIG_IGN);
599578

@@ -642,6 +621,37 @@ static struct cmd2process *start_multi_file_filter(struct hashmap *hashmap, cons
642621
done:
643622
sigchain_pop(SIGPIPE);
644623

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);
645655
if (err) {
646656
error("initialization for external filter '%s' failed", cmd);
647657
kill_multi_file_filter(hashmap, entry);

0 commit comments

Comments
 (0)