| 216 | } |
| 217 | |
| 218 | static char *apply_command(struct conf_info *conf, const char *arg) |
| 219 | { |
| 220 | struct strbuf cmd = STRBUF_INIT; |
| 221 | struct strbuf buf = STRBUF_INIT; |
| 222 | struct child_process cp = CHILD_PROCESS_INIT; |
| 223 | char *result; |
| 224 | |
| 225 | if (conf->cmd) { |
| 226 | strbuf_addstr(&cmd, conf->cmd); |
| 227 | strvec_push(&cp.args, cmd.buf); |
| 228 | if (arg) |
| 229 | strvec_push(&cp.args, arg); |
| 230 | } else if (conf->command) { |
| 231 | strbuf_addstr(&cmd, conf->command); |
| 232 | if (arg) |
| 233 | strbuf_replace(&cmd, TRAILER_ARG_STRING, arg); |
| 234 | strvec_push(&cp.args, cmd.buf); |
| 235 | } |
| 236 | strvec_pushv(&cp.env, (const char **)local_repo_env); |
| 237 | cp.no_stdin = 1; |
| 238 | cp.use_shell = 1; |
| 239 | |
| 240 | if (capture_command(&cp, &buf, 1024)) { |
| 241 | error(_("running trailer command '%s' failed"), cmd.buf); |
| 242 | strbuf_release(&buf); |
| 243 | result = xstrdup(""); |
| 244 | } else { |
| 245 | strbuf_trim(&buf); |
| 246 | result = strbuf_detach(&buf, NULL); |
| 247 | } |
| 248 | |
| 249 | strbuf_release(&cmd); |
| 250 | return result; |
| 251 | } |
| 252 | |
| 253 | static void apply_item_command(struct trailer_item *in_tok, struct arg_item *arg_tok) |
| 254 | { |
no test coverage detected