Palmer Dabbelt <[email protected]> wrote:
> diff --git a/builtin/fetch.c b/builtin/fetch.c
> index 8aa6a0caf1ab..fa12ad44e7d9 100644
> --- a/builtin/fetch.c
> +++ b/builtin/fetch.c
<snip>
> +static int next_remote_to_fetch(struct child_process *cp,
> + struct strbuf *out,
> + void *state_uncast,
> + void **task_state_out)
> +{
> + int i;
> + struct fetch_remote *state = state_uncast;
> + struct fetch_remote_task *task_state = NULL;
> + const char *remote_name;
> +
> + if (state->next_remote_index >= state->all_remotes->nr)
> + return 0;
> +
> + remote_name =
> state->all_remotes->items[state->next_remote_index].string;
> + state->next_remote_index++;
> +
> + /*
> + * Finds somewhere to store the state for a task. This is guarnteed to
> + * succeed because there are always enough tasks allocated to cover the
> + * number that have been requested to run in parallel. Rather than
> + * bothering with some sort of free list, this just brute force
> + * searches for a free task. The assumption is that there aren't that
> + * many tasks to look through.
> + */
> + for (i = 0; i < state->task_count; ++i) {
> + if (!state->all_tasks[i].in_use) {
> + task_state = state->all_tasks + i;
> + break;
> + }
> + }
Fwiw, I added list.h, the linked-list derived from the Linux
kernel to simplify usage of free lists, queues, etc...
I think it could improve readability, too; but I'm not really
a C programmer and prefer high-level scripting languages.