Skip to content

Commit 9e86e1a

Browse files
pks-tgitster
authored andcommitted
bisect: fix misuse of refs_for_each_ref_in()
All callers of `refs_for_each_ref_in()` pass in a string that is terminated with a trailing slash to indicate that they only want to see refs in that specific ref hierarchy. This is in fact a requirement if one wants to use this function, as the function trims the prefix from each yielded ref. So if there was a reference that was called "refs/bisect" as in our example, the result after trimming would be the empty string, and that's something we disallow. Fix this by adding the trailing slash. Furthermore, taking a closer look, we strip the prefix only to re-add it in `mark_for_removal()`. This is somewhat roundabout, as we can instead call `refs_for_each_fullref_in()` to not do any stripping at all. Do so to simplify the code a bit. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 7174098 commit 9e86e1a

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

bisect.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,7 @@ int estimate_bisect_steps(int all)
11801180
static int mark_for_removal(const struct reference *ref, void *cb_data)
11811181
{
11821182
struct string_list *refs = cb_data;
1183-
char *bisect_ref = xstrfmt("refs/bisect%s", ref->name);
1183+
char *bisect_ref = xstrdup(ref->name);
11841184
string_list_append(refs, bisect_ref);
11851185
return 0;
11861186
}
@@ -1191,9 +1191,9 @@ int bisect_clean_state(void)
11911191

11921192
/* There may be some refs packed during bisection */
11931193
struct string_list refs_for_removal = STRING_LIST_INIT_NODUP;
1194-
refs_for_each_ref_in(get_main_ref_store(the_repository),
1195-
"refs/bisect", mark_for_removal,
1196-
(void *) &refs_for_removal);
1194+
refs_for_each_fullref_in(get_main_ref_store(the_repository),
1195+
"refs/bisect/", NULL, mark_for_removal,
1196+
&refs_for_removal);
11971197
string_list_append(&refs_for_removal, xstrdup("BISECT_HEAD"));
11981198
string_list_append(&refs_for_removal, xstrdup("BISECT_EXPECTED_REV"));
11991199
result = refs_delete_refs(get_main_ref_store(the_repository),

0 commit comments

Comments
 (0)