Skip to content

Commit f260505

Browse files
avargitster
authored andcommitted
string_list API users: use string_list_init_{no,}dup
Follow-up on the introduction of string_list_init_nodup() and string_list_init_dup() in the series merged in bd4232f (Merge branch 'ab/struct-init', 2021-07-16) and convert code that implicitly relied on xcalloc() being equivalent to the initializer to use xmalloc() and string_list_init_{no,}dup() instead. In the case of get_unmerged() in merge-recursive.c we used the combination of xcalloc() and assigning "1" to "strdup_strings" to get what we'd get via string_list_init_dup(), let's use that instead. Adjacent code in cmd_format_patch() will be changed in a subsequent commit, since we're changing that let's change the other in-tree patterns that do the same. Let's also convert a "x == NULL" to "!x" per our CodingGuidelines, as we need to change the "if" line anyway. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4b59b2d commit f260505

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

builtin/log.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
231231
}
232232

233233
if (mailmap) {
234-
rev->mailmap = xcalloc(1, sizeof(struct string_list));
234+
rev->mailmap = xmalloc(sizeof(struct string_list));
235+
string_list_init_nodup(rev->mailmap);
235236
read_mailmap(rev->mailmap);
236237
}
237238

@@ -2173,8 +2174,10 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
21732174
prepare_bases(&bases, base, list, nr);
21742175
}
21752176

2176-
if (in_reply_to || thread || cover_letter)
2177-
rev.ref_message_ids = xcalloc(1, sizeof(struct string_list));
2177+
if (in_reply_to || thread || cover_letter) {
2178+
rev.ref_message_ids = xmalloc(sizeof(*rev.ref_message_ids));
2179+
string_list_init_nodup(rev.ref_message_ids);
2180+
}
21782181
if (in_reply_to) {
21792182
const char *msgid = clean_message_id(in_reply_to);
21802183
string_list_append(rev.ref_message_ids, msgid);

builtin/shortlog.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ static void insert_one_record(struct shortlog *log,
8181
format_subject(&subject, oneline, " ");
8282
buffer = strbuf_detach(&subject, NULL);
8383

84-
if (item->util == NULL)
85-
item->util = xcalloc(1, sizeof(struct string_list));
84+
if (!item->util) {
85+
item->util = xmalloc(sizeof(struct string_list));
86+
string_list_init_nodup(item->util);
87+
}
8688
string_list_append(item->util, buffer);
8789
}
8890
}

merge-recursive.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,10 +522,10 @@ static struct stage_data *insert_stage_data(struct repository *r,
522522
*/
523523
static struct string_list *get_unmerged(struct index_state *istate)
524524
{
525-
struct string_list *unmerged = xcalloc(1, sizeof(struct string_list));
525+
struct string_list *unmerged = xmalloc(sizeof(struct string_list));
526526
int i;
527527

528-
unmerged->strdup_strings = 1;
528+
string_list_init_dup(unmerged);
529529

530530
/* TODO: audit for interaction with sparse-index. */
531531
ensure_full_index(istate);

0 commit comments

Comments
 (0)