Moving from using expand_data to ref_array_item structure. That helps us to reuse functions from ref-filter easier. Signed-off-by: Olga Telezhnaia <olyatelezhnaya@xxxxxxxxx> Mentored-by: Christian Couder <christian.couder@xxxxxxxxx> Mentored by: Jeff King <peff@xxxxxxxx> --- builtin/cat-file.c | 32 ++++++++++++++++++++------------ ref-filter.h | 5 +++++ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 67e7790d2f319..5b7bc34f1ec6d 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -183,27 +183,27 @@ static int is_atom(const char *atom, const char *s, int slen) } static void expand_atom(struct strbuf *sb, const char *atom, int len, - struct expand_data *data) + struct ref_array_item *item) { if (is_atom("objectname", atom, len)) - strbuf_addstr(sb, oid_to_hex(&data->oid)); + strbuf_addstr(sb, oid_to_hex(&item->objectname)); else if (is_atom("objecttype", atom, len)) - strbuf_addstr(sb, typename(data->type)); + strbuf_addstr(sb, typename(item->type)); else if (is_atom("objectsize", atom, len)) - strbuf_addf(sb, "%lu", data->size); + strbuf_addf(sb, "%lu", item->size); else if (is_atom("objectsize:disk", atom, len)) - strbuf_addf(sb, "%"PRIuMAX, (uintmax_t)data->disk_size); + strbuf_addf(sb, "%"PRIuMAX, (uintmax_t)item->disk_size); else if (is_atom("rest", atom, len)) { - if (data->rest) - strbuf_addstr(sb, data->rest); + if (item->rest) + strbuf_addstr(sb, item->rest); } else if (is_atom("deltabase", atom, len)) - strbuf_addstr(sb, oid_to_hex(&data->delta_base_oid)); + strbuf_addstr(sb, oid_to_hex(item->delta_base_oid)); } -static size_t expand_format(struct strbuf *sb, const char *start, void *vdata) +static size_t expand_format(struct strbuf *sb, const char *start, void *data) { const char *end; - struct expand_data *data = vdata; + struct ref_array_item *item = data; if (*start != '(') return 0; @@ -211,7 +211,7 @@ static size_t expand_format(struct strbuf *sb, const char *start, void *vdata) if (!end) die("format element '%s' does not end in ')'", start); - expand_atom(sb, start + 1, end - start - 1, data); + expand_atom(sb, start + 1, end - start - 1, item); return end - start + 1; } @@ -283,6 +283,7 @@ static void batch_object_write(const char *obj_name, struct batch_options *opt, struct expand_data *data) { struct strbuf buf = STRBUF_INIT; + struct ref_array_item item = {0}; if (!data->skip_object_info && sha1_object_info_extended(data->oid.hash, &data->info, @@ -293,7 +294,14 @@ static void batch_object_write(const char *obj_name, struct batch_options *opt, return; } - strbuf_expand(&buf, opt->format.format, expand_format, data); + item.objectname = data->oid; + item.type = data->type; + item.size = data->size; + item.disk_size = data->disk_size; + item.rest = data->rest; + item.delta_base_oid = &data->delta_base_oid; + + strbuf_expand(&buf, opt->format.format, expand_format, &item); strbuf_addch(&buf, '\n'); batch_write(opt, buf.buf, buf.len); strbuf_release(&buf); diff --git a/ref-filter.h b/ref-filter.h index 52e07dbe6864a..781921d4e0978 100644 --- a/ref-filter.h +++ b/ref-filter.h @@ -40,6 +40,11 @@ struct ref_array_item { const char *symref; struct commit *commit; struct atom_value *value; + enum object_type type; + unsigned long size; + off_t disk_size; + const char *rest; + struct object_id *delta_base_oid; char refname[FLEX_ARRAY]; }; -- https://github.com/git/git/pull/452