Skip to content

Commit 0ffaa00

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 53df97a commit 0ffaa00

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

ref-filter.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,15 +1824,18 @@ static const struct object_id *match_points_at(struct oid_array *points_at,
18241824
return NULL;
18251825
}
18261826

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+
*/
18281832
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)
18311834
{
18321835
struct ref_array_item *ref;
1836+
18331837
FLEX_ALLOC_STR(ref, refname, refname);
18341838
oidcpy(&ref->objectname, oid);
1835-
ref->flag = flag;
18361839

18371840
return ref;
18381841
}
@@ -1927,12 +1930,13 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
19271930
* to do its job and the resulting list may yet to be pruned
19281931
* by maxcount logic.
19291932
*/
1930-
ref = new_ref_array_item(refname, oid, flag);
1933+
ref = new_ref_array_item(refname, oid);
19311934
ref->commit = commit;
1935+
ref->flag = flag;
1936+
ref->kind = kind;
19321937

19331938
REALLOC_ARRAY(ref_cbdata->array->items, ref_cbdata->array->nr + 1);
19341939
ref_cbdata->array->items[ref_cbdata->array->nr++] = ref;
1935-
ref->kind = kind;
19361940
return 0;
19371941
}
19381942

@@ -2169,7 +2173,7 @@ void pretty_print_ref(const char *name, const struct object_id *oid,
21692173
const struct ref_format *format)
21702174
{
21712175
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);
21732177
ref_item->kind = ref_kind_from_refname(name);
21742178
show_ref_array_item(ref_item, format);
21752179
free_array_item(ref_item);

0 commit comments

Comments
 (0)