Re: [PATCH v2 1/2] refs: Add for_each_worktree_ref for iterating over all worktree HEADs
- From
Junio C Hamano <gitster@pobox.com>
- Date
- May 20, 2017, 10:30 UTC
- Message-ID
- <xmqqy3trstup.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <20170518014210.94189-1-manishearth@gmail.com>
manishearth@gmail.com writes:
Show 17 quoted lines
> +int for_each_worktree_ref(each_ref_fn fn, void *cb_data)
> +{
> + int i, flag, retval = 0;
> + struct object_id oid;
> + struct worktree **worktrees = get_worktrees(GWT_SORT_LINKED);
> + struct commit* commit;
> + for (i = 0; worktrees[i]; i++) {
> + if ((commit = lookup_commit_reference(worktrees[i]->head_sha1))) {
> + oid = commit->object.oid;
> + if (!read_ref_full("HEAD", RESOLVE_REF_READING, oid.hash, &flag)) {
> + if ((retval = fn("HEAD", &oid, flag, cb_data)))
> + return retval;
> + }
> + }
> + }
> + return retval;
> +}I would have expected for-each-worktree-ref to iterate over all the refs in a given worktree, but that is not what this does. This instead iterates over worktrees and shows only their HEAD ref, no other refs. This helper is somewhat misnamed.
By the way, doesn't nd/prune-in-worktree topic that has been cooking in 'pu' supersede this change? It not just protects the commit at the tip of HEAD in each worktree, it also makes sure the ones in HEAD's reflog are not prematurely pruned.
Thanks.