Skip to content

Commit 6375a00

Browse files
peffgitster
authored andcommitted
bisect: simplify string_list memory handling
We declare the refs_for_removal string_list as NODUP, forcing us to manually allocate strings we insert. And then when it comes time to clean up, we set strdup_strings so that string_list_clear() will free them for us. This is a confusing pattern, and can be done much more simply by just declaring the list with the DUP initializer in the first place. It was written this way originally because one of the callsites generated the item using xstrfmt(). But that spot switched to a plain xstrdup() in the preceding commit. That means we can now just let the string_list code handle allocation itself. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 9e86e1a commit 6375a00

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

bisect.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,8 +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 = xstrdup(ref->name);
1184-
string_list_append(refs, bisect_ref);
1183+
string_list_append(refs, ref->name);
11851184
return 0;
11861185
}
11871186

@@ -1190,16 +1189,15 @@ int bisect_clean_state(void)
11901189
int result = 0;
11911190

11921191
/* There may be some refs packed during bisection */
1193-
struct string_list refs_for_removal = STRING_LIST_INIT_NODUP;
1192+
struct string_list refs_for_removal = STRING_LIST_INIT_DUP;
11941193
refs_for_each_fullref_in(get_main_ref_store(the_repository),
11951194
"refs/bisect/", NULL, mark_for_removal,
11961195
&refs_for_removal);
1197-
string_list_append(&refs_for_removal, xstrdup("BISECT_HEAD"));
1198-
string_list_append(&refs_for_removal, xstrdup("BISECT_EXPECTED_REV"));
1196+
string_list_append(&refs_for_removal, "BISECT_HEAD");
1197+
string_list_append(&refs_for_removal, "BISECT_EXPECTED_REV");
11991198
result = refs_delete_refs(get_main_ref_store(the_repository),
12001199
"bisect: remove", &refs_for_removal,
12011200
REF_NO_DEREF);
1202-
refs_for_removal.strdup_strings = 1;
12031201
string_list_clear(&refs_for_removal, 0);
12041202
unlink_or_warn(git_path_bisect_ancestors_ok());
12051203
unlink_or_warn(git_path_bisect_log());

0 commit comments

Comments
 (0)