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:
Alex Riesen
2010-07-03 14:41:54 +02:00
committed by Junio C Hamano
parent 8d31635ce2
commit 8a57c6e943
4 changed files with 66 additions and 105 deletions

View File

@ -544,40 +544,14 @@ static int will_fetch(struct ref **head, const unsigned char *sha1)
return 0;
}
struct tag_data {
struct ref **head;
struct ref ***tail;
};
static int add_to_tail(struct string_list_item *item, void *cb_data)
{
struct tag_data *data = (struct tag_data *)cb_data;
struct ref *rm = NULL;
/* We have already decided to ignore this item */
if (!item->util)
return 0;
rm = alloc_ref(item->string);
rm->peer_ref = alloc_ref(item->string);
hashcpy(rm->old_sha1, item->util);
**data->tail = rm;
*data->tail = &rm->next;
return 0;
}
static void find_non_local_tags(struct transport *transport,
struct ref **head,
struct ref ***tail)
{
struct string_list existing_refs = { NULL, 0, 0, 0 };
struct string_list remote_refs = { NULL, 0, 0, 0 };
struct tag_data data;
const struct ref *ref;
struct string_list_item *item = NULL;
data.head = head; data.tail = tail;
for_each_ref(add_existing, &existing_refs);
for (ref = transport_get_remote_refs(transport); ref; ref = ref->next) {
@ -631,10 +605,20 @@ static void find_non_local_tags(struct transport *transport,
item->util = NULL;
/*
* For all the tags in the remote_refs string list, call
* add_to_tail to add them to the list of refs to be fetched
* For all the tags in the remote_refs string list,
* add them to the list of refs to be fetched
*/
for_each_string_list(&remote_refs, add_to_tail, &data);
for_each_string_list_item(item, &remote_refs) {
/* Unless we have already decided to ignore this item... */
if (item->util)
{
struct ref *rm = alloc_ref(item->string);
rm->peer_ref = alloc_ref(item->string);
hashcpy(rm->old_sha1, item->util);
**tail = rm;
*tail = &rm->next;
}
}
string_list_clear(&remote_refs, 0);
}