|
5 | 5 | #include "sub-process.h"
|
6 | 6 | #include "sigchain.h"
|
7 | 7 | #include "pkt-line.h"
|
| 8 | +#include "quote.h" |
8 | 9 |
|
9 | 10 | int cmd2process_cmp(const void *cmp_data UNUSED,
|
10 | 11 | const struct hashmap_entry *eptr,
|
@@ -119,6 +120,52 @@ int subprocess_start(struct hashmap *hashmap, struct subprocess_entry *entry, co
|
119 | 120 | return 0;
|
120 | 121 | }
|
121 | 122 |
|
| 123 | +int subprocess_start_strvec(struct hashmap *hashmap, |
| 124 | + struct subprocess_entry *entry, |
| 125 | + int is_git_cmd, |
| 126 | + const struct strvec *argv, |
| 127 | + subprocess_start_fn startfn) |
| 128 | +{ |
| 129 | + int err; |
| 130 | + int k; |
| 131 | + struct child_process *process; |
| 132 | + struct strbuf quoted = STRBUF_INIT; |
| 133 | + |
| 134 | + process = &entry->process; |
| 135 | + |
| 136 | + child_process_init(process); |
| 137 | + for (k = 0; k < argv->nr; k++) |
| 138 | + strvec_push(&process->args, argv->v[k]); |
| 139 | + process->use_shell = 1; |
| 140 | + process->in = -1; |
| 141 | + process->out = -1; |
| 142 | + process->git_cmd = is_git_cmd; |
| 143 | + process->clean_on_exit = 1; |
| 144 | + process->clean_on_exit_handler = subprocess_exit_handler; |
| 145 | + process->trace2_child_class = "subprocess"; |
| 146 | + |
| 147 | + sq_quote_argv_pretty("ed, argv->v); |
| 148 | + entry->cmd = strbuf_detach("ed, NULL); |
| 149 | + |
| 150 | + err = start_command(process); |
| 151 | + if (err) { |
| 152 | + error("cannot fork to run subprocess '%s'", entry->cmd); |
| 153 | + return err; |
| 154 | + } |
| 155 | + |
| 156 | + hashmap_entry_init(&entry->ent, strhash(entry->cmd)); |
| 157 | + |
| 158 | + err = startfn(entry); |
| 159 | + if (err) { |
| 160 | + error("initialization for subprocess '%s' failed", entry->cmd); |
| 161 | + subprocess_stop(hashmap, entry); |
| 162 | + return err; |
| 163 | + } |
| 164 | + |
| 165 | + hashmap_add(hashmap, &entry->ent); |
| 166 | + return 0; |
| 167 | +} |
| 168 | + |
122 | 169 | static int handshake_version(struct child_process *process,
|
123 | 170 | const char *welcome_prefix, int *versions,
|
124 | 171 | int *chosen_version)
|
|
0 commit comments