/* * NEEDSWORK: this function can go once the legacy-difftool Perl script is * retired. * * We intentionally avoid reading the config directly here, to avoid messing up * the GIT_* environment variables when we need to fall back to exec()ing the * Perl script. */ static int use_builtin_difftool(void) { struct child_process cp = CHILD_PROCESS_INIT; struct strbuf out = STRBUF_INIT; int ret; argv_array_pushl(&cp.args, "config", "--bool", "difftool.usebuiltin", NULL); cp.git_cmd = 1; if (capture_command(&cp, &out, 6)) return 0; strbuf_trim(&out); ret = !strcmp("true", out.buf); strbuf_release(&out); return ret; }
static void wt_status_print_submodule_summary(struct wt_status *s, int uncommitted) { struct child_process sm_summary = CHILD_PROCESS_INIT; struct strbuf cmd_stdout = STRBUF_INIT; struct strbuf summary = STRBUF_INIT; char *summary_content; argv_array_pushf(&sm_summary.env_array, "GIT_INDEX_FILE=%s", s->index_file); argv_array_push(&sm_summary.args, "submodule"); argv_array_push(&sm_summary.args, "summary"); argv_array_push(&sm_summary.args, uncommitted ? "--files" : "--cached"); argv_array_push(&sm_summary.args, "--for-status"); argv_array_push(&sm_summary.args, "--summary-limit"); argv_array_pushf(&sm_summary.args, "%d", s->submodule_summary); if (!uncommitted) argv_array_push(&sm_summary.args, s->amend ? "HEAD^" : "HEAD"); sm_summary.git_cmd = 1; sm_summary.no_stdin = 1; capture_command(&sm_summary, &cmd_stdout, 1024); /* prepend header, only if there's an actual output */ if (cmd_stdout.len) { if (uncommitted) strbuf_addstr(&summary, _("Submodules changed but not updated:")); else strbuf_addstr(&summary, _("Submodule changes to be committed:")); strbuf_addstr(&summary, "\n\n"); } strbuf_addbuf(&summary, &cmd_stdout); strbuf_release(&cmd_stdout); if (s->display_comment_prefix) { size_t len; summary_content = strbuf_detach(&summary, &len); strbuf_add_commented_lines(&summary, summary_content, len); free(summary_content); } fputs(summary.buf, s->fp); strbuf_release(&summary); }
/* * Call the query-fsmonitor hook passing the time of the last saved results. */ static int query_fsmonitor(int version, uint64_t last_update, struct strbuf *query_result) { struct child_process cp = CHILD_PROCESS_INIT; char ver[64]; char date[64]; const char *argv[4]; if (!(argv[0] = core_fsmonitor)) return -1; snprintf(ver, sizeof(ver), "%d", version); snprintf(date, sizeof(date), "%" PRIuMAX, (uintmax_t)last_update); argv[1] = ver; argv[2] = date; argv[3] = NULL; cp.argv = argv; cp.use_shell = 1; cp.dir = get_git_work_tree(); return capture_command(&cp, query_result, 1024); }
/** * Given the repo and refspecs, sets fork_point to the point at which the * current branch forked from its remote-tracking branch. Returns 0 on success, * -1 on failure. */ static int get_rebase_fork_point(struct object_id *fork_point, const char *repo, const char *refspec) { int ret; struct branch *curr_branch; const char *remote_branch; struct child_process cp = CHILD_PROCESS_INIT; struct strbuf sb = STRBUF_INIT; curr_branch = branch_get("HEAD"); if (!curr_branch) return -1; if (refspec) remote_branch = get_tracking_branch(repo, refspec); else remote_branch = get_upstream_branch(repo); if (!remote_branch) return -1; argv_array_pushl(&cp.args, "merge-base", "--fork-point", remote_branch, curr_branch->name, NULL); cp.no_stdin = 1; cp.no_stderr = 1; cp.git_cmd = 1; ret = capture_command(&cp, &sb, GIT_SHA1_HEXSZ); if (ret) goto cleanup; ret = get_oid_hex(sb.buf, fork_point); if (ret) goto cleanup; cleanup: strbuf_release(&sb); return ret ? -1 : 0; }
static int use_builtin_stash(void) { struct child_process cp = CHILD_PROCESS_INIT; struct strbuf out = STRBUF_INIT; int ret, env = git_env_bool("GIT_TEST_STASH_USE_BUILTIN", -1); if (env != -1) return env; argv_array_pushl(&cp.args, "config", "--bool", "stash.usebuiltin", NULL); cp.git_cmd = 1; if (capture_command(&cp, &out, 6)) { strbuf_release(&out); return 1; } strbuf_trim(&out); ret = !strcmp("true", out.buf); strbuf_release(&out); return ret; }
static int is_submodule_commit_present(const char *path, unsigned char sha1[20]) { int is_present = 0; if (!add_submodule_odb(path) && lookup_commit_reference(sha1)) { /* Even if the submodule is checked out and the commit is * present, make sure it is reachable from a ref. */ struct child_process cp = CHILD_PROCESS_INIT; const char *argv[] = {"rev-list", "-n", "1", NULL, "--not", "--all", NULL}; struct strbuf buf = STRBUF_INIT; argv[3] = sha1_to_hex(sha1); cp.argv = argv; cp.env = local_repo_env; cp.git_cmd = 1; cp.no_stdin = 1; cp.dir = path; if (!capture_command(&cp, &buf, 1024) && !buf.len) is_present = 1; strbuf_release(&buf); } return is_present; }
/* * Launch child process to grep contents of a submodule */ static int grep_submodule_launch(struct grep_opt *opt, const struct grep_source *gs) { struct child_process cp = CHILD_PROCESS_INIT; int status, i; const char *end_of_base; const char *name; struct work_item *w = opt->output_priv; end_of_base = strchr(gs->name, ':'); if (gs->identifier && end_of_base) name = end_of_base + 1; else name = gs->name; prepare_submodule_repo_env(&cp.env_array); argv_array_push(&cp.env_array, GIT_DIR_ENVIRONMENT); /* Add super prefix */ argv_array_pushf(&cp.args, "--super-prefix=%s%s/", super_prefix ? super_prefix : "", name); argv_array_push(&cp.args, "grep"); /* * Add basename of parent project * When performing grep on a tree object the filename is prefixed * with the object's name: 'tree-name:filename'. In order to * provide uniformity of output we want to pass the name of the * parent project's object name to the submodule so the submodule can * prefix its output with the parent's name and not its own SHA1. */ if (gs->identifier && end_of_base) argv_array_pushf(&cp.args, "--parent-basename=%.*s", (int) (end_of_base - gs->name), gs->name); /* Add options */ for (i = 0; i < submodule_options.argc; i++) { /* * If there is a tree identifier for the submodule, add the * rev after adding the submodule options but before the * pathspecs. To do this we listen for the '--' and insert the * sha1 before pushing the '--' onto the child process argv * array. */ if (gs->identifier && !strcmp("--", submodule_options.argv[i])) { argv_array_push(&cp.args, sha1_to_hex(gs->identifier)); } argv_array_push(&cp.args, submodule_options.argv[i]); } cp.git_cmd = 1; cp.dir = gs->path; /* * Capture output to output buffer and check the return code from the * child process. A '0' indicates a hit, a '1' indicates no hit and * anything else is an error. */ status = capture_command(&cp, &w->out, 0); if (status && (status != 1)) { /* flush the buffer */ write_or_die(1, w->out.buf, w->out.len); die("process for submodule '%s' failed with exit code: %d", gs->name, status); } /* invert the return code to make a hit equal to 1 */ return !status; }
static int frame_command(shell_t *shell, shell_argv_t *cmd_argv, char *tag) { int argc = cmd_argv->argc; char **argv = cmd_argv->argv; char *op; char *id; int ret = 0; /* Set error reporting tag */ error_default_tag(tag); /* Check number of arguments */ if ( argc < 2 ) { shell_std_help(shell, argv[0]); return -1; } op = argv[1]; id = argv[2]; /* Operation 'geometry' and 'refresh': same as command capture (deprecated command compatibility) */ if ( strcmp(op, "geometry") == 0 ) { capture_command(shell, cmd_argv, tag); } /* The 'add' operation */ else if ( strcmp(op, "add") == 0 ) { /* Check number of arguments */ if ( argc < 3 ) { shell_std_help(shell, argv[0]); return -1; } /* Process 'frame add' command */ if ( frame_command_add(id, argc-3, argv+3) ) return -1; } /* The 'remove' operation */ else if ( strcmp(op, "remove") == 0 ) { /* Check number of arguments */ if ( argc > 3 ) { shell_std_help(shell, argv[0]); return -1; } /* Process 'frame remove' command */ if ( frame_command_remove(id) ) return -1; } /* The 'show' operation */ else if ( strcmp(op, "show") == 0 ) { /* Check number of arguments */ if ( argc > 3 ) { shell_std_help(shell, argv[0]); return -1; } /* Process 'frame show' command */ if ( frame_command_show(id) ) return -1; } /* The 'refresh' operation */ else if ( strcmp(op, "refresh") == 0 ) { /* Check number of arguments */ if ( argc > 3 ) { shell_std_help(shell, argv[0]); return -1; } /* Process 'frame refresh' command */ if ( frame_command_refresh(id) ) return -1; } /* The 'filter' operation */ else if ( strcmp(op, "filter") == 0 ) { /* Process 'frame filter' command */ if ( frame_command_filter(id, argc-3, argv+3) ) return -1; } /* The 'ocr' operation */ else if ( strcmp(op, "ocr") == 0 ) { /* Process 'frame filter' command */ if ( frame_command_ocr(id, argc-3, argv+3) ) return -1; } /* Unknown operation */ else { error(tag, "Unknown qualifier '%s'", argv[1]); shell_std_help(shell, argv[0]); return -1; } return ret; }
std::string capture_command(std::string const& command, environment_t const& env) { return capture_command(command, &env); }
std::string capture_command(std::string const& command) { return capture_command(command, 0); }
void start_echo() { start_process(sample_sound()); start_process(capture_command(),1); start_process(echo_control(),1); start_process(rpt(),1); }