summaryrefslogtreecommitdiff
path: root/ref-filter.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2018-04-06 18:59:26 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-04-08 21:14:45 (GMT)
commit0ffaa00f453978bffc4ff0f8a45ea0a52549e7cd (patch)
tree201dd562cff9cec7fccda22d0868a6eea84ef632 /ref-filter.c
parent53df97a29d78070f3dfaf3e4d9a5ae61f33d7906 (diff)
downloadgit-0ffaa00f453978bffc4ff0f8a45ea0a52549e7cd.zip
git-0ffaa00f453978bffc4ff0f8a45ea0a52549e7cd.tar.gz
git-0ffaa00f453978bffc4ff0f8a45ea0a52549e7cd.tar.bz2
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>
Diffstat (limited to 'ref-filter.c')
-rw-r--r--ref-filter.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/ref-filter.c b/ref-filter.c
index ade97a8..c1c3cc9 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1824,15 +1824,18 @@ static const struct object_id *match_points_at(struct oid_array *points_at,
return NULL;
}
-/* Allocate space for a new ref_array_item and copy the objectname and flag to it */
+/*
+ * Allocate space for a new ref_array_item and copy the name and oid to it.
+ *
+ * Callers can then fill in other struct members at their leisure.
+ */
static struct ref_array_item *new_ref_array_item(const char *refname,
- const struct object_id *oid,
- int flag)
+ const struct object_id *oid)
{
struct ref_array_item *ref;
+
FLEX_ALLOC_STR(ref, refname, refname);
oidcpy(&ref->objectname, oid);
- ref->flag = flag;
return ref;
}
@@ -1927,12 +1930,13 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
* to do its job and the resulting list may yet to be pruned
* by maxcount logic.
*/
- ref = new_ref_array_item(refname, oid, flag);
+ ref = new_ref_array_item(refname, oid);
ref->commit = commit;
+ ref->flag = flag;
+ ref->kind = kind;
REALLOC_ARRAY(ref_cbdata->array->items, ref_cbdata->array->nr + 1);
ref_cbdata->array->items[ref_cbdata->array->nr++] = ref;
- ref->kind = kind;
return 0;
}
@@ -2169,7 +2173,7 @@ void pretty_print_ref(const char *name, const struct object_id *oid,
const struct ref_format *format)
{
struct ref_array_item *ref_item;
- ref_item = new_ref_array_item(name, oid, 0);
+ ref_item = new_ref_array_item(name, oid);
ref_item->kind = ref_kind_from_refname(name);
show_ref_array_item(ref_item, format);
free_array_item(ref_item);