ref-filter: make ref_array_item allocation more consistent

We have a helper function to allocate ref_array_item structs, but it only takes a subset of the possible fields in the struct as initializers. We could have it accept an argument for _every_ field, but that becomes a pain for the fields which some callers don't want to set initially. Instead, let's be explicit that it takes only the minimum required to create the ref, and that callers should then fill in the rest themselves. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Apr 6, 2018 at 14:59 UTC 0ffaa00f453978bffc4ff0f8a45ea0a52549e7cd
1 file changed +11 -7
ref-filter.c
+11 -7
@@ -1824,15 +1824,18 @@ static const struct object_id *match_points_at(struct oid_array *points_at,
1824 return NULL;
1825 }
1826
1827 -/* Allocate space for a new ref_array_item and copy the objectname and flag to it */
1827 +/*
1828 + * Allocate space for a new ref_array_item and copy the name and oid to it.
1829 + *
1830 + * Callers can then fill in other struct members at their leisure.
1831 + */
1832 static struct ref_array_item *new_ref_array_item(const char *refname,
1829 - const struct object_id *oid,
1830 - int flag)
1833 + const struct object_id *oid)
1834 {
1835 struct ref_array_item *ref;
1836 +
1837 FLEX_ALLOC_STR(ref, refname, refname);
1838 oidcpy(&ref->objectname, oid);
1835 - ref->flag = flag;
1839
1840 return ref;
1841 }
@@ -1927,12 +1930,13 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
1930 * to do its job and the resulting list may yet to be pruned
1931 * by maxcount logic.
1932 */
1930 - ref = new_ref_array_item(refname, oid, flag);
1933 + ref = new_ref_array_item(refname, oid);
1934 ref->commit = commit;
1935 + ref->flag = flag;
1936 + ref->kind = kind;
1937
1938 REALLOC_ARRAY(ref_cbdata->array->items, ref_cbdata->array->nr + 1);
1939 ref_cbdata->array->items[ref_cbdata->array->nr++] = ref;
1935 - ref->kind = kind;
1940 return 0;
1941 }
1942
@@ -2169,7 +2173,7 @@ void pretty_print_ref(const char *name, const struct object_id *oid,
2173 const struct ref_format *format)
2174 {
2175 struct ref_array_item *ref_item;
2172 - ref_item = new_ref_array_item(name, oid, 0);
2176 + ref_item = new_ref_array_item(name, oid);
2177 ref_item->kind = ref_kind_from_refname(name);
2178 show_ref_array_item(ref_item, format);
2179 free_array_item(ref_item);