convert: separate generic structures and variables from the filter specific ones
To enable future reuse of the filter.<driver>.process infrastructure, split the cmd2process structure into two separate parts. subprocess_entry will now contain the generic data required to manage the creation and tracking of the child process in a hashmap. cmd2process is a filter protocol specific structure that is used to track the negotiated capabilities of the filter. 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
1b0b46ee3b310b66023423ba32f023d923d7cb0e
1 file changed
+20
-15
convert.c
+20
-15
@@ -496,26 +496,31 @@ static int apply_single_file_filter(const char *path, const char *src, size_t le
496
#define CAP_CLEAN (1u<<0)
497
#define CAP_SMUDGE (1u<<1)
498
499
-struct cmd2process {
499
+struct subprocess_entry {
500
struct hashmap_entry ent; /* must be the first member! */
501
- unsigned int supported_capabilities;
501
const char *cmd;
502
struct child_process process;
503
};
504
505
+struct cmd2process {
506
+ struct subprocess_entry subprocess; /* must be the first member! */
507
+ unsigned int supported_capabilities;
508
+};
509
+
510
static int cmd_process_map_initialized;
511
static struct hashmap cmd_process_map;
512
509
-static int cmd2process_cmp(const struct cmd2process *e1,
510
- const struct cmd2process *e2,
513
+static int cmd2process_cmp(const struct subprocess_entry *e1,
514
+ const struct subprocess_entry *e2,
515
const void *unused)
516
{
517
return strcmp(e1->cmd, e2->cmd);
518
}
519
516
-static struct cmd2process *find_multi_file_filter_entry(struct hashmap *hashmap, const char *cmd)
520
+static struct subprocess_entry *find_multi_file_filter_entry(struct hashmap *hashmap, const char *cmd)
521
{
518
- struct cmd2process key;
522
+ struct subprocess_entry key;
523
+
524
hashmap_entry_init(&key, strhash(cmd));
525
key.cmd = cmd;
526
return hashmap_get(hashmap, &key, NULL);
@@ -541,7 +546,7 @@ static void read_multi_file_filter_status(int fd, struct strbuf *status)
546
}
547
}
548
544
-static void kill_multi_file_filter(struct hashmap *hashmap, struct cmd2process *entry)
549
+static void kill_multi_file_filter(struct hashmap *hashmap, struct subprocess_entry *entry)
550
{
551
if (!entry)
552
return;
@@ -571,8 +576,8 @@ static int start_multi_file_filter_fn(struct cmd2process *entry)
576
struct string_list cap_list = STRING_LIST_INIT_NODUP;
577
char *cap_buf;
578
const char *cap_name;
574
- struct child_process *process = &entry->process;
575
- const char *cmd = entry->cmd;
579
+ struct child_process *process = &entry->subprocess.process;
580
+ const char *cmd = entry->subprocess.cmd;
581
582
sigchain_push(SIGPIPE, SIG_IGN);
583
@@ -632,9 +637,9 @@ static struct cmd2process *start_multi_file_filter(struct hashmap *hashmap, cons
637
const char *argv[] = { cmd, NULL };
638
639
entry = xmalloc(sizeof(*entry));
635
- entry->cmd = cmd;
640
+ entry->subprocess.cmd = cmd;
641
entry->supported_capabilities = 0;
637
- process = &entry->process;
642
+ process = &entry->subprocess.process;
643
644
child_process_init(process);
645
process->argv = argv;
@@ -654,7 +659,7 @@ static struct cmd2process *start_multi_file_filter(struct hashmap *hashmap, cons
659
err = start_multi_file_filter_fn(entry);
660
if (err) {
661
error("initialization for external filter '%s' failed", cmd);
657
- kill_multi_file_filter(hashmap, entry);
662
+ kill_multi_file_filter(hashmap, &entry->subprocess);
663
return NULL;
664
}
665
@@ -678,7 +683,7 @@ static int apply_multi_file_filter(const char *path, const char *src, size_t len
683
hashmap_init(&cmd_process_map, (hashmap_cmp_fn) cmd2process_cmp, 0);
684
entry = NULL;
685
} else {
681
- entry = find_multi_file_filter_entry(&cmd_process_map, cmd);
686
+ entry = (struct cmd2process *)find_multi_file_filter_entry(&cmd_process_map, cmd);
687
}
688
689
fflush(NULL);
@@ -688,7 +693,7 @@ static int apply_multi_file_filter(const char *path, const char *src, size_t len
693
if (!entry)
694
return 0;
695
}
691
- process = &entry->process;
696
+ process = &entry->subprocess.process;
697
698
if (!(wanted_capability & entry->supported_capabilities))
699
return 0;
@@ -759,7 +764,7 @@ done:
764
* Force shutdown and restart if another blob requires filtering.
765
*/
766
error("external filter '%s' failed", cmd);
762
- kill_multi_file_filter(&cmd_process_map, entry);
767
+ kill_multi_file_filter(&cmd_process_map, &entry->subprocess);
768
}
769
} else {
770
strbuf_swap(dst, &nbuf);