Thread (1 message) 1 message, 1 author, 2024-08-01

Re: [PATCH v2 3/3] ref-filter: populate symref from iterator

From: Junio C Hamano <hidden>
Date: 2024-08-01 16:51:57

"John Cai via GitGitGadget" [off-list ref] writes:
quoted hunk
From: John Cai <redacted>

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 <redacted>
---
 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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help