Re: [PATCH v7 1/3] ref-filter: add worktreepath atom
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Feb 1, 2019, 22:31 UTC
- Message-ID
- <xmqqr2crw25r.fsf@gitster-ct.c.googlers.com>
- In-Reply-To
- <20190201220420.36216-2-nbelakovski@gmail.com>
nbelakovski@gmail.com writes:
Show 25 quoted lines
> +static void lazy_init_worktree_map(void)
> +{
> + if (ref_to_worktree_map.worktrees)
> + return;
> +
> + ref_to_worktree_map.worktrees = get_worktrees(0);
> + hashmap_init(&(ref_to_worktree_map.map), ref_to_worktree_map_cmpfnc, NULL, 0);
> + populate_worktree_map(&(ref_to_worktree_map.map), ref_to_worktree_map.worktrees);
> +}
> +
> +static char *get_worktree_path(const struct used_atom *atom, const struct ref_array_item *ref)
> +{
> + struct hashmap_entry entry;
> + struct ref_to_worktree_entry *lookup_result;
> +
> + lazy_init_worktree_map();
> +
> + hashmap_entry_init(&entry, strhash(ref->refname));
> + lookup_result = hashmap_get(&(ref_to_worktree_map.map), &entry, ref->refname);
> +
> + if (lookup_result)
> + return xstrdup(lookup_result->wt->path);
> + else
> + return xstrdup("");
> +}Makes more sense than the previous round; much simpler to have lazy-init in this function.
Thanks.