diff options
author | Junio C Hamano <gitster@pobox.com> | 2018-04-25 13:28:59 +0900 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2018-04-25 13:28:59 +0900 |
commit | b3d6c48c5fbec88e96799c5463f7fdddaa19e9d5 (patch) | |
tree | 50ac07cd92713658d4ba35afcaa86854b751f582 | |
parent | Merge branch 'en/doc-typoes' (diff) | |
parent | ref-filter: factor ref_array pushing into its own function (diff) | |
download | tgif-b3d6c48c5fbec88e96799c5463f7fdddaa19e9d5.tar.xz |
Merge branch 'jk/ref-array-push'
API clean-up aournd ref-filter code.
* jk/ref-array-push:
ref-filter: factor ref_array pushing into its own function
ref-filter: make ref_array_item allocation more consistent
ref-filter: use "struct object_id" consistently
-rw-r--r-- | builtin/tag.c | 2 | ||||
-rw-r--r-- | builtin/verify-tag.c | 2 | ||||
-rw-r--r-- | ref-filter.c | 36 | ||||
-rw-r--r-- | ref-filter.h | 10 |
4 files changed, 36 insertions, 14 deletions
diff --git a/builtin/tag.c b/builtin/tag.c index 8cff6d0b72..46a5c6a1da 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -118,7 +118,7 @@ static int verify_tag(const char *name, const char *ref, return -1; if (format->format) - pretty_print_ref(name, oid->hash, format); + pretty_print_ref(name, oid, format); return 0; } diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c index ad7b79fa5c..6fa04b751a 100644 --- a/builtin/verify-tag.c +++ b/builtin/verify-tag.c @@ -72,7 +72,7 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix) } if (format.format) - pretty_print_ref(name, oid.hash, &format); + pretty_print_ref(name, &oid, &format); } return had_error; } diff --git a/ref-filter.c b/ref-filter.c index a847838484..ac82f9f21e 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1828,15 +1828,30 @@ 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 unsigned char *objectname, - int flag) + const struct object_id *oid) { struct ref_array_item *ref; + FLEX_ALLOC_STR(ref, refname, refname); - hashcpy(ref->objectname.hash, objectname); - ref->flag = flag; + oidcpy(&ref->objectname, oid); + + return ref; +} + +struct ref_array_item *ref_array_push(struct ref_array *array, + const char *refname, + const struct object_id *oid) +{ + struct ref_array_item *ref = new_ref_array_item(refname, oid); + + ALLOC_GROW(array->items, array->nr + 1, array->alloc); + array->items[array->nr++] = ref; return ref; } @@ -1931,12 +1946,11 @@ 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->hash, flag); + ref = ref_array_push(ref_cbdata->array, refname, oid); ref->commit = commit; - - REALLOC_ARRAY(ref_cbdata->array->items, ref_cbdata->array->nr + 1); - ref_cbdata->array->items[ref_cbdata->array->nr++] = ref; + ref->flag = flag; ref->kind = kind; + return 0; } @@ -2169,11 +2183,11 @@ void show_ref_array_item(struct ref_array_item *info, putchar('\n'); } -void pretty_print_ref(const char *name, const unsigned char *sha1, +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, sha1, 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); diff --git a/ref-filter.h b/ref-filter.h index 0d98342b34..76cf87cb6c 100644 --- a/ref-filter.h +++ b/ref-filter.h @@ -132,7 +132,15 @@ void setup_ref_filter_porcelain_msg(void); * Print a single ref, outside of any ref-filter. Note that the * name must be a fully qualified refname. */ -void pretty_print_ref(const char *name, const unsigned char *sha1, +void pretty_print_ref(const char *name, const struct object_id *oid, const struct ref_format *format); +/* + * Push a single ref onto the array; this can be used to construct your own + * ref_array without using filter_refs(). + */ +struct ref_array_item *ref_array_push(struct ref_array *array, + const char *refname, + const struct object_id *oid); + #endif /* REF_FILTER_H */ |