diff options
author | Pranit Bauva <pranit.bauva@gmail.com> | 2017-09-29 06:49:39 +0000 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-10-06 14:12:33 +0900 |
commit | fb71a329964da0892cc11cc94b5b379b0803ed92 (patch) | |
tree | c7140d412c414f18ecef52d281ca3e61d98aa90c /bisect.c | |
parent | bisect--helper: `write_terms` shell function in C (diff) | |
download | tgif-fb71a329964da0892cc11cc94b5b379b0803ed92.tar.xz |
bisect--helper: `bisect_clean_state` shell function in C
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 .
Using `--bisect-clean-state` subcommand is a measure to port shell
function to C so as to use the existing test suite. As more functions
are ported, this subcommand will be retired but its implementation will
be called by bisect_reset() and bisect_start().
Also introduce a function `mark_for_removal` to store the refs which
need to be removed while iterating through the refs.
Mentored-by: Lars Schneider <larsxschneider@gmail.com>
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Pranit Bauva <pranit.bauva@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'bisect.c')
-rw-r--r-- | bisect.c | 42 |
1 files changed, 42 insertions, 0 deletions
@@ -433,7 +433,12 @@ static int read_bisect_refs(void) static GIT_PATH_FUNC(git_path_bisect_names, "BISECT_NAMES") static GIT_PATH_FUNC(git_path_bisect_expected_rev, "BISECT_EXPECTED_REV") +static GIT_PATH_FUNC(git_path_bisect_ancestors_ok, "BISECT_ANCESTORS_OK") +static GIT_PATH_FUNC(git_path_bisect_run, "BISECT_RUN") +static GIT_PATH_FUNC(git_path_bisect_start, "BISECT_START") +static GIT_PATH_FUNC(git_path_bisect_log, "BISECT_LOG") static GIT_PATH_FUNC(git_path_bisect_terms, "BISECT_TERMS") +static GIT_PATH_FUNC(git_path_head_name, "head-name") static void read_bisect_paths(struct argv_array *array) { @@ -1044,3 +1049,40 @@ int estimate_bisect_steps(int all) return (e < 3 * x) ? n : n - 1; } + +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; +} + +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("bisect: remove", &refs_for_removal, REF_NODEREF); + refs_for_removal.strdup_strings = 1; + string_list_clear(&refs_for_removal, 0); + unlink_or_warn(git_path_bisect_expected_rev()); + unlink_or_warn(git_path_bisect_ancestors_ok()); + unlink_or_warn(git_path_bisect_log()); + unlink_or_warn(git_path_bisect_names()); + unlink_or_warn(git_path_bisect_run()); + unlink_or_warn(git_path_bisect_terms()); + /* Cleanup head-name if it got left by an old version of git-bisect */ + unlink_or_warn(git_path_head_name()); + /* + * Cleanup BISECT_START last to support the --no-checkout option + * introduced in the commit 4796e823a. + */ + unlink_or_warn(git_path_bisect_start()); + + return result; +} |