MCPcopy Index your code
hub / github.com/git/git / prepare_cmd

Function prepare_cmd

run-command.c:410–448  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

408}
409
410static int prepare_cmd(struct strvec *out, const struct child_process *cmd)
411{
412 if (!cmd->args.v[0])
413 BUG("command is empty");
414
415 /*
416 * Add SHELL_PATH so in the event exec fails with ENOEXEC we can
417 * attempt to interpret the command with 'sh'.
418 */
419 strvec_push(out, SHELL_PATH);
420
421 if (cmd->git_cmd) {
422 prepare_git_cmd(out, cmd->args.v);
423 } else if (cmd->use_shell) {
424 prepare_shell_cmd(out, cmd->args.v);
425 } else {
426 strvec_pushv(out, cmd->args.v);
427 }
428
429 /*
430 * If there are no dir separator characters in the command then perform
431 * a path lookup and use the resolved path as the command to exec. If
432 * there are dir separator characters, we have exec attempt to invoke
433 * the command directly.
434 */
435 if (!has_dir_sep(out->v[1])) {
436 char *program = locate_in_PATH(out->v[1]);
437 if (program) {
438 free((char *)out->v[1]);
439 out->v[1] = program;
440 } else {
441 strvec_clear(out);
442 errno = ENOENT;
443 return -1;
444 }
445 }
446
447 return 0;
448}
449
450static char **prep_childenv(const char *const *deltaenv)
451{

Callers 1

start_commandFunction · 0.85

Calls 6

strvec_pushFunction · 0.85
prepare_git_cmdFunction · 0.85
prepare_shell_cmdFunction · 0.85
strvec_pushvFunction · 0.85
locate_in_PATHFunction · 0.85
strvec_clearFunction · 0.85

Tested by

no test coverage detected