Re: [PATCH v2 3/3] ref-filter: populate symref from iterator
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Aug 1, 2024, 16:51 UTC
- Message-ID
- <xmqqwml0uqxi.fsf@gitster.g>
- In-Reply-To
- <3e147e7d850773f44b48d1b86e89aef1415a0ccd.1722524334.git.gitgitgadget@gmail.com>
"John Cai via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 34 quoted lines
> From: John Cai <johncai86@gmail.com>
>
> With a previous commit, the reference the symbolic ref points to is saved
> in the ref iterator records. Instead of making a separate call to
> resolve_refdup() each time, we can just populate the ref_array_item with
> the value from the iterator.
>
> Signed-off-by: John Cai <johncai86@gmail.com>
> ---
> ref-filter.c | 12 +++++++-----
> 1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/ref-filter.c b/ref-filter.c
> index 39997890feb..08997e59662 100644
> --- a/ref-filter.c
> +++ b/ref-filter.c
> @@ -2783,7 +2783,7 @@ static int filter_ref_kind(struct ref_filter *filter, const char *refname)
> return ref_kind_from_refname(refname);
> }
>
> -static struct ref_array_item *apply_ref_filter(const char *refname, const struct object_id *oid,
> +static struct ref_array_item *apply_ref_filter(const char *refname, const char *referent, const struct object_id *oid,
> int flag, struct ref_filter *filter)
> {
> struct ref_array_item *ref;
> @@ -2852,6 +2852,8 @@ static struct ref_array_item *apply_ref_filter(const char *refname, const struct
> ref->commit = commit;
> ref->flag = flag;
> ref->kind = kind;
> + if (flag & REF_ISSYMREF)
> + ref->symref = xstrdup_or_null(referent);
>
> return ref;
> }What is curious is that we do not lose any code from populate_value() with this change.
Is that because of this piece of code near the beginning of it?
CALLOC_ARRAY(ref->value, used_atom_cnt);
if (need_symref && (ref->flag & REF_ISSYMREF) && !ref->symref) {
ref->symref = refs_resolve_refdup(get_main_ref_store(the_repository),
ref->refname,
RESOLVE_REF_READING,
NULL, NULL);
if (!ref->symref)
ref->symref = xstrdup("");
}That is, if we somehow know the value of ref->symref for a ref that is known to be a symbolic ref (and when we know we need symref information in the output), we do not bother calling refs_resolve here to obtain the value.
Thanks.