Skip to content

Commit a30ce14

Browse files
john-caigitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e820771 commit a30ce14

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

ref-filter.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2343,6 +2343,12 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
23432343

23442344
CALLOC_ARRAY(ref->value, used_atom_cnt);
23452345

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+
*/
23462352
if (need_symref && (ref->flag & REF_ISSYMREF) && !ref->symref) {
23472353
ref->symref = refs_resolve_refdup(get_main_ref_store(the_repository),
23482354
ref->refname,
@@ -2783,7 +2789,7 @@ static int filter_ref_kind(struct ref_filter *filter, const char *refname)
27832789
return ref_kind_from_refname(refname);
27842790
}
27852791

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,
27872793
int flag, struct ref_filter *filter)
27882794
{
27892795
struct ref_array_item *ref;
@@ -2852,6 +2858,7 @@ static struct ref_array_item *apply_ref_filter(const char *refname, const struct
28522858
ref->commit = commit;
28532859
ref->flag = flag;
28542860
ref->kind = kind;
2861+
ref->symref = xstrdup_or_null(referent);
28552862

28562863
return ref;
28572864
}
@@ -2865,12 +2872,12 @@ struct ref_filter_cbdata {
28652872
* A call-back given to for_each_ref(). Filter refs and keep them for
28662873
* later object processing.
28672874
*/
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)
28692876
{
28702877
struct ref_filter_cbdata *ref_cbdata = cb_data;
28712878
struct ref_array_item *ref;
28722879

2873-
ref = apply_ref_filter(refname, oid, flag, ref_cbdata->filter);
2880+
ref = apply_ref_filter(refname, referent, oid, flag, ref_cbdata->filter);
28742881
if (ref)
28752882
ref_array_append(ref_cbdata->array, ref);
28762883

@@ -2900,13 +2907,13 @@ struct ref_filter_and_format_cbdata {
29002907
} internal;
29012908
};
29022909

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)
29042911
{
29052912
struct ref_filter_and_format_cbdata *ref_cbdata = cb_data;
29062913
struct ref_array_item *ref;
29072914
struct strbuf output = STRBUF_INIT, err = STRBUF_INIT;
29082915

2909-
ref = apply_ref_filter(refname, oid, flag, ref_cbdata->filter);
2916+
ref = apply_ref_filter(refname, referent, oid, flag, ref_cbdata->filter);
29102917
if (!ref)
29112918
return 0;
29122919

0 commit comments

Comments
 (0)