ref-filter: populate symref from iterator
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
John Cai committed
Aug 9, 2024 at 15:37 UTC
a30ce14a806b6b726ce87fc231a3536e8cc0b0fa
1 file changed
+12
-5
ref-filter.c
+12
-5
@@ -2343,6 +2343,12 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
2343
2344
CALLOC_ARRAY(ref->value, used_atom_cnt);
2345
2346
+ /**
2347
+ * NEEDSWORK: The following code might be unncessary if all codepaths
2348
+ * that call populate_value() populates the symref member of ref_array_item
2349
+ * like in apply_ref_filter(). Currently pretty_print_ref() is the only codepath
2350
+ * that calls populate_value() without first populating symref.
2351
+ */
2352
if (need_symref && (ref->flag & REF_ISSYMREF) && !ref->symref) {
2353
ref->symref = refs_resolve_refdup(get_main_ref_store(the_repository),
2354
ref->refname,
@@ -2783,7 +2789,7 @@ static int filter_ref_kind(struct ref_filter *filter, const char *refname)
2789
return ref_kind_from_refname(refname);
2790
}
2791
2786
-static struct ref_array_item *apply_ref_filter(const char *refname, const struct object_id *oid,
2792
+static struct ref_array_item *apply_ref_filter(const char *refname, const char *referent, const struct object_id *oid,
2793
int flag, struct ref_filter *filter)
2794
{
2795
struct ref_array_item *ref;
@@ -2852,6 +2858,7 @@ static struct ref_array_item *apply_ref_filter(const char *refname, const struct
2858
ref->commit = commit;
2859
ref->flag = flag;
2860
ref->kind = kind;
2861
+ ref->symref = xstrdup_or_null(referent);
2862
2863
return ref;
2864
}
@@ -2865,12 +2872,12 @@ struct ref_filter_cbdata {
2872
* A call-back given to for_each_ref(). Filter refs and keep them for
2873
* later object processing.
2874
*/
2868
-static int filter_one(const char *refname, const char *referent UNUSED, const struct object_id *oid, int flag, void *cb_data)
2875
+static int filter_one(const char *refname, const char *referent, const struct object_id *oid, int flag, void *cb_data)
2876
{
2877
struct ref_filter_cbdata *ref_cbdata = cb_data;
2878
struct ref_array_item *ref;
2879
2873
- ref = apply_ref_filter(refname, oid, flag, ref_cbdata->filter);
2880
+ ref = apply_ref_filter(refname, referent, oid, flag, ref_cbdata->filter);
2881
if (ref)
2882
ref_array_append(ref_cbdata->array, ref);
2883
@@ -2900,13 +2907,13 @@ struct ref_filter_and_format_cbdata {
2907
} internal;
2908
};
2909
2903
-static int filter_and_format_one(const char *refname, const char *referent UNUSED, const struct object_id *oid, int flag, void *cb_data)
2910
+static int filter_and_format_one(const char *refname, const char *referent, const struct object_id *oid, int flag, void *cb_data)
2911
{
2912
struct ref_filter_and_format_cbdata *ref_cbdata = cb_data;
2913
struct ref_array_item *ref;
2914
struct strbuf output = STRBUF_INIT, err = STRBUF_INIT;
2915
2909
- ref = apply_ref_filter(refname, oid, flag, ref_cbdata->filter);
2916
+ ref = apply_ref_filter(refname, referent, oid, flag, ref_cbdata->filter);
2917
if (!ref)
2918
return 0;
2919