Re: [PATCH v2 1/6] bisect--helper: `bisect_clean_state` shell function in C
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Jun 15, 2016, 18:04 UTC
- Message-ID
- <CAPig+cRfYS4FX+z4Yn-He_LctWdh7Ua56JU2HJs2C2+nTi5YyA@mail.gmail.com>
- In-Reply-To
- <20160615140026.10519-2-pranit.bauva@gmail.com>
On Wed, Jun 15, 2016 at 10:00 AM, Pranit Bauva <pranit.bauva@gmail.com> wrote:
Show 26 quoted lines
> Reimplement `bisect_clean_state` shell function in C and add a
> `bisect-clean-state` 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
> +static int mark_for_removal(const char *refname, const struct object_id *oid,
> + int flag, void *cb_data)
> +{
> + struct string_list *refs = cb_data;
> + char *ref = xstrfmt("refs/bisect/%s", refname);
> + string_list_append(refs, ref);
> + return 0;
> +}
> +
> +static int bisect_clean_state(void)
> +{
> + int result = 0;
> +
> + /* There may be some refs packed during bisection */
> + struct string_list refs_for_removal = STRING_LIST_INIT_NODUP;
> + for_each_ref_in("refs/bisect/", mark_for_removal, (void *) &refs_for_removal);
> + string_list_append(&refs_for_removal, xstrdup("BISECT_HEAD"));
> + result = delete_refs(&refs_for_removal);
> + string_list_clear(&refs_for_removal, 0);This is leaking all the strings added to 'refs_for_removal', isn't it? Either you need to loop over the items and free the strings manually, or (if it's not too ugly), set 'strdup_strings' before invoking string_list_clear().
Show 16 quoted lines
> + remove_path(git_path_bisect_expected_rev()); > + remove_path(git_path_bisect_ancestors_ok()); > + remove_path(git_path_bisect_log()); > + remove_path(git_path_bisect_names()); > + remove_path(git_path_bisect_run()); > + remove_path(git_path_bisect_write_terms()); > + /* Cleanup head-name if it got left by an old version of git-bisect */ > + remove_path(git_path_head_name()); > + /* > + * Cleanup BISECT_START last to support the --no-checkout option > + * introduced in the commit 4796e823a. > + */ > + remove_path(git_path_bisect_start()); > + > + return result; > +}