{"thread":{"id":"47756","subject":"[PATCH RFC v2 08/25] ref-filter: reuse parse_ref_filter_atom()","startedAt":"2018-02-05T11:27:45Z","lastAt":"2018-02-05T21:19:45Z","messageCount":26,"participants":["Olga Telezhnaya","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":25},"messages":[{"id":"338187","messageId":"0102016165b8b432-757d5546-a944-4a4f-abf2-9b6206184e23-000000@eu-west-1.amazonses.com","threadId":"47756","inReplyTo":"0102016165b8b3c4-54efe4c4-6d19-435d-b5b9-6c727771353b-000000@eu-west-1.amazonses.com","subject":"[PATCH RFC v2 08/25] ref-filter: reuse parse_ref_filter_atom()","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-02-05T11:27:39Z","receivedAt":"2018-02-05T11:27:45Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Continue migrating formatting logic from cat-file to ref-filter.\nReuse parse_ref_filter_atom() for unifying all processes in ref-filter\nand further removing of mark_atom_in_object_info().\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored by: Jeff King <peff@peff.net>\n---\n ref-filter.c | 34 +++++++++++++++++++++++++---------\n 1 file changed, 25 insertions(+), 9 deletions(-)\n\ndiff --git a/ref-filter.c b/ref-filter.c\nindex ff87e632f463c..5c75259b1ab8c 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -100,6 +100,7 @@ static struct used_atom {\n \t} u;\n } *used_atom;\n static int used_atom_cnt, need_tagged, need_symref;\n+struct expand_data *cat_file_info;\n \n static void color_atom_parser(const struct ref_format *format, struct used_atom *atom, const char *color_value)\n {\n@@ -251,6 +252,16 @@ static void objectname_atom_parser(const struct ref_format *format, struct used_\n \t\tdie(_(\"unrecognized %%(objectname) argument: %s\"), arg);\n }\n \n+static void objectsize_atom_parser(const struct ref_format *format, struct used_atom *atom, const char *arg)\n+{\n+\tif (!arg)\n+\t\t; /* default to normal object size */\n+\telse if (!strcmp(arg, \"disk\"))\n+\t\tcat_file_info->info.disk_sizep = &cat_file_info->disk_size;\n+\telse\n+\t\tdie(_(\"urecognized %%(objectsize) argument: %s\"), arg);\n+}\n+\n static void refname_atom_parser(const struct ref_format *format, struct used_atom *atom, const char *arg)\n {\n \trefname_atom_parser_internal(&atom->u.refname, arg, atom->name);\n@@ -371,6 +382,14 @@ static struct valid_atom {\n \t{ \"else\" },\n };\n \n+static struct valid_atom valid_cat_file_atom[] = {\n+\t{ \"objectname\" },\n+\t{ \"objecttype\" },\n+\t{ \"objectsize\", FIELD_ULONG, objectsize_atom_parser },\n+\t{ \"rest\" },\n+\t{ \"deltabase\" },\n+};\n+\n #define REF_FORMATTING_STATE_INIT  { 0, NULL }\n \n struct ref_formatting_stack {\n@@ -401,20 +420,14 @@ static int is_atom(const char *atom, const char *s, int slen)\n static void mark_atom_in_object_info(const char *atom, int len,\n \t\t\t\t    struct expand_data *data)\n {\n-\tif (is_atom(\"objectname\", atom, len))\n-\t\t; /* do nothing */\n-\telse if (is_atom(\"objecttype\", atom, len))\n+\tif (is_atom(\"objecttype\", atom, len))\n \t\tdata->info.typep = &data->type;\n \telse if (is_atom(\"objectsize\", atom, len))\n \t\tdata->info.sizep = &data->size;\n-\telse if (is_atom(\"objectsize:disk\", atom, len))\n-\t\tdata->info.disk_sizep = &data->disk_size;\n \telse if (is_atom(\"rest\", atom, len))\n \t\tdata->split_on_whitespace = 1;\n \telse if (is_atom(\"deltabase\", atom, len))\n \t\tdata->info.delta_base_sha1 = data->delta_base_oid.hash;\n-\telse\n-\t\tdie(\"unknown format element: %.*s\", len, atom);\n }\n \n /*\n@@ -483,6 +496,8 @@ static int parse_ref_filter_atom(const struct ref_format *format,\n \t\tneed_tagged = 1;\n \tif (!strcmp(valid_atom[i].name, \"symref\"))\n \t\tneed_symref = 1;\n+\tif (cat_file_info)\n+\t\tmark_atom_in_object_info(atom, atom_len, cat_file_info);\n \treturn at;\n }\n \n@@ -726,6 +741,7 @@ int verify_ref_format(struct ref_format *format)\n {\n \tconst char *cp, *sp;\n \n+\tcat_file_info = format->cat_file_data;\n \tformat->need_color_reset_at_eol = 0;\n \tfor (cp = format->format; *cp && (sp = find_next(cp)); ) {\n \t\tconst char *color, *ep = strchr(sp, ')');\n@@ -736,8 +752,8 @@ int verify_ref_format(struct ref_format *format)\n \t\t/* sp points at \"%(\" and ep points at the closing \")\" */\n \n \t\tif (format->cat_file_data)\n-\t\t\tmark_atom_in_object_info(sp + 2, ep - sp - 2,\n-\t\t\t\t\t\tformat->cat_file_data);\n+\t\t\tat = parse_ref_filter_atom(format, valid_cat_file_atom,\n+\t\t\t\t\t\t   ARRAY_SIZE(valid_cat_file_atom), sp + 2, ep);\n \t\telse {\n \t\t\tat = parse_ref_filter_atom(format, valid_atom,\n \t\t\t\t\t\t   ARRAY_SIZE(valid_atom), sp + 2, ep);\n\n--\nhttps://github.com/git/git/pull/452\n"},{"id":"338188","messageId":"0102016165b8b426-befe124b-fbe7-4b83-b7e0-c340b4f6dd57-000000@eu-west-1.amazonses.com","threadId":"47756","inReplyTo":"0102016165b8b3c4-54efe4c4-6d19-435d-b5b9-6c727771353b-000000@eu-west-1.amazonses.com","subject":"[PATCH RFC v2 05/25] cat-file: move struct expand_data into ref-filter","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-02-05T11:27:39Z","receivedAt":"2018-02-05T11:27:48Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Need that for further reusing of formatting logic in cat-file.\nHave plans to get rid of using expand_data in cat-file at all,\nand use it only in ref-filter for collecting, formatting and printing\nneeded data.\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored by: Jeff King <peff@peff.net>\n---\n builtin/cat-file.c | 36 ------------------------------------\n ref-filter.h       | 36 ++++++++++++++++++++++++++++++++++++\n 2 files changed, 36 insertions(+), 36 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 98fc5ec069a49..37d6096d201b5 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -176,42 +176,6 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,\n \treturn 0;\n }\n \n-struct expand_data {\n-\tstruct object_id oid;\n-\tenum object_type type;\n-\tunsigned long size;\n-\toff_t disk_size;\n-\tconst char *rest;\n-\tstruct object_id delta_base_oid;\n-\n-\t/*\n-\t * If mark_query is true, we do not expand anything, but rather\n-\t * just mark the object_info with items we wish to query.\n-\t */\n-\tint mark_query;\n-\n-\t/*\n-\t * Whether to split the input on whitespace before feeding it to\n-\t * get_sha1; this is decided during the mark_query phase based on\n-\t * whether we have a %(rest) token in our format.\n-\t */\n-\tint split_on_whitespace;\n-\n-\t/*\n-\t * After a mark_query run, this object_info is set up to be\n-\t * passed to sha1_object_info_extended. It will point to the data\n-\t * elements above, so you can retrieve the response from there.\n-\t */\n-\tstruct object_info info;\n-\n-\t/*\n-\t * This flag will be true if the requested batch format and options\n-\t * don't require us to call sha1_object_info, which can then be\n-\t * optimized out.\n-\t */\n-\tunsigned skip_object_info : 1;\n-};\n-\n static int is_atom(const char *atom, const char *s, int slen)\n {\n \tint alen = strlen(atom);\ndiff --git a/ref-filter.h b/ref-filter.h\nindex b75c8ac45248e..17f2ac24d2739 100644\n--- a/ref-filter.h\n+++ b/ref-filter.h\n@@ -72,6 +72,42 @@ struct ref_filter {\n \t\tverbose;\n };\n \n+struct expand_data {\n+\tstruct object_id oid;\n+\tenum object_type type;\n+\tunsigned long size;\n+\toff_t disk_size;\n+\tconst char *rest;\n+\tstruct object_id delta_base_oid;\n+\n+\t/*\n+\t * If mark_query is true, we do not expand anything, but rather\n+\t * just mark the object_info with items we wish to query.\n+\t */\n+\tint mark_query;\n+\n+\t/*\n+\t * Whether to split the input on whitespace before feeding it to\n+\t * get_sha1; this is decided during the mark_query phase based on\n+\t * whether we have a %(rest) token in our format.\n+\t */\n+\tint split_on_whitespace;\n+\n+\t/*\n+\t * After a mark_query run, this object_info is set up to be\n+\t * passed to sha1_object_info_extended. It will point to the data\n+\t * elements above, so you can retrieve the response from there.\n+\t */\n+\tstruct object_info info;\n+\n+\t/*\n+\t * This flag will be true if the requested batch format and options\n+\t * don't require us to call sha1_object_info, which can then be\n+\t * optimized out.\n+\t */\n+\tunsigned skip_object_info : 1;\n+};\n+\n struct ref_format {\n \t/*\n \t * Set these to define the format; make sure you call\n\n--\nhttps://github.com/git/git/pull/452\n"},{"id":"338189","messageId":"0102016165b8b4bd-0dc70183-2c3d-4c12-8fb0-7a9685b278b8-000000@eu-west-1.amazonses.com","threadId":"47756","inReplyTo":"0102016165b8b3c4-54efe4c4-6d19-435d-b5b9-6c727771353b-000000@eu-west-1.amazonses.com","subject":"[PATCH RFC v2 22/25] ref-filter: work with objectsize:disk","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-02-05T11:27:39Z","receivedAt":"2018-02-05T11:27:50Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Make a temporary solution for commands that could use\nobjectsize:disk atom.\nIt's better to fill it with value or give an error if there is no value\nfor this atom, but as a first solution we do dothing.\nIt means that if objectsize:disk is used, we put an empty string there.\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored by: Jeff King <peff@peff.net>\n---\n ref-filter.c | 6 ++++--\n 1 file changed, 4 insertions(+), 2 deletions(-)\n\ndiff --git a/ref-filter.c b/ref-filter.c\nindex aa15dd0b4723e..b21358aea476b 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -826,8 +826,10 @@ static void grab_common_values(struct atom_value *val, int deref, struct object\n \t\t\tv->value = sz;\n \t\t\tv->s = xstrfmt(\"%lu\", sz);\n \t\t} else if (!strcmp(name, \"objectsize:disk\")) {\n-\t\t\tv->value = cat_file_info.disk_size;\n-\t\t\tv->s = xstrfmt(\"%\"PRIuMAX, (uintmax_t)v->value);\n+\t\t\tif (is_cat) {\n+\t\t\t\tv->value = cat_file_info.disk_size;\n+\t\t\t\tv->s = xstrfmt(\"%\"PRIuMAX, (uintmax_t)v->value);\n+\t\t\t}\n \t\t} else if (deref)\n \t\t\tgrab_objectname(name, obj->oid.hash, v, &used_atom[i]);\n \t}\n\n--\nhttps://github.com/git/git/pull/452\n"},{"id":"338190","messageId":"0102016165b8b446-49346772-1b0c-42d9-b550-5331604374e3-000000@eu-west-1.amazonses.com","threadId":"47756","inReplyTo":"0102016165b8b3c4-54efe4c4-6d19-435d-b5b9-6c727771353b-000000@eu-west-1.amazonses.com","subject":"[PATCH RFC v2 13/25] ref-filter: get rid of mark_atom_in_object_info()","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-02-05T11:27:39Z","receivedAt":"2018-02-05T11:27:53Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Remove mark_atom_in_object_info() and create same logic\nin terms of ref-filter style.\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored by: Jeff King <peff@peff.net>\n---\n ref-filter.c | 45 +++++++++++++++++++++------------------------\n 1 file changed, 21 insertions(+), 24 deletions(-)\n\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 3f92a27d98b6c..34a54db168265 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -255,13 +255,29 @@ static void objectname_atom_parser(const struct ref_format *format, struct used_\n static void objectsize_atom_parser(const struct ref_format *format, struct used_atom *atom, const char *arg)\n {\n \tif (!arg)\n-\t\t; /* default to normal object size */\n+\t\tcat_file_info->info.sizep = &cat_file_info->size;\n \telse if (!strcmp(arg, \"disk\"))\n \t\tcat_file_info->info.disk_sizep = &cat_file_info->disk_size;\n \telse\n \t\tdie(_(\"urecognized %%(objectsize) argument: %s\"), arg);\n }\n \n+static void objecttype_atom_parser(const struct ref_format *format, struct used_atom *atom, const char *arg)\n+{\n+\tif (!arg)\n+\t\tcat_file_info->info.typep = &cat_file_info->type;\n+\telse\n+\t\tdie(_(\"urecognized %%(objecttype) argument: %s\"), arg);\n+}\n+\n+static void deltabase_atom_parser(const struct ref_format *format, struct used_atom *atom, const char *arg)\n+{\n+\tif (!arg)\n+\t\tcat_file_info->info.delta_base_sha1 = cat_file_info->delta_base_oid.hash;\n+\telse\n+\t\tdie(_(\"urecognized %%(deltabase) argument: %s\"), arg);\n+}\n+\n static void refname_atom_parser(const struct ref_format *format, struct used_atom *atom, const char *arg)\n {\n \trefname_atom_parser_internal(&atom->u.refname, arg, atom->name);\n@@ -384,10 +400,10 @@ static struct valid_atom {\n \n static struct valid_atom valid_cat_file_atom[] = {\n \t{ \"objectname\" },\n-\t{ \"objecttype\" },\n+\t{ \"objecttype\", FIELD_STR, objecttype_atom_parser },\n \t{ \"objectsize\", FIELD_ULONG, objectsize_atom_parser },\n \t{ \"rest\" },\n-\t{ \"deltabase\" },\n+\t{ \"deltabase\", FIELD_STR, deltabase_atom_parser },\n };\n \n #define REF_FORMATTING_STATE_INIT  { 0, NULL }\n@@ -411,25 +427,6 @@ struct atom_value {\n \tstruct used_atom *atom;\n };\n \n-static int is_atom(const char *atom, const char *s, int slen)\n-{\n-\tint alen = strlen(atom);\n-\treturn alen == slen && !memcmp(atom, s, alen);\n-}\n-\n-static void mark_atom_in_object_info(const char *atom, int len,\n-\t\t\t\t    struct expand_data *data)\n-{\n-\tif (is_atom(\"objecttype\", atom, len))\n-\t\tdata->info.typep = &data->type;\n-\telse if (is_atom(\"objectsize\", atom, len))\n-\t\tdata->info.sizep = &data->size;\n-\telse if (is_atom(\"rest\", atom, len))\n-\t\tdata->split_on_whitespace = 1;\n-\telse if (is_atom(\"deltabase\", atom, len))\n-\t\tdata->info.delta_base_sha1 = data->delta_base_oid.hash;\n-}\n-\n /*\n  * Used to parse format string and sort specifiers\n  */\n@@ -496,8 +493,8 @@ static int parse_ref_filter_atom(const struct ref_format *format,\n \t\tneed_tagged = 1;\n \tif (!strcmp(valid_atom[i].name, \"symref\"))\n \t\tneed_symref = 1;\n-\tif (cat_file_info)\n-\t\tmark_atom_in_object_info(atom, atom_len, cat_file_info);\n+\tif (cat_file_info && !strcmp(valid_atom[i].name, \"rest\"))\n+\t\tcat_file_info->split_on_whitespace = 1;\n \treturn at;\n }\n \n\n--\nhttps://github.com/git/git/pull/452\n"},{"id":"338191","messageId":"0102016165b8b42e-fdf2a584-b8e3-4279-bc69-eb9755a541e2-000000@eu-west-1.amazonses.com","threadId":"47756","inReplyTo":"0102016165b8b3c4-54efe4c4-6d19-435d-b5b9-6c727771353b-000000@eu-west-1.amazonses.com","subject":"[PATCH RFC v2 06/25] cat-file: split expand_atom() into 2 functions","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-02-05T11:27:39Z","receivedAt":"2018-02-05T11:27:56Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Split expand_atom() into 2 different functions,\nmark_atom_in_object_info() prepares variable for further filling,\n(new) expand_atom() creates resulting string.\nNeed that for further reusing of formatting logic from ref-filter.\nBoth functions will be step-by-step removed by the end of this patch.\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored by: Jeff King <peff@peff.net>\n---\n builtin/cat-file.c | 73 ++++++++++++++++++++++++++++--------------------------\n 1 file changed, 38 insertions(+), 35 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 37d6096d201b5..edb04a96d9bd3 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -182,47 +182,47 @@ static int is_atom(const char *atom, const char *s, int slen)\n \treturn alen == slen && !memcmp(atom, s, alen);\n }\n \n-static void expand_atom(struct strbuf *sb, const char *atom, int len,\n-\t\t\tvoid *vdata)\n+static void mark_atom_in_object_info(const char *atom, int len,\n+\t\t\t\t     struct expand_data *data)\n {\n-\tstruct expand_data *data = vdata;\n+\tif (is_atom(\"objectname\", atom, len))\n+\t\t; /* do nothing */\n+\telse if (is_atom(\"objecttype\", atom, len))\n+\t\tdata->info.typep = &data->type;\n+\telse if (is_atom(\"objectsize\", atom, len))\n+\t\tdata->info.sizep = &data->size;\n+\telse if (is_atom(\"objectsize:disk\", atom, len))\n+\t\tdata->info.disk_sizep = &data->disk_size;\n+\telse if (is_atom(\"rest\", atom, len))\n+\t\tdata->split_on_whitespace = 1;\n+\telse if (is_atom(\"deltabase\", atom, len))\n+\t\tdata->info.delta_base_sha1 = data->delta_base_oid.hash;\n+\telse\n+\t\tdie(\"unknown format element: %.*s\", len, atom);\n+}\n \n-\tif (is_atom(\"objectname\", atom, len)) {\n-\t\tif (!data->mark_query)\n-\t\t\tstrbuf_addstr(sb, oid_to_hex(&data->oid));\n-\t} else if (is_atom(\"objecttype\", atom, len)) {\n-\t\tif (data->mark_query)\n-\t\t\tdata->info.typep = &data->type;\n-\t\telse\n-\t\t\tstrbuf_addstr(sb, typename(data->type));\n-\t} else if (is_atom(\"objectsize\", atom, len)) {\n-\t\tif (data->mark_query)\n-\t\t\tdata->info.sizep = &data->size;\n-\t\telse\n-\t\t\tstrbuf_addf(sb, \"%lu\", data->size);\n-\t} else if (is_atom(\"objectsize:disk\", atom, len)) {\n-\t\tif (data->mark_query)\n-\t\t\tdata->info.disk_sizep = &data->disk_size;\n-\t\telse\n-\t\t\tstrbuf_addf(sb, \"%\"PRIuMAX, (uintmax_t)data->disk_size);\n-\t} else if (is_atom(\"rest\", atom, len)) {\n-\t\tif (data->mark_query)\n-\t\t\tdata->split_on_whitespace = 1;\n-\t\telse if (data->rest)\n+static void expand_atom(struct strbuf *sb, const char *atom, int len,\n+\t\t\t struct expand_data *data)\n+{\n+\tif (is_atom(\"objectname\", atom, len))\n+\t\tstrbuf_addstr(sb, oid_to_hex(&data->oid));\n+\telse if (is_atom(\"objecttype\", atom, len))\n+\t\tstrbuf_addstr(sb, typename(data->type));\n+\telse if (is_atom(\"objectsize\", atom, len))\n+\t\tstrbuf_addf(sb, \"%lu\", data->size);\n+\telse if (is_atom(\"objectsize:disk\", atom, len))\n+\t\tstrbuf_addf(sb, \"%\"PRIuMAX, (uintmax_t)data->disk_size);\n+\telse if (is_atom(\"rest\", atom, len)) {\n+\t\tif (data->rest)\n \t\t\tstrbuf_addstr(sb, data->rest);\n-\t} else if (is_atom(\"deltabase\", atom, len)) {\n-\t\tif (data->mark_query)\n-\t\t\tdata->info.delta_base_sha1 = data->delta_base_oid.hash;\n-\t\telse\n-\t\t\tstrbuf_addstr(sb,\n-\t\t\t\t      oid_to_hex(&data->delta_base_oid));\n-\t} else\n-\t\tdie(\"unknown format element: %.*s\", len, atom);\n+\t} else if (is_atom(\"deltabase\", atom, len))\n+\t\tstrbuf_addstr(sb, oid_to_hex(&data->delta_base_oid));\n }\n \n-static size_t expand_format(struct strbuf *sb, const char *start, void *data)\n+static size_t expand_format(struct strbuf *sb, const char *start, void *vdata)\n {\n \tconst char *end;\n+\tstruct expand_data *data = vdata;\n \n \tif (*start != '(')\n \t\treturn 0;\n@@ -230,7 +230,10 @@ static size_t expand_format(struct strbuf *sb, const char *start, void *data)\n \tif (!end)\n \t\tdie(\"format element '%s' does not end in ')'\", start);\n \n-\texpand_atom(sb, start + 1, end - start - 1, data);\n+\tif (data->mark_query)\n+\t\tmark_atom_in_object_info(start + 1, end - start - 1, data);\n+\telse\n+\t\texpand_atom(sb, start + 1, end - start - 1, data);\n \n \treturn end - start + 1;\n }\n\n--\nhttps://github.com/git/git/pull/452\n"},{"id":"338192","messageId":"0102016165b8b45f-26ed9dd1-3ab5-421e-b76d-cf9cf2c377b0-000000@eu-west-1.amazonses.com","threadId":"47756","inReplyTo":"0102016165b8b3c4-54efe4c4-6d19-435d-b5b9-6c727771353b-000000@eu-west-1.amazonses.com","subject":"[PATCH RFC v2 16/25] cat-file: move skip_object_info into ref-filter","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-02-05T11:27:39Z","receivedAt":"2018-02-05T11:27:59Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Move logic related to skip_object_info into ref-filter,\nso that cat-file does not use that field at all.\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored by: Jeff King <peff@peff.net>\n---\n builtin/cat-file.c | 7 +------\n ref-filter.c       | 5 +++++\n ref-filter.h       | 1 +\n 3 files changed, 7 insertions(+), 6 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex a55138f1fd1d1..37adf626d0e55 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -395,14 +395,9 @@ static int batch_objects(struct batch_options *opt)\n \tmemset(&data, 0, sizeof(data));\n \topt->format.cat_file_data = &data;\n \topt->format.is_cat = 1;\n+\topt->format.all_objects = opt->all_objects;\n \tverify_ref_format(&opt->format);\n \n-\tif (opt->all_objects) {\n-\t\tstruct object_info empty = OBJECT_INFO_INIT;\n-\t\tif (!memcmp(&data.info, &empty, sizeof(empty)))\n-\t\t\tdata.skip_object_info = 1;\n-\t}\n-\n \t/*\n \t * If we are printing out the object, then always fill in the type,\n \t * since we will want to decide whether or not to stream.\ndiff --git a/ref-filter.c b/ref-filter.c\nindex bbcd507d179a9..7dcd36cd2cddc 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -777,6 +777,11 @@ int verify_ref_format(struct ref_format *format)\n \t}\n \tif (format->need_color_reset_at_eol && !want_color(format->use_color))\n \t\tformat->need_color_reset_at_eol = 0;\n+\tif (is_cat && format->all_objects) {\n+\t\tstruct object_info empty = OBJECT_INFO_INIT;\n+\t\tif (!memcmp(&cat_file_info->info, &empty, sizeof(empty)))\n+\t\t\tcat_file_info->skip_object_info = 1;\n+\t}\n \treturn 0;\n }\n \ndiff --git a/ref-filter.h b/ref-filter.h\nindex f590e5d694df4..e882eb5126118 100644\n--- a/ref-filter.h\n+++ b/ref-filter.h\n@@ -119,6 +119,7 @@ struct ref_format {\n \t */\n \tstruct expand_data *cat_file_data;\n \tint is_cat;\n+\tint all_objects;\n };\n \n #define REF_FORMAT_INIT { NULL, 0, -1 }\n\n--\nhttps://github.com/git/git/pull/452\n"},{"id":"338193","messageId":"0102016165b8b43b-65f0cf49-6159-40d8-9bee-de4205e5532f-000000@eu-west-1.amazonses.com","threadId":"47756","inReplyTo":"0102016165b8b3c4-54efe4c4-6d19-435d-b5b9-6c727771353b-000000@eu-west-1.amazonses.com","subject":"[PATCH RFC v2 11/25] ref-filter: rename field in ref_array_item stuct","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-02-05T11:27:39Z","receivedAt":"2018-02-05T11:28:01Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Rename objectname field to oid in struct ref_array_item.\nNext commit will add objectname field that will contain\nstring representation of object id.\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored by: Jeff King <peff@peff.net>\n---\n builtin/cat-file.c |  4 ++--\n ref-filter.c       | 10 +++++-----\n ref-filter.h       |  2 +-\n 3 files changed, 8 insertions(+), 8 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 61b7acc79155d..367b1bd5802dc 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -186,7 +186,7 @@ static void expand_atom(struct strbuf *sb, const char *atom, int len,\n \t\t\t struct ref_array_item *item)\n {\n \tif (is_atom(\"objectname\", atom, len))\n-\t\tstrbuf_addstr(sb, oid_to_hex(&item->objectname));\n+\t\tstrbuf_addstr(sb, oid_to_hex(&item->oid));\n \telse if (is_atom(\"objecttype\", atom, len))\n \t\tstrbuf_addstr(sb, typename(item->type));\n \telse if (is_atom(\"objectsize\", atom, len))\n@@ -294,7 +294,7 @@ static void batch_object_write(const char *obj_name, struct batch_options *opt,\n \t\treturn;\n \t}\n \n-\titem.objectname = data->oid;\n+\titem.oid = data->oid;\n \titem.type = data->type;\n \titem.size = data->size;\n \titem.disk_size = data->disk_size;\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 4acd391b5dfac..d09ec1bde6d54 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -1489,7 +1489,7 @@ int populate_value(struct ref_array_item *ref)\n \t\t\t\tv->s = xstrdup(buf + 1);\n \t\t\t}\n \t\t\tcontinue;\n-\t\t} else if (!deref && grab_objectname(name, ref->objectname.hash, v, atom)) {\n+\t\t} else if (!deref && grab_objectname(name, ref->oid.hash, v, atom)) {\n \t\t\tcontinue;\n \t\t} else if (!strcmp(name, \"HEAD\")) {\n \t\t\tif (atom->u.head && !strcmp(ref->refname, atom->u.head))\n@@ -1534,13 +1534,13 @@ int populate_value(struct ref_array_item *ref)\n \tif (used_atom_cnt <= i)\n \t\treturn 0;\n \n-\tbuf = get_obj(&ref->objectname, &obj, &size, &eaten);\n+\tbuf = get_obj(&ref->oid, &obj, &size, &eaten);\n \tif (!buf)\n \t\tdie(_(\"missing object %s for %s\"),\n-\t\t    oid_to_hex(&ref->objectname), ref->refname);\n+\t\t    oid_to_hex(&ref->oid), ref->refname);\n \tif (!obj)\n \t\tdie(_(\"parse_object_buffer failed on %s for %s\"),\n-\t\t    oid_to_hex(&ref->objectname), ref->refname);\n+\t\t    oid_to_hex(&ref->oid), ref->refname);\n \n \tgrab_values(ref->value, 0, obj, buf, size);\n \tif (!eaten)\n@@ -1890,7 +1890,7 @@ static struct ref_array_item *new_ref_array_item(const char *refname,\n {\n \tstruct ref_array_item *ref;\n \tFLEX_ALLOC_STR(ref, refname, refname);\n-\thashcpy(ref->objectname.hash, objectname);\n+\thashcpy(ref->oid.hash, objectname);\n \tref->flag = flag;\n \n \treturn ref;\ndiff --git a/ref-filter.h b/ref-filter.h\nindex e16ea2a990119..87b026b8b76d0 100644\n--- a/ref-filter.h\n+++ b/ref-filter.h\n@@ -34,7 +34,7 @@ struct ref_sorting {\n };\n \n struct ref_array_item {\n-\tstruct object_id objectname;\n+\tstruct object_id oid;\n \tint flag;\n \tunsigned int kind;\n \tconst char *symref;\n\n--\nhttps://github.com/git/git/pull/452\n"},{"id":"338194","messageId":"0102016165b8b3c4-54efe4c4-6d19-435d-b5b9-6c727771353b-000000@eu-west-1.amazonses.com","threadId":"47756","inReplyTo":"0102016133ff3a86-44d354ec-13c6-4c38-bc75-1ba4422db5a7-000000@eu-west-1.amazonses.com","subject":"[PATCH RFC v2 01/25] ref-filter: get rid of goto","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-02-05T11:27:38Z","receivedAt":"2018-02-05T11:28:05Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Get rid of goto command in ref-filter for better readability.\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored by: Jeff King <peff@peff.net>\n---\n ref-filter.c | 9 +++++----\n 1 file changed, 5 insertions(+), 4 deletions(-)\n\ndiff --git a/ref-filter.c b/ref-filter.c\nindex f9e25aea7a97e..d04295e33448e 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -1477,12 +1477,13 @@ static void populate_value(struct ref_array_item *ref)\n \n \tfor (i = 0; i < used_atom_cnt; i++) {\n \t\tstruct atom_value *v = &ref->value[i];\n-\t\tif (v->s == NULL)\n-\t\t\tgoto need_obj;\n+\t\tif (v->s == NULL) {\n+\t\t\tbreak;\n+\t\t}\n \t}\n-\treturn;\n+\tif (used_atom_cnt <= i)\n+\t\treturn;\n \n- need_obj:\n \tbuf = get_obj(&ref->objectname, &obj, &size, &eaten);\n \tif (!buf)\n \t\tdie(_(\"missing object %s for %s\"),\n\n--\nhttps://github.com/git/git/pull/452\n"},{"id":"338195","messageId":"0102016165b8b42b-18bf5fff-cc40-471f-b633-26eeef71c989-000000@eu-west-1.amazonses.com","threadId":"47756","inReplyTo":"0102016165b8b3c4-54efe4c4-6d19-435d-b5b9-6c727771353b-000000@eu-west-1.amazonses.com","subject":"[PATCH RFC v2 04/25] ref-filter: make valid_atom as function parameter","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-02-05T11:27:39Z","receivedAt":"2018-02-05T11:28:07Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Make valid_atom as a function parameter,\nthere could be another variable further.\nNeed that for further reusing of formatting logic in cat-file.c.\n\nWe do not need to allow users to pass their own valid_atom variable in\nglobal functions like verify_ref_format() because in the end we want to\nhave same set of valid atoms for all commands. But, as a first step\nof migrating, I create further another version of valid_atom\nfor cat-file.\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored by: Jeff King <peff@peff.net>\n---\n ref-filter.c | 17 +++++++++++------\n 1 file changed, 11 insertions(+), 6 deletions(-)\n\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 9ed5e66066a7a..5e7ed0f338490 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -325,7 +325,7 @@ static void head_atom_parser(const struct ref_format *format, struct used_atom *\n \tatom->u.head = resolve_refdup(\"HEAD\", RESOLVE_REF_READING, NULL, NULL);\n }\n \n-static struct {\n+static struct valid_atom {\n \tconst char *name;\n \tcmp_type cmp_type;\n \tvoid (*parser)(const struct ref_format *format, struct used_atom *atom, const char *arg);\n@@ -396,6 +396,7 @@ struct atom_value {\n  * Used to parse format string and sort specifiers\n  */\n static int parse_ref_filter_atom(const struct ref_format *format,\n+\t\t\t\t const struct valid_atom *valid_atom, int n_atoms,\n \t\t\t\t const char *atom, const char *ep)\n {\n \tconst char *sp;\n@@ -425,13 +426,13 @@ static int parse_ref_filter_atom(const struct ref_format *format,\n \tatom_len = (arg ? arg : ep) - sp;\n \n \t/* Is the atom a valid one? */\n-\tfor (i = 0; i < ARRAY_SIZE(valid_atom); i++) {\n+\tfor (i = 0; i < n_atoms; i++) {\n \t\tint len = strlen(valid_atom[i].name);\n \t\tif (len == atom_len && !memcmp(valid_atom[i].name, sp, len))\n \t\t\tbreak;\n \t}\n \n-\tif (ARRAY_SIZE(valid_atom) <= i)\n+\tif (n_atoms <= i)\n \t\tdie(_(\"unknown field name: %.*s\"), (int)(ep-atom), atom);\n \n \t/* Add it in, including the deref prefix */\n@@ -708,7 +709,8 @@ int verify_ref_format(struct ref_format *format)\n \t\tif (!ep)\n \t\t\treturn error(_(\"malformed format string %s\"), sp);\n \t\t/* sp points at \"%(\" and ep points at the closing \")\" */\n-\t\tat = parse_ref_filter_atom(format, sp + 2, ep);\n+\t\tat = parse_ref_filter_atom(format, valid_atom,\n+\t\t\t\t\t   ARRAY_SIZE(valid_atom), sp + 2, ep);\n \t\tcp = ep + 1;\n \n \t\tif (skip_prefix(used_atom[at].name, \"color:\", &color))\n@@ -2145,7 +2147,9 @@ int format_ref_array_item(struct ref_array_item *info,\n \t\tif (cp < sp)\n \t\t\tappend_literal(cp, sp, &state);\n \t\tif (get_ref_atom_value(info,\n-\t\t\t\t       parse_ref_filter_atom(format, sp + 2, ep),\n+\t\t\t\t       parse_ref_filter_atom(format, valid_atom,\n+\t\t\t\t\t\t\t     ARRAY_SIZE(valid_atom),\n+\t\t\t\t\t\t\t     sp + 2, ep),\n \t\t\t\t       &atomv))\n \t\t\treturn -1;\n \t\tatomv->handler(atomv, &state);\n@@ -2198,7 +2202,8 @@ static int parse_sorting_atom(const char *atom)\n \t */\n \tstruct ref_format dummy = REF_FORMAT_INIT;\n \tconst char *end = atom + strlen(atom);\n-\treturn parse_ref_filter_atom(&dummy, atom, end);\n+\treturn parse_ref_filter_atom(&dummy, valid_atom,\n+\t\t\t\t     ARRAY_SIZE(valid_atom), atom, end);\n }\n \n /*  If no sorting option is given, use refname to sort as default */\n\n--\nhttps://github.com/git/git/pull/452\n"},{"id":"338196","messageId":"0102016165b8b444-99fcbf50-ab35-4781-821a-a0dc90ed813b-000000@eu-west-1.amazonses.com","threadId":"47756","inReplyTo":"0102016165b8b3c4-54efe4c4-6d19-435d-b5b9-6c727771353b-000000@eu-west-1.amazonses.com","subject":"[PATCH RFC v2 03/25] cat-file: reuse struct ref_format","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-02-05T11:27:39Z","receivedAt":"2018-02-05T11:28:09Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Start using ref_format struct instead of simple char*.\nNeed that for further reusing of formatting logic from ref-filter.\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored by: Jeff King <peff@peff.net>\n---\n builtin/cat-file.c | 15 ++++++++-------\n 1 file changed, 8 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex f5fa4fd75af26..98fc5ec069a49 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -13,15 +13,16 @@\n #include \"tree-walk.h\"\n #include \"sha1-array.h\"\n #include \"packfile.h\"\n+#include \"ref-filter.h\"\n \n struct batch_options {\n+\tstruct ref_format format;\n \tint enabled;\n \tint follow_symlinks;\n \tint print_contents;\n \tint buffer_output;\n \tint all_objects;\n \tint cmdmode; /* may be 'w' or 'c' for --filters or --textconv */\n-\tconst char *format;\n };\n \n static const char *force_path;\n@@ -348,7 +349,7 @@ static void batch_object_write(const char *obj_name, struct batch_options *opt,\n \t\treturn;\n \t}\n \n-\tstrbuf_expand(&buf, opt->format, expand_format, data);\n+\tstrbuf_expand(&buf, opt->format.format, expand_format, data);\n \tstrbuf_addch(&buf, '\\n');\n \tbatch_write(opt, buf.buf, buf.len);\n \tstrbuf_release(&buf);\n@@ -441,8 +442,8 @@ static int batch_objects(struct batch_options *opt)\n \tint save_warning;\n \tint retval = 0;\n \n-\tif (!opt->format)\n-\t\topt->format = \"%(objectname) %(objecttype) %(objectsize)\";\n+\tif (!opt->format.format)\n+\t\topt->format.format = \"%(objectname) %(objecttype) %(objectsize)\";\n \n \t/*\n \t * Expand once with our special mark_query flag, which will prime the\n@@ -451,7 +452,7 @@ static int batch_objects(struct batch_options *opt)\n \t */\n \tmemset(&data, 0, sizeof(data));\n \tdata.mark_query = 1;\n-\tstrbuf_expand(&buf, opt->format, expand_format, &data);\n+\tstrbuf_expand(&buf, opt->format.format, expand_format, &data);\n \tdata.mark_query = 0;\n \tif (opt->cmdmode)\n \t\tdata.split_on_whitespace = 1;\n@@ -543,7 +544,7 @@ static int batch_option_callback(const struct option *opt,\n \n \tbo->enabled = 1;\n \tbo->print_contents = !strcmp(opt->long_name, \"batch\");\n-\tbo->format = arg;\n+\tbo->format.format = arg;\n \n \treturn 0;\n }\n@@ -552,7 +553,7 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)\n {\n \tint opt = 0;\n \tconst char *exp_type = NULL, *obj_name = NULL;\n-\tstruct batch_options batch = {0};\n+\tstruct batch_options batch = { REF_FORMAT_INIT };\n \tint unknown_type = 0;\n \n \tconst struct option options[] = {\n\n--\nhttps://github.com/git/git/pull/452\n"},{"id":"338197","messageId":"0102016165b8b47f-c7aaef74-cbf3-45eb-b1d3-a8f94f814a84-000000@eu-west-1.amazonses.com","threadId":"47756","inReplyTo":"0102016165b8b3c4-54efe4c4-6d19-435d-b5b9-6c727771353b-000000@eu-west-1.amazonses.com","subject":"[PATCH RFC v2 25/25] cat-file: update of docs","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-02-05T11:27:39Z","receivedAt":"2018-02-05T11:28:12Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Update the docs for cat-file command. Some new formatting atoms added\nbecause of reusing ref-filter code.\nWe do not support cat-file atoms in general formatting logic\n(there is just the support for cat-file), that is why some of the atoms\nare still explained in cat-file docs.\nWe need to move these explanations when atoms will be supported\nby other commands.\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored by: Jeff King <peff@peff.net>\n---\n Documentation/git-cat-file.txt | 13 ++-----------\n 1 file changed, 2 insertions(+), 11 deletions(-)\n\ndiff --git a/Documentation/git-cat-file.txt b/Documentation/git-cat-file.txt\nindex f90f09b03fae5..90639ac21d0e8 100644\n--- a/Documentation/git-cat-file.txt\n+++ b/Documentation/git-cat-file.txt\n@@ -187,17 +187,8 @@ linkgit:git-rev-parse[1].\n You can specify the information shown for each object by using a custom\n `<format>`. The `<format>` is copied literally to stdout for each\n object, with placeholders of the form `%(atom)` expanded, followed by a\n-newline. The available atoms are:\n-\n-`objectname`::\n-\tThe 40-hex object name of the object.\n-\n-`objecttype`::\n-\tThe type of the object (the same as `cat-file -t` reports).\n-\n-`objectsize`::\n-\tThe size, in bytes, of the object (the same as `cat-file -s`\n-\treports).\n+newline. The available atoms are the same as that of\n+linkgit:git-for-each-ref[1], but there are some additional ones:\n \n `objectsize:disk`::\n \tThe size, in bytes, that the object takes up on disk. See the\n\n--\nhttps://github.com/git/git/pull/452\n"},{"id":"338198","messageId":"0102016165b8b479-a61894ea-257d-42a7-af7d-607124715633-000000@eu-west-1.amazonses.com","threadId":"47756","inReplyTo":"0102016165b8b3c4-54efe4c4-6d19-435d-b5b9-6c727771353b-000000@eu-west-1.amazonses.com","subject":"[PATCH RFC v2 24/25] cat-file: tests for new atoms added","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-02-05T11:27:39Z","receivedAt":"2018-02-05T11:28:15Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Add some tests for new formatting atoms from ref-filter.\nSome of new atoms are supported automatically,\nsome of them are expanded into empty string\n(because they are useless for some types of objects),\nsome of them could be supported later in other patches.\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored by: Jeff King <peff@peff.net>\n---\n t/t1006-cat-file.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 48 insertions(+)\n\ndiff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh\nindex b19f332694620..e72fcaf0e02c5 100755\n--- a/t/t1006-cat-file.sh\n+++ b/t/t1006-cat-file.sh\n@@ -20,6 +20,19 @@ maybe_remove_timestamp () {\n     fi\n }\n \n+test_atom () {\n+    name=$1\n+    sha1=$2\n+    atoms=$3\n+    expected=$4\n+\n+    test_expect_success \"$name\" '\n+\techo \"$expected\" >expect &&\n+\techo $sha1 | git cat-file --batch-check=\"$atoms\" >actual &&\n+\ttest_cmp expect actual\n+    '\n+}\n+\n run_tests () {\n     type=$1\n     sha1=$2\n@@ -119,6 +132,13 @@ $content\"\n \tmaybe_remove_timestamp \"$(cat actual.full)\" $no_ts >actual &&\n \ttest_cmp expect actual\n     '\n+\n+    for atom in refname parent body trailers upstream push symref flag\n+    do\n+\ttest_atom \"Check %($atom) gives empty output\" \"$sha1\" \"%($atom)\" \"\"\n+    done\n+\n+    test_atom \"Check %(HEAD) gives only one space as output\" \"$sha1\" '%(HEAD)' ' '\n }\n \n hello_content=\"Hello World\"\n@@ -140,6 +160,12 @@ test_expect_success '--batch-check without %(rest) considers whole line' '\n \ttest_cmp expect actual\n '\n \n+shortname=`echo $hello_sha1 | sed 's/^.\\{0\\}\\(.\\{7\\}\\).*/\\1/'`\n+test_atom 'Check format option %(objectname:short) works' \"$hello_sha1\" '%(objectname:short)' \"$shortname\"\n+\n+test_atom 'Check format option %(align) is not broken' \\\n+    \"$hello_sha1\" \"%(align:8)%(objecttype)%(end)%(objectname)\" \"blob    $hello_sha1\"\n+\n tree_sha1=$(git write-tree)\n tree_size=33\n tree_pretty_content=\"100644 blob $hello_sha1\thello\"\n@@ -157,6 +183,17 @@ $commit_message\"\n \n run_tests 'commit' $commit_sha1 $commit_size \"$commit_content\" \"$commit_content\" 1\n \n+test_atom \"Check format option %(if) is not broken\" \"$commit_sha1\" \\\n+    \"%(if)%(author)%(then)%(objectname)%(end)\" \"$commit_sha1\"\n+test_atom \"Check %(tree) works for commit\" \"$commit_sha1\" \"%(tree)\" \"$tree_sha1\"\n+test_atom \"Check %(numparent) works for commit\" \"$commit_sha1\" \"%(numparent)\" \"0\"\n+test_atom \"Check %(authorname) works for commit\" \"$commit_sha1\" \"%(authorname)\" \"$GIT_AUTHOR_NAME\"\n+test_atom \"Check %(authoremail) works for commit\" \"$commit_sha1\" \"%(authoremail)\" \"<$GIT_AUTHOR_EMAIL>\"\n+test_atom \"Check %(committername) works for commit\" \"$commit_sha1\" \"%(committername)\" \"$GIT_COMMITTER_NAME\"\n+test_atom \"Check %(committeremail) works for commit\" \"$commit_sha1\" \"%(committeremail)\" \"<$GIT_COMMITTER_EMAIL>\"\n+test_atom \"Check %(subject) works for commit\" \"$commit_sha1\" \"%(subject)\" \"$commit_message\"\n+test_atom \"Check %(contents) works for commit\" \"$commit_sha1\" \"%(contents)\" \"$commit_message\"\n+\n tag_header_without_timestamp=\"object $hello_sha1\n type blob\n tag hellotag\n@@ -171,6 +208,17 @@ tag_size=$(strlen \"$tag_content\")\n \n run_tests 'tag' $tag_sha1 $tag_size \"$tag_content\" \"$tag_content\" 1\n \n+test_atom \"Check %(object) works for tag\" \"$tag_sha1\" \"%(object)\" \"$hello_sha1\"\n+test_atom \"Check %(type) works for tag\" \"$tag_sha1\" \"%(type)\" \"blob\"\n+test_atom \"Check %(tag) works for tag\" \"$tag_sha1\" \"%(tag)\" \"hellotag\"\n+test_atom \"Check %(taggername) works for tag\" \"$tag_sha1\" \"%(taggername)\" \"$GIT_COMMITTER_NAME\"\n+test_atom \"Check %(taggeremail) works for tag\" \"$tag_sha1\" \"%(taggeremail)\" \"<$GIT_COMMITTER_EMAIL>\"\n+test_atom \"Check %(subject) works for tag\" \"$tag_sha1\" \"%(subject)\" \"$tag_description\"\n+test_atom \"Check %(contents) works for tag\" \"$tag_sha1\" \"%(contents)\" \"$tag_description\"\n+\n+test_atom \"Check %(color) gives no additional output\" \"$sha1\" \\\n+    \"%(objectname) %(color:green) %(objecttype)\" \"$sha1  $type\"\n+\n test_expect_success \\\n     \"Reach a blob from a tag pointing to it\" \\\n     \"test '$hello_content' = \\\"\\$(git cat-file blob $tag_sha1)\\\"\"\n\n--\nhttps://github.com/git/git/pull/452\n"},{"id":"338199","messageId":"0102016165b8b459-938aff59-da10-4b83-9e42-cd6feb06adb5-000000@eu-west-1.amazonses.com","threadId":"47756","inReplyTo":"0102016165b8b3c4-54efe4c4-6d19-435d-b5b9-6c727771353b-000000@eu-west-1.amazonses.com","subject":"[PATCH RFC v2 15/25] ref_filter: add is_atom_used function","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-02-05T11:27:39Z","receivedAt":"2018-02-05T11:28:17Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Delete all items related to split_on_whitespace from ref-filter\nand add new function for handling the logic.\nNow cat-file could invoke that function to implementing its logic.\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored by: Jeff King <peff@peff.net>\n---\n builtin/cat-file.c |  8 +++-----\n ref-filter.c       | 17 +++++++++++++++--\n ref-filter.h       | 10 +++-------\n 3 files changed, 21 insertions(+), 14 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex e8e788f41b890..a55138f1fd1d1 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -382,8 +382,7 @@ static int batch_objects(struct batch_options *opt)\n {\n \tstruct strbuf buf = STRBUF_INIT;\n \tstruct expand_data data;\n-\tint save_warning;\n-\tint retval = 0;\n+\tint save_warning, is_rest, retval = 0;\n \n \tif (!opt->format.format)\n \t\topt->format.format = \"%(objectname) %(objecttype) %(objectsize)\";\n@@ -397,8 +396,6 @@ static int batch_objects(struct batch_options *opt)\n \topt->format.cat_file_data = &data;\n \topt->format.is_cat = 1;\n \tverify_ref_format(&opt->format);\n-\tif (opt->cmdmode)\n-\t\tdata.split_on_whitespace = 1;\n \n \tif (opt->all_objects) {\n \t\tstruct object_info empty = OBJECT_INFO_INIT;\n@@ -437,9 +434,10 @@ static int batch_objects(struct batch_options *opt)\n \t */\n \tsave_warning = warn_on_object_refname_ambiguity;\n \twarn_on_object_refname_ambiguity = 0;\n+\tis_rest = opt->cmdmode || is_atom_used(&opt->format, \"rest\");\n \n \twhile (strbuf_getline(&buf, stdin) != EOF) {\n-\t\tif (data.split_on_whitespace) {\n+\t\tif (is_rest) {\n \t\t\t/*\n \t\t\t * Split at first whitespace, tying off the beginning\n \t\t\t * of the string and saving the remainder (or NULL) in\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 91290b62450b3..bbcd507d179a9 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -494,8 +494,6 @@ static int parse_ref_filter_atom(const struct ref_format *format,\n \t\tneed_tagged = 1;\n \tif (!strcmp(valid_atom[i].name, \"symref\"))\n \t\tneed_symref = 1;\n-\tif (is_cat && !strcmp(valid_atom[i].name, \"rest\"))\n-\t\tcat_file_info->split_on_whitespace = 1;\n \treturn at;\n }\n \n@@ -731,6 +729,21 @@ static const char *find_next(const char *cp)\n \treturn NULL;\n }\n \n+/* Search for atom in given format. */\n+int is_atom_used(const struct ref_format *format, const char *atom)\n+{\n+\tconst char *cp, *sp;\n+\tfor (cp = format->format; *cp && (sp = find_next(cp)); ) {\n+\t\tconst char *ep = strchr(sp, ')');\n+\t\tint atom_len = ep - sp - 2;\n+\t\tsp += 2;\n+\t\tif (atom_len == strlen(atom) && !memcmp(sp, atom, atom_len))\n+\t\t\treturn 1;\n+\t\tcp = ep + 1;\n+\t}\n+\treturn 0;\n+}\n+\n /*\n  * Make sure the format string is well formed, and parse out\n  * the used atoms.\ndiff --git a/ref-filter.h b/ref-filter.h\nindex 69271e8c39f40..f590e5d694df4 100644\n--- a/ref-filter.h\n+++ b/ref-filter.h\n@@ -86,13 +86,6 @@ struct expand_data {\n \tconst char *rest;\n \tstruct object_id delta_base_oid;\n \n-\t/*\n-\t * Whether to split the input on whitespace before feeding it to\n-\t * get_sha1; this is decided during the mark_query phase based on\n-\t * whether we have a %(rest) token in our format.\n-\t */\n-\tint split_on_whitespace;\n-\n \t/*\n \t * After a mark_query run, this object_info is set up to be\n \t * passed to sha1_object_info_extended. It will point to the data\n@@ -187,4 +180,7 @@ void pretty_print_ref(const char *name, const unsigned char *sha1,\n /* Fill the values of request and prepare all data for final string creation */\n int populate_value(struct ref_array_item *ref);\n \n+/* Search for atom in given format. */\n+int is_atom_used(const struct ref_format *format, const char *atom);\n+\n #endif /*  REF_FILTER_H  */\n\n--\nhttps://github.com/git/git/pull/452\n"},{"id":"338200","messageId":"0102016165b8b43d-02e7214d-c360-444d-a25f-2f1b5721db4d-000000@eu-west-1.amazonses.com","threadId":"47756","inReplyTo":"0102016165b8b3c4-54efe4c4-6d19-435d-b5b9-6c727771353b-000000@eu-west-1.amazonses.com","subject":"[PATCH RFC v2 10/25] ref-filter: make populate_value() global","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-02-05T11:27:39Z","receivedAt":"2018-02-05T11:28:20Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Make function global for further using in cat-file.\nIn the end of patch series this function becomes internal again,\nso this is a part of middle step. cat-file would use more general\nfunctions further.\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored by: Jeff King <peff@peff.net>\n---\n ref-filter.c | 2 +-\n ref-filter.h | 3 +++\n 2 files changed, 4 insertions(+), 1 deletion(-)\n\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 5c75259b1ab8c..4acd391b5dfac 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -1407,7 +1407,7 @@ static const char *get_refname(struct used_atom *atom, struct ref_array_item *re\n  * Parse the object referred by ref, and grab needed value.\n  * Return 0 if everything was successful, -1 otherwise.\n  */\n-static int populate_value(struct ref_array_item *ref)\n+int populate_value(struct ref_array_item *ref)\n {\n \tvoid *buf;\n \tstruct object *obj;\ndiff --git a/ref-filter.h b/ref-filter.h\nindex 781921d4e0978..e16ea2a990119 100644\n--- a/ref-filter.h\n+++ b/ref-filter.h\n@@ -182,4 +182,7 @@ void setup_ref_filter_porcelain_msg(void);\n void pretty_print_ref(const char *name, const unsigned char *sha1,\n \t\t      const struct ref_format *format);\n \n+/* Fill the values of request and prepare all data for final string creation */\n+int populate_value(struct ref_array_item *ref);\n+\n #endif /*  REF_FILTER_H  */\n\n--\nhttps://github.com/git/git/pull/452\n"},{"id":"338201","messageId":"0102016165b8b466-7ec0e6e3-0d33-4665-be2c-b1c12bcb37b5-000000@eu-west-1.amazonses.com","threadId":"47756","inReplyTo":"0102016165b8b3c4-54efe4c4-6d19-435d-b5b9-6c727771353b-000000@eu-west-1.amazonses.com","subject":"[PATCH RFC v2 18/25] ref-filter: make valid_atom general again","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-02-05T11:27:39Z","receivedAt":"2018-02-05T11:28:23Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Stop using valid_cat_file_atom, making the code more general.\nFurther commits will contain some tests, docs and\nsupport of new features.\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored by: Jeff King <peff@peff.net>\n---\n ref-filter.c | 34 +++++++++-------------------------\n 1 file changed, 9 insertions(+), 25 deletions(-)\n\ndiff --git a/ref-filter.c b/ref-filter.c\nindex a65a90790fd2c..3f3583ac515a5 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -359,8 +359,8 @@ static struct valid_atom {\n \tvoid (*parser)(const struct ref_format *format, struct used_atom *atom, const char *arg);\n } valid_atom[] = {\n \t{ \"refname\" , FIELD_STR, refname_atom_parser },\n-\t{ \"objecttype\" },\n-\t{ \"objectsize\", FIELD_ULONG },\n+\t{ \"objecttype\", FIELD_STR, objecttype_atom_parser },\n+\t{ \"objectsize\", FIELD_ULONG, objectsize_atom_parser },\n \t{ \"objectname\", FIELD_STR, objectname_atom_parser },\n \t{ \"tree\" },\n \t{ \"parent\" },\n@@ -397,12 +397,6 @@ static struct valid_atom {\n \t{ \"if\", FIELD_STR, if_atom_parser },\n \t{ \"then\" },\n \t{ \"else\" },\n-};\n-\n-static struct valid_atom valid_cat_file_atom[] = {\n-\t{ \"objectname\" },\n-\t{ \"objecttype\", FIELD_STR, objecttype_atom_parser },\n-\t{ \"objectsize\", FIELD_ULONG, objectsize_atom_parser },\n \t{ \"rest\" },\n \t{ \"deltabase\", FIELD_STR, deltabase_atom_parser },\n };\n@@ -432,7 +426,6 @@ struct atom_value {\n  * Used to parse format string and sort specifiers\n  */\n static int parse_ref_filter_atom(const struct ref_format *format,\n-\t\t\t\t const struct valid_atom *valid_atom, int n_atoms,\n \t\t\t\t const char *atom, const char *ep)\n {\n \tconst char *sp;\n@@ -462,13 +455,13 @@ static int parse_ref_filter_atom(const struct ref_format *format,\n \tatom_len = (arg ? arg : ep) - sp;\n \n \t/* Is the atom a valid one? */\n-\tfor (i = 0; i < n_atoms; i++) {\n+\tfor (i = 0; i < ARRAY_SIZE(valid_atom); i++) {\n \t\tint len = strlen(valid_atom[i].name);\n \t\tif (len == atom_len && !memcmp(valid_atom[i].name, sp, len))\n \t\t\tbreak;\n \t}\n \n-\tif (n_atoms <= i)\n+\tif (ARRAY_SIZE(valid_atom) <= i)\n \t\tdie(_(\"unknown field name: %.*s\"), (int)(ep-atom), atom);\n \n \t/* Add it in, including the deref prefix */\n@@ -762,15 +755,9 @@ int verify_ref_format(struct ref_format *format)\n \t\t\treturn error(_(\"malformed format string %s\"), sp);\n \t\t/* sp points at \"%(\" and ep points at the closing \")\" */\n \n-\t\tif (is_cat)\n-\t\t\tat = parse_ref_filter_atom(format, valid_cat_file_atom,\n-\t\t\t\t\t\t   ARRAY_SIZE(valid_cat_file_atom), sp + 2, ep);\n-\t\telse {\n-\t\t\tat = parse_ref_filter_atom(format, valid_atom,\n-\t\t\t\t\t\t   ARRAY_SIZE(valid_atom), sp + 2, ep);\n-\t\t\tif (skip_prefix(used_atom[at].name, \"color:\", &color))\n-\t\t\t\tformat->need_color_reset_at_eol = !!strcmp(color, \"reset\");\n-\t\t}\n+\t\tat = parse_ref_filter_atom(format, sp + 2, ep);\n+\t\tif (skip_prefix(used_atom[at].name, \"color:\", &color))\n+\t\t\tformat->need_color_reset_at_eol = !!strcmp(color, \"reset\");\n \n \t\tcp = ep + 1;\n \t}\n@@ -2232,9 +2219,7 @@ int format_ref_array_item(struct ref_array_item *info,\n \t\tif (cp < sp)\n \t\t\tappend_literal(cp, sp, &state);\n \t\tif (get_ref_atom_value(info,\n-\t\t\t\t       parse_ref_filter_atom(format, valid_atom,\n-\t\t\t\t\t\t\t     ARRAY_SIZE(valid_atom),\n-\t\t\t\t\t\t\t     sp + 2, ep),\n+\t\t\t\t       parse_ref_filter_atom(format, sp + 2, ep),\n \t\t\t\t       &atomv))\n \t\t\treturn -1;\n \t\tatomv->handler(atomv, &state);\n@@ -2287,8 +2272,7 @@ static int parse_sorting_atom(const char *atom)\n \t */\n \tstruct ref_format dummy = REF_FORMAT_INIT;\n \tconst char *end = atom + strlen(atom);\n-\treturn parse_ref_filter_atom(&dummy, valid_atom,\n-\t\t\t\t     ARRAY_SIZE(valid_atom), atom, end);\n+\treturn parse_ref_filter_atom(&dummy, atom, end);\n }\n \n /*  If no sorting option is given, use refname to sort as default */\n\n--\nhttps://github.com/git/git/pull/452\n"},{"id":"338202","messageId":"0102016165b8b41c-79ff8d08-8681-4bd2-b0a8-13580048c543-000000@eu-west-1.amazonses.com","threadId":"47756","inReplyTo":"0102016165b8b3c4-54efe4c4-6d19-435d-b5b9-6c727771353b-000000@eu-west-1.amazonses.com","subject":"[PATCH RFC v2 02/25] ref-filter: add return value to some functions","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-02-05T11:27:39Z","receivedAt":"2018-02-05T11:28:26Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Add return flag to format_ref_array_item(), show_ref_array_item(),\nget_ref_array_info() and populate_value() for further using.\nNeed it to handle situations when item is broken but we can not invoke\ndie() because we are in batch mode and all items need to be processed.\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored by: Jeff King <peff@peff.net>\n---\n ref-filter.c | 37 ++++++++++++++++++++++++-------------\n ref-filter.h | 14 ++++++++++----\n 2 files changed, 34 insertions(+), 17 deletions(-)\n\ndiff --git a/ref-filter.c b/ref-filter.c\nindex d04295e33448e..9ed5e66066a7a 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -1356,8 +1356,9 @@ static const char *get_refname(struct used_atom *atom, struct ref_array_item *re\n \n /*\n  * Parse the object referred by ref, and grab needed value.\n+ * Return 0 if everything was successful, -1 otherwise.\n  */\n-static void populate_value(struct ref_array_item *ref)\n+static int populate_value(struct ref_array_item *ref)\n {\n \tvoid *buf;\n \tstruct object *obj;\n@@ -1482,7 +1483,7 @@ static void populate_value(struct ref_array_item *ref)\n \t\t}\n \t}\n \tif (used_atom_cnt <= i)\n-\t\treturn;\n+\t\treturn 0;\n \n \tbuf = get_obj(&ref->objectname, &obj, &size, &eaten);\n \tif (!buf)\n@@ -1501,7 +1502,7 @@ static void populate_value(struct ref_array_item *ref)\n \t * object, we are done.\n \t */\n \tif (!need_tagged || (obj->type != OBJ_TAG))\n-\t\treturn;\n+\t\treturn 0;\n \n \t/*\n \t * If it is a tag object, see if we use a value that derefs\n@@ -1525,19 +1526,24 @@ static void populate_value(struct ref_array_item *ref)\n \tgrab_values(ref->value, 1, obj, buf, size);\n \tif (!eaten)\n \t\tfree(buf);\n+\n+\treturn 0;\n }\n \n /*\n  * Given a ref, return the value for the atom.  This lazily gets value\n  * out of the object by calling populate value.\n+ * Return 0 if everything was successful, -1 otherwise.\n  */\n-static void get_ref_atom_value(struct ref_array_item *ref, int atom, struct atom_value **v)\n+static int get_ref_atom_value(struct ref_array_item *ref, int atom, struct atom_value **v)\n {\n+\tint retval = 0;\n \tif (!ref->value) {\n-\t\tpopulate_value(ref);\n+\t\tretval = populate_value(ref);\n \t\tfill_missing_values(ref->value);\n \t}\n \t*v = &ref->value[atom];\n+\treturn retval;\n }\n \n /*\n@@ -2122,7 +2128,7 @@ static void append_literal(const char *cp, const char *ep, struct ref_formatting\n \t}\n }\n \n-void format_ref_array_item(struct ref_array_item *info,\n+int format_ref_array_item(struct ref_array_item *info,\n \t\t\t   const struct ref_format *format,\n \t\t\t   struct strbuf *final_buf)\n {\n@@ -2138,9 +2144,10 @@ void format_ref_array_item(struct ref_array_item *info,\n \t\tep = strchr(sp, ')');\n \t\tif (cp < sp)\n \t\t\tappend_literal(cp, sp, &state);\n-\t\tget_ref_atom_value(info,\n-\t\t\t\t   parse_ref_filter_atom(format, sp + 2, ep),\n-\t\t\t\t   &atomv);\n+\t\tif (get_ref_atom_value(info,\n+\t\t\t\t       parse_ref_filter_atom(format, sp + 2, ep),\n+\t\t\t\t       &atomv))\n+\t\t\treturn -1;\n \t\tatomv->handler(atomv, &state);\n \t}\n \tif (*cp) {\n@@ -2156,17 +2163,21 @@ void format_ref_array_item(struct ref_array_item *info,\n \t\tdie(_(\"format: %%(end) atom missing\"));\n \tstrbuf_addbuf(final_buf, &state.stack->output);\n \tpop_stack_element(&state.stack);\n+\treturn 0;\n }\n \n-void show_ref_array_item(struct ref_array_item *info,\n+int show_ref_array_item(struct ref_array_item *info,\n \t\t\t const struct ref_format *format)\n {\n \tstruct strbuf final_buf = STRBUF_INIT;\n+\tint retval = format_ref_array_item(info, format, &final_buf);\n \n-\tformat_ref_array_item(info, format, &final_buf);\n-\tfwrite(final_buf.buf, 1, final_buf.len, stdout);\n+\tif (!retval) {\n+\t\tfwrite(final_buf.buf, 1, final_buf.len, stdout);\n+\t\tputchar('\\n');\n+\t}\n \tstrbuf_release(&final_buf);\n-\tputchar('\\n');\n+\treturn retval;\n }\n \n void pretty_print_ref(const char *name, const unsigned char *sha1,\ndiff --git a/ref-filter.h b/ref-filter.h\nindex 0d98342b34319..b75c8ac45248e 100644\n--- a/ref-filter.h\n+++ b/ref-filter.h\n@@ -109,12 +109,18 @@ void ref_array_clear(struct ref_array *array);\n int verify_ref_format(struct ref_format *format);\n /*  Sort the given ref_array as per the ref_sorting provided */\n void ref_array_sort(struct ref_sorting *sort, struct ref_array *array);\n-/*  Based on the given format and quote_style, fill the strbuf */\n-void format_ref_array_item(struct ref_array_item *info,\n+/*\n+ * Based on the given format and quote_style, fill the strbuf.\n+ * Return 0 if everything was successful, -1 otherwise (and strbuf remains empty)\n+ */\n+int format_ref_array_item(struct ref_array_item *info,\n \t\t\t   const struct ref_format *format,\n \t\t\t   struct strbuf *final_buf);\n-/*  Print the ref using the given format and quote_style */\n-void show_ref_array_item(struct ref_array_item *info, const struct ref_format *format);\n+/*\n+ * Print the ref using the given format and quote_style.\n+ * Return 0 if everything was successful, -1 otherwise.\n+ */\n+int show_ref_array_item(struct ref_array_item *info, const struct ref_format *format);\n /*  Parse a single sort specifier and add it to the list */\n void parse_ref_sorting(struct ref_sorting **sorting_tail, const char *atom);\n /*  Callback function for parsing the sort option */\n\n--\nhttps://github.com/git/git/pull/452\n"},{"id":"338203","messageId":"0102016165b8b45f-ef11e989-4095-4130-8708-9a335136a8e6-000000@eu-west-1.amazonses.com","threadId":"47756","inReplyTo":"0102016165b8b3c4-54efe4c4-6d19-435d-b5b9-6c727771353b-000000@eu-west-1.amazonses.com","subject":"[PATCH RFC v2 20/25] ref-filter: make populate_value() internal again","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-02-05T11:27:39Z","receivedAt":"2018-02-05T11:28:28Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Remove populate_value() from header file. We needed that\nfor interim step, now it could be returned back.\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored by: Jeff King <peff@peff.net>\n---\n ref-filter.c | 2 +-\n ref-filter.h | 3 ---\n 2 files changed, 1 insertion(+), 4 deletions(-)\n\ndiff --git a/ref-filter.c b/ref-filter.c\nindex e34580e8db508..70c685851466b 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -1429,7 +1429,7 @@ static int check_and_fill_for_cat(struct ref_array_item *ref)\n  * Parse the object referred by ref, and grab needed value.\n  * Return 0 if everything was successful, -1 otherwise.\n  */\n-int populate_value(struct ref_array_item *ref)\n+static int populate_value(struct ref_array_item *ref)\n {\n \tvoid *buf;\n \tstruct object *obj;\ndiff --git a/ref-filter.h b/ref-filter.h\nindex 244a27bfc4e12..c0edb17aa404a 100644\n--- a/ref-filter.h\n+++ b/ref-filter.h\n@@ -177,9 +177,6 @@ void setup_ref_filter_porcelain_msg(void);\n void pretty_print_ref(const char *name, const unsigned char *sha1,\n \t\t      const struct ref_format *format);\n \n-/* Fill the values of request and prepare all data for final string creation */\n-int populate_value(struct ref_array_item *ref);\n-\n /* Search for atom in given format. */\n int is_atom_used(const struct ref_format *format, const char *atom);\n \n\n--\nhttps://github.com/git/git/pull/452\n"},{"id":"338204","messageId":"0102016165b8b471-72f5b9de-0738-47d6-babf-2817ace7e518-000000@eu-west-1.amazonses.com","threadId":"47756","inReplyTo":"0102016165b8b3c4-54efe4c4-6d19-435d-b5b9-6c727771353b-000000@eu-west-1.amazonses.com","subject":"[PATCH RFC v2 19/25] cat-file: reuse printing logic from ref-filter","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-02-05T11:27:39Z","receivedAt":"2018-02-05T11:28:31Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Reuse code from ref-filter to print resulting message.\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored by: Jeff King <peff@peff.net>\n---\n builtin/cat-file.c | 51 ++++-----------------------------------------------\n ref-filter.c       | 21 +++++++++++++++++++--\n 2 files changed, 23 insertions(+), 49 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 5b9869cdb9096..746b02ff150a7 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -176,45 +176,6 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,\n \treturn 0;\n }\n \n-static int is_atom(const char *atom, const char *s, int slen)\n-{\n-\tint alen = strlen(atom);\n-\treturn alen == slen && !memcmp(atom, s, alen);\n-}\n-\n-static void expand_atom(struct strbuf *sb, const char *atom, int len,\n-\t\t\t struct ref_array_item *item)\n-{\n-\tif (is_atom(\"objectname\", atom, len))\n-\t\tstrbuf_addstr(sb, oid_to_hex(&item->oid));\n-\telse if (is_atom(\"objecttype\", atom, len))\n-\t\tstrbuf_addstr(sb, typename(item->type));\n-\telse if (is_atom(\"objectsize\", atom, len))\n-\t\tstrbuf_addf(sb, \"%lu\", item->size);\n-\telse if (is_atom(\"objectsize:disk\", atom, len))\n-\t\tstrbuf_addf(sb, \"%\"PRIuMAX, (uintmax_t)item->disk_size);\n-\telse if (is_atom(\"rest\", atom, len)) {\n-\t\tif (item->rest)\n-\t\t\tstrbuf_addstr(sb, item->rest);\n-\t} else if (is_atom(\"deltabase\", atom, len))\n-\t\tstrbuf_addstr(sb, oid_to_hex(item->delta_base_oid));\n-}\n-\n-static size_t expand_format(struct strbuf *sb, const char *start, void *data)\n-{\n-\tconst char *end;\n-\tstruct ref_array_item *item = data;\n-\n-\tif (*start != '(')\n-\t\treturn 0;\n-\tend = strchr(start + 1, ')');\n-\tif (!end)\n-\t\tdie(\"format element '%s' does not end in ')'\", start);\n-\n-\texpand_atom(sb, start + 1, end - start - 1, item);\n-\treturn end - start + 1;\n-}\n-\n static void batch_write(struct batch_options *opt, const void *data, int len)\n {\n \tif (opt->buffer_output) {\n@@ -282,23 +243,19 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d\n static void batch_object_write(const char *obj_name, struct batch_options *opt,\n \t\t\t       struct expand_data *data)\n {\n-\tstruct strbuf buf = STRBUF_INIT;\n \tstruct ref_array_item item = {0};\n \n \titem.oid = data->oid;\n \titem.rest = data->rest;\n \titem.objectname = obj_name;\n \n-\tif (populate_value(&item))\n+\tif (show_ref_array_item(&item, &opt->format))\n \t\treturn;\n-\n-\tdata->type = item.type;\n-\tstrbuf_expand(&buf, opt->format.format, expand_format, &item);\n-\tstrbuf_addch(&buf, '\\n');\n-\tbatch_write(opt, buf.buf, buf.len);\n-\tstrbuf_release(&buf);\n+\tif (!opt->buffer_output)\n+\t\tfflush(stdout);\n \n \tif (opt->print_contents) {\n+\t\tdata->type = item.type;\n \t\tprint_object_or_die(opt, data);\n \t\tbatch_write(opt, \"\\n\", 1);\n \t}\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 3f3583ac515a5..e34580e8db508 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -1466,7 +1466,21 @@ int populate_value(struct ref_array_item *ref)\n \t\t\tname++;\n \t\t}\n \n-\t\tif (starts_with(name, \"refname\"))\n+\t\tif (is_cat) {\n+\t\t\tif (starts_with(name, \"objectname\"))\n+\t\t\t\tv->s = oid_to_hex(&ref->oid);\n+\t\t\telse if (starts_with(name, \"objecttype\"))\n+\t\t\t\tv->s = typename(ref->type);\n+\t\t\telse if (starts_with(name, \"objectsize\")) {\n+\t\t\t\tv->s = xstrfmt(\"%lu\", ref->size);\n+\t\t\t} else if (starts_with(name, \"objectsize:disk\")) {\n+\t\t\t\tv->s = xstrfmt(\"%\"PRIuMAX, (uintmax_t)ref->disk_size);\n+\t\t\t} else if (starts_with(name, \"rest\"))\n+\t\t\t\tv->s = ref->rest;\n+\t\t\telse if (starts_with(name, \"deltabase\"))\n+\t\t\t\tv->s = xstrdup(oid_to_hex(ref->delta_base_oid));\n+\t\t\tcontinue;\n+\t\t} else if (starts_with(name, \"refname\"))\n \t\t\trefname = get_refname(atom, ref);\n \t\telse if (starts_with(name, \"symref\"))\n \t\t\trefname = get_symref(atom, ref);\n@@ -2208,6 +2222,7 @@ int format_ref_array_item(struct ref_array_item *info,\n {\n \tconst char *cp, *sp, *ep;\n \tstruct ref_formatting_state state = REF_FORMATTING_STATE_INIT;\n+\tint retval = 0;\n \n \tstate.quote_style = format->quote_style;\n \tpush_stack_element(&state.stack);\n@@ -2224,6 +2239,8 @@ int format_ref_array_item(struct ref_array_item *info,\n \t\t\treturn -1;\n \t\tatomv->handler(atomv, &state);\n \t}\n+\tif (is_cat && strlen(format->format) == 0)\n+\t\tretval = check_and_fill_for_cat(info);\n \tif (*cp) {\n \t\tsp = cp + strlen(cp);\n \t\tappend_literal(cp, sp, &state);\n@@ -2237,7 +2254,7 @@ int format_ref_array_item(struct ref_array_item *info,\n \t\tdie(_(\"format: %%(end) atom missing\"));\n \tstrbuf_addbuf(final_buf, &state.stack->output);\n \tpop_stack_element(&state.stack);\n-\treturn 0;\n+\treturn retval;\n }\n \n int show_ref_array_item(struct ref_array_item *info,\n\n--\nhttps://github.com/git/git/pull/452\n"},{"id":"338205","messageId":"0102016165b8b44a-5508af8f-5539-4938-b41d-46137915de22-000000@eu-west-1.amazonses.com","threadId":"47756","inReplyTo":"0102016165b8b3c4-54efe4c4-6d19-435d-b5b9-6c727771353b-000000@eu-west-1.amazonses.com","subject":"[PATCH RFC v2 12/25] cat-file: start reusing populate_value()","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-02-05T11:27:39Z","receivedAt":"2018-02-05T11:28:33Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Move logic related to getting object info from cat-file to ref-filter.\nIt will help to reuse whole formatting logic from ref-filter further.\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored by: Jeff King <peff@peff.net>\n---\n builtin/cat-file.c | 17 ++++-------------\n ref-filter.c       | 20 ++++++++++++++++++++\n ref-filter.h       |  1 +\n 3 files changed, 25 insertions(+), 13 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 367b1bd5802dc..179c955b86bd5 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -285,21 +285,12 @@ static void batch_object_write(const char *obj_name, struct batch_options *opt,\n \tstruct strbuf buf = STRBUF_INIT;\n \tstruct ref_array_item item = {0};\n \n-\tif (!data->skip_object_info &&\n-\t    sha1_object_info_extended(data->oid.hash, &data->info,\n-\t\t\t\t      OBJECT_INFO_LOOKUP_REPLACE) < 0) {\n-\t\tprintf(\"%s missing\\n\",\n-\t\t       obj_name ? obj_name : oid_to_hex(&data->oid));\n-\t\tfflush(stdout);\n-\t\treturn;\n-\t}\n-\n \titem.oid = data->oid;\n-\titem.type = data->type;\n-\titem.size = data->size;\n-\titem.disk_size = data->disk_size;\n \titem.rest = data->rest;\n-\titem.delta_base_oid = &data->delta_base_oid;\n+\titem.objectname = obj_name;\n+\n+\tif (populate_value(&item))\n+\t\treturn;\n \n \tstrbuf_expand(&buf, opt->format.format, expand_format, &item);\n \tstrbuf_addch(&buf, '\\n');\ndiff --git a/ref-filter.c b/ref-filter.c\nindex d09ec1bde6d54..3f92a27d98b6c 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -1403,6 +1403,23 @@ static const char *get_refname(struct used_atom *atom, struct ref_array_item *re\n \treturn show_ref(&atom->u.refname, ref->refname);\n }\n \n+static int check_and_fill_for_cat(struct ref_array_item *ref)\n+{\n+\tif (!cat_file_info->skip_object_info &&\n+\t    sha1_object_info_extended(ref->oid.hash, &cat_file_info->info,\n+\t\t\t\t      OBJECT_INFO_LOOKUP_REPLACE) < 0) {\n+\t\tconst char *e = ref->objectname;\n+\t\tprintf(\"%s missing\\n\", e ? e : oid_to_hex(&ref->oid));\n+\t\tfflush(stdout);\n+\t\treturn -1;\n+\t}\n+\tref->type = cat_file_info->type;\n+\tref->size = cat_file_info->size;\n+\tref->disk_size = cat_file_info->disk_size;\n+\tref->delta_base_oid = &cat_file_info->delta_base_oid;\n+\treturn 0;\n+}\n+\n /*\n  * Parse the object referred by ref, and grab needed value.\n  * Return 0 if everything was successful, -1 otherwise.\n@@ -1424,6 +1441,9 @@ int populate_value(struct ref_array_item *ref)\n \t\t\tref->symref = \"\";\n \t}\n \n+\tif (cat_file_info && check_and_fill_for_cat(ref))\n+\t\treturn -1;\n+\n \t/* Fill in specials first */\n \tfor (i = 0; i < used_atom_cnt; i++) {\n \t\tstruct used_atom *atom = &used_atom[i];\ndiff --git a/ref-filter.h b/ref-filter.h\nindex 87b026b8b76d0..5c6e019998716 100644\n--- a/ref-filter.h\n+++ b/ref-filter.h\n@@ -45,6 +45,7 @@ struct ref_array_item {\n \toff_t disk_size;\n \tconst char *rest;\n \tstruct object_id *delta_base_oid;\n+\tconst char *objectname;\n \tchar refname[FLEX_ARRAY];\n };\n \n\n--\nhttps://github.com/git/git/pull/452\n"},{"id":"338206","messageId":"0102016165b8b44c-a6d5c188-a9f2-4c5a-8cfb-6094af8f0163-000000@eu-west-1.amazonses.com","threadId":"47756","inReplyTo":"0102016165b8b3c4-54efe4c4-6d19-435d-b5b9-6c727771353b-000000@eu-west-1.amazonses.com","subject":"[PATCH RFC v2 14/25] ref-filter: add is_cat flag","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-02-05T11:27:39Z","receivedAt":"2018-02-05T11:28:36Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Add is_cat flag, further it helps to get rid of cat_file_data field\nin ref_format.\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored by: Jeff King <peff@peff.net>\n---\n builtin/cat-file.c | 1 +\n ref-filter.c       | 8 +++++---\n ref-filter.h       | 1 +\n 3 files changed, 7 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 179c955b86bd5..e8e788f41b890 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -395,6 +395,7 @@ static int batch_objects(struct batch_options *opt)\n \t */\n \tmemset(&data, 0, sizeof(data));\n \topt->format.cat_file_data = &data;\n+\topt->format.is_cat = 1;\n \tverify_ref_format(&opt->format);\n \tif (opt->cmdmode)\n \t\tdata.split_on_whitespace = 1;\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 34a54db168265..91290b62450b3 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -101,6 +101,7 @@ static struct used_atom {\n } *used_atom;\n static int used_atom_cnt, need_tagged, need_symref;\n struct expand_data *cat_file_info;\n+static int is_cat = 0;\n \n static void color_atom_parser(const struct ref_format *format, struct used_atom *atom, const char *color_value)\n {\n@@ -493,7 +494,7 @@ static int parse_ref_filter_atom(const struct ref_format *format,\n \t\tneed_tagged = 1;\n \tif (!strcmp(valid_atom[i].name, \"symref\"))\n \t\tneed_symref = 1;\n-\tif (cat_file_info && !strcmp(valid_atom[i].name, \"rest\"))\n+\tif (is_cat && !strcmp(valid_atom[i].name, \"rest\"))\n \t\tcat_file_info->split_on_whitespace = 1;\n \treturn at;\n }\n@@ -739,6 +740,7 @@ int verify_ref_format(struct ref_format *format)\n \tconst char *cp, *sp;\n \n \tcat_file_info = format->cat_file_data;\n+\tis_cat = format->is_cat;\n \tformat->need_color_reset_at_eol = 0;\n \tfor (cp = format->format; *cp && (sp = find_next(cp)); ) {\n \t\tconst char *color, *ep = strchr(sp, ')');\n@@ -748,7 +750,7 @@ int verify_ref_format(struct ref_format *format)\n \t\t\treturn error(_(\"malformed format string %s\"), sp);\n \t\t/* sp points at \"%(\" and ep points at the closing \")\" */\n \n-\t\tif (format->cat_file_data)\n+\t\tif (is_cat)\n \t\t\tat = parse_ref_filter_atom(format, valid_cat_file_atom,\n \t\t\t\t\t\t   ARRAY_SIZE(valid_cat_file_atom), sp + 2, ep);\n \t\telse {\n@@ -1438,7 +1440,7 @@ int populate_value(struct ref_array_item *ref)\n \t\t\tref->symref = \"\";\n \t}\n \n-\tif (cat_file_info && check_and_fill_for_cat(ref))\n+\tif (is_cat && check_and_fill_for_cat(ref))\n \t\treturn -1;\n \n \t/* Fill in specials first */\ndiff --git a/ref-filter.h b/ref-filter.h\nindex 5c6e019998716..69271e8c39f40 100644\n--- a/ref-filter.h\n+++ b/ref-filter.h\n@@ -125,6 +125,7 @@ struct ref_format {\n \t * hopefully would be reduced later.\n \t */\n \tstruct expand_data *cat_file_data;\n+\tint is_cat;\n };\n \n #define REF_FORMAT_INIT { NULL, 0, -1 }\n\n--\nhttps://github.com/git/git/pull/452\n"},{"id":"338207","messageId":"0102016165b8b477-dde9b525-d0a3-4b32-a049-3b5a7042ddab-000000@eu-west-1.amazonses.com","threadId":"47756","inReplyTo":"0102016165b8b3c4-54efe4c4-6d19-435d-b5b9-6c727771353b-000000@eu-west-1.amazonses.com","subject":"[PATCH RFC v2 21/25] ref-filter: unifying formatting of cat-file opts","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-02-05T11:27:39Z","receivedAt":"2018-02-05T11:28:39Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"cat-file options are now filled by general logic.\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored by: Jeff King <peff@peff.net>\n---\n ref-filter.c | 31 ++++++++++++++-----------------\n 1 file changed, 14 insertions(+), 17 deletions(-)\n\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 70c685851466b..aa15dd0b4723e 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -825,8 +825,10 @@ static void grab_common_values(struct atom_value *val, int deref, struct object\n \t\telse if (!strcmp(name, \"objectsize\")) {\n \t\t\tv->value = sz;\n \t\t\tv->s = xstrfmt(\"%lu\", sz);\n-\t\t}\n-\t\telse if (deref)\n+\t\t} else if (!strcmp(name, \"objectsize:disk\")) {\n+\t\t\tv->value = cat_file_info.disk_size;\n+\t\t\tv->s = xstrfmt(\"%\"PRIuMAX, (uintmax_t)v->value);\n+\t\t} else if (deref)\n \t\t\tgrab_objectname(name, obj->oid.hash, v, &used_atom[i]);\n \t}\n }\n@@ -1466,21 +1468,7 @@ static int populate_value(struct ref_array_item *ref)\n \t\t\tname++;\n \t\t}\n \n-\t\tif (is_cat) {\n-\t\t\tif (starts_with(name, \"objectname\"))\n-\t\t\t\tv->s = oid_to_hex(&ref->oid);\n-\t\t\telse if (starts_with(name, \"objecttype\"))\n-\t\t\t\tv->s = typename(ref->type);\n-\t\t\telse if (starts_with(name, \"objectsize\")) {\n-\t\t\t\tv->s = xstrfmt(\"%lu\", ref->size);\n-\t\t\t} else if (starts_with(name, \"objectsize:disk\")) {\n-\t\t\t\tv->s = xstrfmt(\"%\"PRIuMAX, (uintmax_t)ref->disk_size);\n-\t\t\t} else if (starts_with(name, \"rest\"))\n-\t\t\t\tv->s = ref->rest;\n-\t\t\telse if (starts_with(name, \"deltabase\"))\n-\t\t\t\tv->s = xstrdup(oid_to_hex(ref->delta_base_oid));\n-\t\t\tcontinue;\n-\t\t} else if (starts_with(name, \"refname\"))\n+\t\tif (starts_with(name, \"refname\"))\n \t\t\trefname = get_refname(atom, ref);\n \t\telse if (starts_with(name, \"symref\"))\n \t\t\trefname = get_symref(atom, ref);\n@@ -1536,6 +1524,15 @@ static int populate_value(struct ref_array_item *ref)\n \t\t\telse\n \t\t\t\tv->s = \" \";\n \t\t\tcontinue;\n+\t\t} else if (starts_with(name, \"rest\")) {\n+\t\t\tv->s = ref->rest ? ref->rest : \"\";\n+\t\t\tcontinue;\n+\t\t} else if (starts_with(name, \"deltabase\")) {\n+\t\t\tif (ref->delta_base_oid)\n+\t\t\t\tv->s = xstrdup(oid_to_hex(ref->delta_base_oid));\n+\t\t\telse\n+\t\t\t\tv->s = \"\";\n+\t\t\tcontinue;\n \t\t} else if (starts_with(name, \"align\")) {\n \t\t\tv->handler = align_atom_handler;\n \t\t\tcontinue;\n\n--\nhttps://github.com/git/git/pull/452\n"},{"id":"338208","messageId":"0102016165b8b435-2029d2cf-fff4-4f4c-bc87-4c6f6a5ec1a5-000000@eu-west-1.amazonses.com","threadId":"47756","inReplyTo":"0102016165b8b3c4-54efe4c4-6d19-435d-b5b9-6c727771353b-000000@eu-west-1.amazonses.com","subject":"[PATCH RFC v2 09/25] cat-file: start use ref_array_item struct","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-02-05T11:27:39Z","receivedAt":"2018-02-05T11:28:42Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Moving from using expand_data to ref_array_item structure.\nThat helps us to reuse functions from ref-filter easier.\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored by: Jeff King <peff@peff.net>\n---\n builtin/cat-file.c | 32 ++++++++++++++++++++------------\n ref-filter.h       |  5 +++++\n 2 files changed, 25 insertions(+), 12 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 909412747cbd2..61b7acc79155d 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -183,27 +183,27 @@ static int is_atom(const char *atom, const char *s, int slen)\n }\n \n static void expand_atom(struct strbuf *sb, const char *atom, int len,\n-\t\t\t struct expand_data *data)\n+\t\t\t struct ref_array_item *item)\n {\n \tif (is_atom(\"objectname\", atom, len))\n-\t\tstrbuf_addstr(sb, oid_to_hex(&data->oid));\n+\t\tstrbuf_addstr(sb, oid_to_hex(&item->objectname));\n \telse if (is_atom(\"objecttype\", atom, len))\n-\t\tstrbuf_addstr(sb, typename(data->type));\n+\t\tstrbuf_addstr(sb, typename(item->type));\n \telse if (is_atom(\"objectsize\", atom, len))\n-\t\tstrbuf_addf(sb, \"%lu\", data->size);\n+\t\tstrbuf_addf(sb, \"%lu\", item->size);\n \telse if (is_atom(\"objectsize:disk\", atom, len))\n-\t\tstrbuf_addf(sb, \"%\"PRIuMAX, (uintmax_t)data->disk_size);\n+\t\tstrbuf_addf(sb, \"%\"PRIuMAX, (uintmax_t)item->disk_size);\n \telse if (is_atom(\"rest\", atom, len)) {\n-\t\tif (data->rest)\n-\t\t\tstrbuf_addstr(sb, data->rest);\n+\t\tif (item->rest)\n+\t\t\tstrbuf_addstr(sb, item->rest);\n \t} else if (is_atom(\"deltabase\", atom, len))\n-\t\tstrbuf_addstr(sb, oid_to_hex(&data->delta_base_oid));\n+\t\tstrbuf_addstr(sb, oid_to_hex(item->delta_base_oid));\n }\n \n-static size_t expand_format(struct strbuf *sb, const char *start, void *vdata)\n+static size_t expand_format(struct strbuf *sb, const char *start, void *data)\n {\n \tconst char *end;\n-\tstruct expand_data *data = vdata;\n+\tstruct ref_array_item *item = data;\n \n \tif (*start != '(')\n \t\treturn 0;\n@@ -211,7 +211,7 @@ static size_t expand_format(struct strbuf *sb, const char *start, void *vdata)\n \tif (!end)\n \t\tdie(\"format element '%s' does not end in ')'\", start);\n \n-\texpand_atom(sb, start + 1, end - start - 1, data);\n+\texpand_atom(sb, start + 1, end - start - 1, item);\n \treturn end - start + 1;\n }\n \n@@ -283,6 +283,7 @@ static void batch_object_write(const char *obj_name, struct batch_options *opt,\n \t\t\t       struct expand_data *data)\n {\n \tstruct strbuf buf = STRBUF_INIT;\n+\tstruct ref_array_item item = {0};\n \n \tif (!data->skip_object_info &&\n \t    sha1_object_info_extended(data->oid.hash, &data->info,\n@@ -293,7 +294,14 @@ static void batch_object_write(const char *obj_name, struct batch_options *opt,\n \t\treturn;\n \t}\n \n-\tstrbuf_expand(&buf, opt->format.format, expand_format, data);\n+\titem.objectname = data->oid;\n+\titem.type = data->type;\n+\titem.size = data->size;\n+\titem.disk_size = data->disk_size;\n+\titem.rest = data->rest;\n+\titem.delta_base_oid = &data->delta_base_oid;\n+\n+\tstrbuf_expand(&buf, opt->format.format, expand_format, &item);\n \tstrbuf_addch(&buf, '\\n');\n \tbatch_write(opt, buf.buf, buf.len);\n \tstrbuf_release(&buf);\ndiff --git a/ref-filter.h b/ref-filter.h\nindex 52e07dbe6864a..781921d4e0978 100644\n--- a/ref-filter.h\n+++ b/ref-filter.h\n@@ -40,6 +40,11 @@ struct ref_array_item {\n \tconst char *symref;\n \tstruct commit *commit;\n \tstruct atom_value *value;\n+\tenum object_type type;\n+\tunsigned long size;\n+\toff_t disk_size;\n+\tconst char *rest;\n+\tstruct object_id *delta_base_oid;\n \tchar refname[FLEX_ARRAY];\n };\n \n\n--\nhttps://github.com/git/git/pull/452\n"},{"id":"338209","messageId":"0102016165b8b463-f61e836f-f560-4d3b-9972-164b8ee2eceb-000000@eu-west-1.amazonses.com","threadId":"47756","inReplyTo":"0102016165b8b3c4-54efe4c4-6d19-435d-b5b9-6c727771353b-000000@eu-west-1.amazonses.com","subject":"[PATCH RFC v2 17/25] ref-filter: make cat_file_info independent","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-02-05T11:27:39Z","receivedAt":"2018-02-05T11:28:45Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Remove connection between expand_data variable\nin cat-file and in ref-filter.\nIt will help further to get rid of using expand_data in cat-file.\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored by: Jeff King <peff@peff.net>\n---\n builtin/cat-file.c |  2 +-\n ref-filter.c       | 29 +++++++++++++++--------------\n ref-filter.h       |  1 -\n 3 files changed, 16 insertions(+), 16 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 37adf626d0e55..5b9869cdb9096 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -292,6 +292,7 @@ static void batch_object_write(const char *obj_name, struct batch_options *opt,\n \tif (populate_value(&item))\n \t\treturn;\n \n+\tdata->type = item.type;\n \tstrbuf_expand(&buf, opt->format.format, expand_format, &item);\n \tstrbuf_addch(&buf, '\\n');\n \tbatch_write(opt, buf.buf, buf.len);\n@@ -393,7 +394,6 @@ static int batch_objects(struct batch_options *opt)\n \t * object.\n \t */\n \tmemset(&data, 0, sizeof(data));\n-\topt->format.cat_file_data = &data;\n \topt->format.is_cat = 1;\n \topt->format.all_objects = opt->all_objects;\n \tverify_ref_format(&opt->format);\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 7dcd36cd2cddc..a65a90790fd2c 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -100,7 +100,7 @@ static struct used_atom {\n \t} u;\n } *used_atom;\n static int used_atom_cnt, need_tagged, need_symref;\n-struct expand_data *cat_file_info;\n+struct expand_data cat_file_info;\n static int is_cat = 0;\n \n static void color_atom_parser(const struct ref_format *format, struct used_atom *atom, const char *color_value)\n@@ -256,9 +256,9 @@ static void objectname_atom_parser(const struct ref_format *format, struct used_\n static void objectsize_atom_parser(const struct ref_format *format, struct used_atom *atom, const char *arg)\n {\n \tif (!arg)\n-\t\tcat_file_info->info.sizep = &cat_file_info->size;\n+\t\tcat_file_info.info.sizep = &cat_file_info.size;\n \telse if (!strcmp(arg, \"disk\"))\n-\t\tcat_file_info->info.disk_sizep = &cat_file_info->disk_size;\n+\t\tcat_file_info.info.disk_sizep = &cat_file_info.disk_size;\n \telse\n \t\tdie(_(\"urecognized %%(objectsize) argument: %s\"), arg);\n }\n@@ -266,7 +266,7 @@ static void objectsize_atom_parser(const struct ref_format *format, struct used_\n static void objecttype_atom_parser(const struct ref_format *format, struct used_atom *atom, const char *arg)\n {\n \tif (!arg)\n-\t\tcat_file_info->info.typep = &cat_file_info->type;\n+\t\tcat_file_info.info.typep = &cat_file_info.type;\n \telse\n \t\tdie(_(\"urecognized %%(objecttype) argument: %s\"), arg);\n }\n@@ -274,7 +274,7 @@ static void objecttype_atom_parser(const struct ref_format *format, struct used_\n static void deltabase_atom_parser(const struct ref_format *format, struct used_atom *atom, const char *arg)\n {\n \tif (!arg)\n-\t\tcat_file_info->info.delta_base_sha1 = cat_file_info->delta_base_oid.hash;\n+\t\tcat_file_info.info.delta_base_sha1 = cat_file_info.delta_base_oid.hash;\n \telse\n \t\tdie(_(\"urecognized %%(deltabase) argument: %s\"), arg);\n }\n@@ -752,7 +752,6 @@ int verify_ref_format(struct ref_format *format)\n {\n \tconst char *cp, *sp;\n \n-\tcat_file_info = format->cat_file_data;\n \tis_cat = format->is_cat;\n \tformat->need_color_reset_at_eol = 0;\n \tfor (cp = format->format; *cp && (sp = find_next(cp)); ) {\n@@ -779,8 +778,8 @@ int verify_ref_format(struct ref_format *format)\n \t\tformat->need_color_reset_at_eol = 0;\n \tif (is_cat && format->all_objects) {\n \t\tstruct object_info empty = OBJECT_INFO_INIT;\n-\t\tif (!memcmp(&cat_file_info->info, &empty, sizeof(empty)))\n-\t\t\tcat_file_info->skip_object_info = 1;\n+\t\tif (!memcmp(&cat_file_info.info, &empty, sizeof(empty)))\n+\t\t\tcat_file_info.skip_object_info = 1;\n \t}\n \treturn 0;\n }\n@@ -1422,18 +1421,20 @@ static const char *get_refname(struct used_atom *atom, struct ref_array_item *re\n \n static int check_and_fill_for_cat(struct ref_array_item *ref)\n {\n-\tif (!cat_file_info->skip_object_info &&\n-\t    sha1_object_info_extended(ref->oid.hash, &cat_file_info->info,\n+\tif (!cat_file_info.info.typep)\n+\t\tcat_file_info.info.typep = &cat_file_info.type;\n+\tif (!cat_file_info.skip_object_info &&\n+\t    sha1_object_info_extended(ref->oid.hash, &cat_file_info.info,\n \t\t\t\t      OBJECT_INFO_LOOKUP_REPLACE) < 0) {\n \t\tconst char *e = ref->objectname;\n \t\tprintf(\"%s missing\\n\", e ? e : oid_to_hex(&ref->oid));\n \t\tfflush(stdout);\n \t\treturn -1;\n \t}\n-\tref->type = cat_file_info->type;\n-\tref->size = cat_file_info->size;\n-\tref->disk_size = cat_file_info->disk_size;\n-\tref->delta_base_oid = &cat_file_info->delta_base_oid;\n+\tref->type = cat_file_info.type;\n+\tref->size = cat_file_info.size;\n+\tref->disk_size = cat_file_info.disk_size;\n+\tref->delta_base_oid = &cat_file_info.delta_base_oid;\n \treturn 0;\n }\n \ndiff --git a/ref-filter.h b/ref-filter.h\nindex e882eb5126118..244a27bfc4e12 100644\n--- a/ref-filter.h\n+++ b/ref-filter.h\n@@ -117,7 +117,6 @@ struct ref_format {\n \t * Helps to move all formatting logic from cat-file to ref-filter,\n \t * hopefully would be reduced later.\n \t */\n-\tstruct expand_data *cat_file_data;\n \tint is_cat;\n \tint all_objects;\n };\n\n--\nhttps://github.com/git/git/pull/452\n"},{"id":"338210","messageId":"0102016165b8b489-c3929c56-d219-4b97-b2bb-f2c190a61baa-000000@eu-west-1.amazonses.com","threadId":"47756","inReplyTo":"0102016165b8b3c4-54efe4c4-6d19-435d-b5b9-6c727771353b-000000@eu-west-1.amazonses.com","subject":"[PATCH RFC v2 23/25] for-each-ref: tests for new atoms added","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-02-05T11:27:39Z","receivedAt":"2018-02-05T11:28:47Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Add tests for new formatting atoms: rest, deltabase, objectsize:disk.\nrest means nothing and we expand it into empty string.\nWe need this atom for cat-file command.\nHave plans to support deltabase and objectsize:disk further\n(as it is done in cat-file), now also expand it to empty string.\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored by: Jeff King <peff@peff.net>\n---\n t/t6300-for-each-ref.sh | 18 ++++++++++++++++++\n 1 file changed, 18 insertions(+)\n\ndiff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh\nindex c128dfc579079..eee656a6abba9 100755\n--- a/t/t6300-for-each-ref.sh\n+++ b/t/t6300-for-each-ref.sh\n@@ -316,6 +316,24 @@ test_expect_success 'exercise strftime with odd fields' '\n \ttest_cmp expected actual\n '\n \n+test_expect_success 'Check format %(objectsize:disk) gives empty output ' '\n+\techo >expected &&\n+\tgit for-each-ref --format=\"%(objectsize:disk)\" refs/heads >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'Check format %(rest) gives empty output ' '\n+\techo >expected &&\n+\tgit for-each-ref --format=\"%(rest)\" refs/heads >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'Check format %(deltabase) gives empty output ' '\n+\techo >expected &&\n+\tgit for-each-ref --format=\"%(deltabase)\" refs/heads >actual &&\n+\ttest_cmp expected actual\n+'\n+\n cat >expected <<\\EOF\n refs/heads/master\n refs/remotes/origin/master\n\n--\nhttps://github.com/git/git/pull/452\n"},{"id":"338211","messageId":"0102016165b8b430-4da13fdc-470c-4b89-b576-3fc983f35a5b-000000@eu-west-1.amazonses.com","threadId":"47756","inReplyTo":"0102016165b8b3c4-54efe4c4-6d19-435d-b5b9-6c727771353b-000000@eu-west-1.amazonses.com","subject":"[PATCH RFC v2 07/25] cat-file: start migrating formatting to ref-filter","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-02-05T11:27:39Z","receivedAt":"2018-02-05T11:28:51Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Move mark_atom_in_object_info() from cat-file to ref-filter and\nstart using it in verify_ref_format().\nIt also means that we start reusing verify_ref_format() in cat-file.\n\nStart from simple moving of mark_atom_in_object_info(),\nit would be removed later by integrating all needed processes into\nref-filter logic.\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored by: Jeff King <peff@peff.net>\n---\n builtin/cat-file.c | 30 +++---------------------------\n ref-filter.c       | 41 ++++++++++++++++++++++++++++++++++++-----\n ref-filter.h       | 12 ++++++------\n 3 files changed, 45 insertions(+), 38 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex edb04a96d9bd3..909412747cbd2 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -182,25 +182,6 @@ static int is_atom(const char *atom, const char *s, int slen)\n \treturn alen == slen && !memcmp(atom, s, alen);\n }\n \n-static void mark_atom_in_object_info(const char *atom, int len,\n-\t\t\t\t     struct expand_data *data)\n-{\n-\tif (is_atom(\"objectname\", atom, len))\n-\t\t; /* do nothing */\n-\telse if (is_atom(\"objecttype\", atom, len))\n-\t\tdata->info.typep = &data->type;\n-\telse if (is_atom(\"objectsize\", atom, len))\n-\t\tdata->info.sizep = &data->size;\n-\telse if (is_atom(\"objectsize:disk\", atom, len))\n-\t\tdata->info.disk_sizep = &data->disk_size;\n-\telse if (is_atom(\"rest\", atom, len))\n-\t\tdata->split_on_whitespace = 1;\n-\telse if (is_atom(\"deltabase\", atom, len))\n-\t\tdata->info.delta_base_sha1 = data->delta_base_oid.hash;\n-\telse\n-\t\tdie(\"unknown format element: %.*s\", len, atom);\n-}\n-\n static void expand_atom(struct strbuf *sb, const char *atom, int len,\n \t\t\t struct expand_data *data)\n {\n@@ -230,11 +211,7 @@ static size_t expand_format(struct strbuf *sb, const char *start, void *vdata)\n \tif (!end)\n \t\tdie(\"format element '%s' does not end in ')'\", start);\n \n-\tif (data->mark_query)\n-\t\tmark_atom_in_object_info(start + 1, end - start - 1, data);\n-\telse\n-\t\texpand_atom(sb, start + 1, end - start - 1, data);\n-\n+\texpand_atom(sb, start + 1, end - start - 1, data);\n \treturn end - start + 1;\n }\n \n@@ -418,9 +395,8 @@ static int batch_objects(struct batch_options *opt)\n \t * object.\n \t */\n \tmemset(&data, 0, sizeof(data));\n-\tdata.mark_query = 1;\n-\tstrbuf_expand(&buf, opt->format.format, expand_format, &data);\n-\tdata.mark_query = 0;\n+\topt->format.cat_file_data = &data;\n+\tverify_ref_format(&opt->format);\n \tif (opt->cmdmode)\n \t\tdata.split_on_whitespace = 1;\n \ndiff --git a/ref-filter.c b/ref-filter.c\nindex 5e7ed0f338490..ff87e632f463c 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -392,6 +392,31 @@ struct atom_value {\n \tstruct used_atom *atom;\n };\n \n+static int is_atom(const char *atom, const char *s, int slen)\n+{\n+\tint alen = strlen(atom);\n+\treturn alen == slen && !memcmp(atom, s, alen);\n+}\n+\n+static void mark_atom_in_object_info(const char *atom, int len,\n+\t\t\t\t    struct expand_data *data)\n+{\n+\tif (is_atom(\"objectname\", atom, len))\n+\t\t; /* do nothing */\n+\telse if (is_atom(\"objecttype\", atom, len))\n+\t\tdata->info.typep = &data->type;\n+\telse if (is_atom(\"objectsize\", atom, len))\n+\t\tdata->info.sizep = &data->size;\n+\telse if (is_atom(\"objectsize:disk\", atom, len))\n+\t\tdata->info.disk_sizep = &data->disk_size;\n+\telse if (is_atom(\"rest\", atom, len))\n+\t\tdata->split_on_whitespace = 1;\n+\telse if (is_atom(\"deltabase\", atom, len))\n+\t\tdata->info.delta_base_sha1 = data->delta_base_oid.hash;\n+\telse\n+\t\tdie(\"unknown format element: %.*s\", len, atom);\n+}\n+\n /*\n  * Used to parse format string and sort specifiers\n  */\n@@ -709,12 +734,18 @@ int verify_ref_format(struct ref_format *format)\n \t\tif (!ep)\n \t\t\treturn error(_(\"malformed format string %s\"), sp);\n \t\t/* sp points at \"%(\" and ep points at the closing \")\" */\n-\t\tat = parse_ref_filter_atom(format, valid_atom,\n-\t\t\t\t\t   ARRAY_SIZE(valid_atom), sp + 2, ep);\n-\t\tcp = ep + 1;\n \n-\t\tif (skip_prefix(used_atom[at].name, \"color:\", &color))\n-\t\t\tformat->need_color_reset_at_eol = !!strcmp(color, \"reset\");\n+\t\tif (format->cat_file_data)\n+\t\t\tmark_atom_in_object_info(sp + 2, ep - sp - 2,\n+\t\t\t\t\t\tformat->cat_file_data);\n+\t\telse {\n+\t\t\tat = parse_ref_filter_atom(format, valid_atom,\n+\t\t\t\t\t\t   ARRAY_SIZE(valid_atom), sp + 2, ep);\n+\t\t\tif (skip_prefix(used_atom[at].name, \"color:\", &color))\n+\t\t\t\tformat->need_color_reset_at_eol = !!strcmp(color, \"reset\");\n+\t\t}\n+\n+\t\tcp = ep + 1;\n \t}\n \tif (format->need_color_reset_at_eol && !want_color(format->use_color))\n \t\tformat->need_color_reset_at_eol = 0;\ndiff --git a/ref-filter.h b/ref-filter.h\nindex 17f2ac24d2739..52e07dbe6864a 100644\n--- a/ref-filter.h\n+++ b/ref-filter.h\n@@ -80,12 +80,6 @@ struct expand_data {\n \tconst char *rest;\n \tstruct object_id delta_base_oid;\n \n-\t/*\n-\t * If mark_query is true, we do not expand anything, but rather\n-\t * just mark the object_info with items we wish to query.\n-\t */\n-\tint mark_query;\n-\n \t/*\n \t * Whether to split the input on whitespace before feeding it to\n \t * get_sha1; this is decided during the mark_query phase based on\n@@ -119,6 +113,12 @@ struct ref_format {\n \n \t/* Internal state to ref-filter */\n \tint need_color_reset_at_eol;\n+\n+\t/*\n+\t * Helps to move all formatting logic from cat-file to ref-filter,\n+\t * hopefully would be reduced later.\n+\t */\n+\tstruct expand_data *cat_file_data;\n };\n \n #define REF_FORMAT_INIT { NULL, 0, -1 }\n\n--\nhttps://github.com/git/git/pull/452\n"},{"id":"338255","messageId":"xmqq4lmv9lsm.fsf@gitster-ct.c.googlers.com","threadId":"47756","inReplyTo":"0102016165b8b44c-a6d5c188-a9f2-4c5a-8cfb-6094af8f0163-000000@eu-west-1.amazonses.com","subject":"Re: [PATCH RFC v2 14/25] ref-filter: add is_cat flag","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-02-05T21:19:37Z","receivedAt":"2018-02-05T21:19:45Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Olga Telezhnaya <olyatelezhnaya@gmail.com> writes:\n\n> diff --git a/ref-filter.c b/ref-filter.c\n> index 34a54db168265..91290b62450b3 100644\n> --- a/ref-filter.c\n> +++ b/ref-filter.c\n> @@ -101,6 +101,7 @@ static struct used_atom {\n>  } *used_atom;\n>  static int used_atom_cnt, need_tagged, need_symref;\n>  struct expand_data *cat_file_info;\n> +static int is_cat = 0;\n>   ...\n> @@ -739,6 +740,7 @@ int verify_ref_format(struct ref_format *format)\n>  \tconst char *cp, *sp;\n>  \n>  \tcat_file_info = format->cat_file_data;\n> +\tis_cat = format->is_cat;\n\nEek.  The global cat_file_info itself may already be bad enough, but\nnow we have another one?\n\nHopefully these are all cleaned up in later steps in the series?\n\n>  \tformat->need_color_reset_at_eol = 0;\n>  \tfor (cp = format->format; *cp && (sp = find_next(cp)); ) {\n>  \t\tconst char *color, *ep = strchr(sp, ')');\n> @@ -748,7 +750,7 @@ int verify_ref_format(struct ref_format *format)\n>  \t\t\treturn error(_(\"malformed format string %s\"), sp);\n>  \t\t/* sp points at \"%(\" and ep points at the closing \")\" */\n>  \n> -\t\tif (format->cat_file_data)\n> +\t\tif (is_cat)\n>  \t\t\tat = parse_ref_filter_atom(format, valid_cat_file_atom,\n>  \t\t\t\t\t\t   ARRAY_SIZE(valid_cat_file_atom), sp + 2, ep);\n>  \t\telse {\n> @@ -1438,7 +1440,7 @@ int populate_value(struct ref_array_item *ref)\n>  \t\t\tref->symref = \"\";\n>  \t}\n>  \n> -\tif (cat_file_info && check_and_fill_for_cat(ref))\n> +\tif (is_cat && check_and_fill_for_cat(ref))\n>  \t\treturn -1;\n>  \n>  \t/* Fill in specials first */\n> diff --git a/ref-filter.h b/ref-filter.h\n> index 5c6e019998716..69271e8c39f40 100644\n> --- a/ref-filter.h\n> +++ b/ref-filter.h\n> @@ -125,6 +125,7 @@ struct ref_format {\n>  \t * hopefully would be reduced later.\n>  \t */\n>  \tstruct expand_data *cat_file_data;\n> +\tint is_cat;\n>  };\n>  \n>  #define REF_FORMAT_INIT { NULL, 0, -1 }\n>\n> --\n> https://github.com/git/git/pull/452\n"}]}