Convert the users of for_each_string_list to for_each_string_list_item macro
The rule for selecting the candidates for conversion is: if the callback function returns only 0 (the condition for for_each_string_list to exit early), than it can be safely converted to the macro. A notable exception are the callers in builtin/remote.c. If converted, the readability in the file will suffer greately. Besides, the code is not very performance critical (at the moment, at least): it does output formatting of the list of remotes. Signed-off-by: Alex Riesen <raa.lkml@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
8d31635ce2
commit
8a57c6e943
46
notes.c
46
notes.c
@ -877,14 +877,6 @@ void string_list_add_refs_from_colon_sep(struct string_list *list,
|
||||
strbuf_release(&globbuf);
|
||||
}
|
||||
|
||||
static int string_list_add_refs_from_list(struct string_list_item *item,
|
||||
void *cb)
|
||||
{
|
||||
struct string_list *list = cb;
|
||||
string_list_add_refs_by_glob(list, item->string);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int notes_display_config(const char *k, const char *v, void *cb)
|
||||
{
|
||||
int *load_refs = cb;
|
||||
@ -947,30 +939,18 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
|
||||
load_subtree(t, &root_tree, t->root, 0);
|
||||
}
|
||||
|
||||
struct load_notes_cb_data {
|
||||
int counter;
|
||||
struct notes_tree **trees;
|
||||
};
|
||||
|
||||
static int load_one_display_note_ref(struct string_list_item *item,
|
||||
void *cb_data)
|
||||
{
|
||||
struct load_notes_cb_data *c = cb_data;
|
||||
struct notes_tree *t = xcalloc(1, sizeof(struct notes_tree));
|
||||
init_notes(t, item->string, combine_notes_ignore, 0);
|
||||
c->trees[c->counter++] = t;
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct notes_tree **load_notes_trees(struct string_list *refs)
|
||||
{
|
||||
struct string_list_item *item;
|
||||
int counter = 0;
|
||||
struct notes_tree **trees;
|
||||
struct load_notes_cb_data cb_data;
|
||||
trees = xmalloc((refs->nr+1) * sizeof(struct notes_tree *));
|
||||
cb_data.counter = 0;
|
||||
cb_data.trees = trees;
|
||||
for_each_string_list(refs, load_one_display_note_ref, &cb_data);
|
||||
trees[cb_data.counter] = NULL;
|
||||
for_each_string_list_item(item, refs) {
|
||||
struct notes_tree *t = xcalloc(1, sizeof(struct notes_tree));
|
||||
init_notes(t, item->string, combine_notes_ignore, 0);
|
||||
trees[counter++] = t;
|
||||
}
|
||||
trees[counter] = NULL;
|
||||
return trees;
|
||||
}
|
||||
|
||||
@ -995,10 +975,12 @@ void init_display_notes(struct display_notes_opt *opt)
|
||||
|
||||
git_config(notes_display_config, &load_config_refs);
|
||||
|
||||
if (opt && opt->extra_notes_refs)
|
||||
for_each_string_list(opt->extra_notes_refs,
|
||||
string_list_add_refs_from_list,
|
||||
&display_notes_refs);
|
||||
if (opt && opt->extra_notes_refs) {
|
||||
struct string_list_item *item;
|
||||
for_each_string_list_item(item, opt->extra_notes_refs)
|
||||
string_list_add_refs_by_glob(&display_notes_refs,
|
||||
item->string);
|
||||
}
|
||||
|
||||
display_notes_trees = load_notes_trees(&display_notes_refs);
|
||||
string_list_clear(&display_notes_refs, 0);
|
||||
|
Reference in New Issue
Block a user