Re: [PATCH v2 4/6] bisect--helper: `bisect_reset` shell function in C
On Wed, Jun 15, 2016 at 10:00 AM, Pranit Bauva <pranit.bauva@gmail.com> wrote:
Show 18 quoted lines
> Reimplement `bisect_reset` shell function in C and add a `--bisect-reset`
> subcommand to `git bisect--helper` to call it from git-bisect.sh .
> [...]
> Signed-off-by: Pranit Bauva <pranit.bauva@gmail.com>
> ---
> diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c
> @@ -123,12 +127,48 @@ static int bisect_clean_state(void)
> +static int bisect_reset(const char *commit)
> +{
> + struct strbuf branch = STRBUF_INIT;
> +
> + if (!commit) {
> + if (strbuf_read_file(&branch, git_path_bisect_start(), 0) < 1) {
> + printf("We are not bisecting.\n");
> + return 0;
> + }
> + strbuf_rtrim(&branch);
> +Style: unnecessary blank line
Show 5 quoted lines
> + } else {
> + struct object_id oid;
> + if (get_oid(commit, &oid))
> + return error(_("'%s' is not a valid commit"), commit);
> + strbuf_addf(&branch, "%s", commit);strbuf_addstr(&branch, commit);
Show 18 quoted lines
> + }
> +
> + if (!file_exists(git_path_bisect_head())) {
> + struct argv_array argv = ARGV_ARRAY_INIT;
> + argv_array_pushl(&argv, "checkout", branch.buf, "--", NULL);
> + if (run_command_v_opt(argv.argv, RUN_GIT_CMD)) {
> + error(_("Could not check out original HEAD '%s'. Try"
> + "'git bisect reset <commit>'."), branch.buf);
> + strbuf_release(&branch);
> + argv_array_clear(&argv);
> + return -1;
> + }
> + argv_array_clear(&argv);
> + }
> +
> + strbuf_release(&branch);
> + return bisect_clean_state();
> +}