{"thread":{"id":"47573","subject":"[PATCH 11/20] cat-file: get rid of duplicate checking","startedAt":"2018-01-09T13:05:32Z","lastAt":"2018-01-10T07:07:15Z","messageCount":24,"participants":["Olga Telezhnaya","Junio C Hamano","Оля Тележная"],"isPatch":true,"patchVersion":1,"patchTotal":20},"messages":[{"id":"336230","messageId":"01020160db067b11-6e867688-40cb-4467-954d-847076ff6157-000000@eu-west-1.amazonses.com","threadId":"47573","inReplyTo":"01020160db0679c9-799a0bc4-b6d1-43e2-ad3b-80be4e4c55e9-000000@eu-west-1.amazonses.com","subject":"[PATCH 11/20] cat-file: get rid of duplicate checking","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-01-09T13:05:23Z","receivedAt":"2018-01-09T13:05:32Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"We could remove this because we have already checked that\nat verify_ref_format function in 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 | 2 --\n 1 file changed, 2 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex dd43457c0ad7e..1f331559e55c7 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -197,8 +197,6 @@ static void expand_atom(struct strbuf *sb, const char *atom, int len,\n \t\tstrbuf_addstr(sb, data->rest);\n \telse if (is_atom(\"deltabase\", atom, len))\n \t\tstrbuf_addstr(sb, oid_to_hex(&data->delta_base_oid));\n-\telse\n-\t\tdie(\"unknown format element: %.*s\", len, atom);\n }\n \n static size_t expand_format(struct strbuf *sb, const char *start, void *vdata)\n\n--\nhttps://github.com/git/git/pull/450\n"},{"id":"336231","messageId":"01020160db067b07-5333ec0b-ce92-4f85-bceb-bbb9761793a9-000000@eu-west-1.amazonses.com","threadId":"47573","inReplyTo":"01020160db0679c9-799a0bc4-b6d1-43e2-ad3b-80be4e4c55e9-000000@eu-west-1.amazonses.com","subject":"[PATCH 10/20] cat-file: simplify expand_atom function","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-01-09T13:05:23Z","receivedAt":"2018-01-09T13:05:34Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Not sure, but looks like there is no need in that checking.\nThere is a checking before whether it is null and we die in such case.\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 1 file changed, 3 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 9055fa3a8b0ae..dd43457c0ad7e 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -193,10 +193,9 @@ static void expand_atom(struct strbuf *sb, const char *atom, int 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+\telse if (is_atom(\"rest\", atom, len))\n+\t\tstrbuf_addstr(sb, data->rest);\n+\telse if (is_atom(\"deltabase\", atom, len))\n \t\tstrbuf_addstr(sb, oid_to_hex(&data->delta_base_oid));\n \telse\n \t\tdie(\"unknown format element: %.*s\", len, atom);\n\n--\nhttps://github.com/git/git/pull/450\n"},{"id":"336232","messageId":"01020160db067b13-009fca6a-7eb1-4246-8966-9e5f8e881642-000000@eu-west-1.amazonses.com","threadId":"47573","inReplyTo":"01020160db0679c9-799a0bc4-b6d1-43e2-ad3b-80be4e4c55e9-000000@eu-west-1.amazonses.com","subject":"[PATCH 09/20] cat-file: get rid of goto in ref-filter","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-01-09T13:05:23Z","receivedAt":"2018-01-09T13:05:36Z","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 | 103 ++++++++++++++++++++++++++++++-----------------------------\n 1 file changed, 53 insertions(+), 50 deletions(-)\n\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 2bd9a8fc4e39c..1b8c8787190a9 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -1405,16 +1405,60 @@ 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 void need_object(struct ref_array_item *ref) {\n+\tstruct object *obj;\n+\tconst struct object_id *tagged;\n+\tunsigned long size;\n+\tint eaten;\n+\tvoid *buf = get_obj(&ref->objectname, &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+\tif (!obj)\n+\t\tdie(_(\"parse_object_buffer failed on %s for %s\"),\n+\t\t    oid_to_hex(&ref->objectname), ref->refname);\n+\n+\tgrab_values(ref->value, 0, obj, buf, size);\n+\tif (!eaten)\n+\t\tfree(buf);\n+\n+\t/*\n+\t * If there is no atom that wants to know about tagged\n+\t * object, we are done.\n+\t */\n+\tif (!need_tagged || (obj->type != OBJ_TAG))\n+\t\treturn;\n+\n+\t/*\n+\t * If it is a tag object, see if we use a value that derefs\n+\t * the object, and if we do grab the object it refers to.\n+\t */\n+\ttagged = &((struct tag *)obj)->tagged->oid;\n+\n+\t/*\n+\t * NEEDSWORK: This derefs tag only once, which\n+\t * is good to deal with chains of trust, but\n+\t * is not consistent with what deref_tag() does\n+\t * which peels the onion to the core.\n+\t */\n+\tbuf = get_obj(tagged, &obj, &size, &eaten);\n+\tif (!buf)\n+\t\tdie(_(\"missing object %s for %s\"),\n+\t\t    oid_to_hex(tagged), ref->refname);\n+\tif (!obj)\n+\t\tdie(_(\"parse_object_buffer failed on %s for %s\"),\n+\t\t    oid_to_hex(tagged), ref->refname);\n+\tgrab_values(ref->value, 1, obj, buf, size);\n+\tif (!eaten)\n+\t\tfree(buf);\n+}\n+\n /*\n  * Parse the object referred by ref, and grab needed value.\n  */\n static void populate_value(struct ref_array_item *ref)\n {\n-\tvoid *buf;\n-\tstruct object *obj;\n-\tint eaten, i;\n-\tunsigned long size;\n-\tconst struct object_id *tagged;\n+\tint i;\n \n \tref->value = xcalloc(used_atom_cnt, sizeof(struct atom_value));\n \n@@ -1528,53 +1572,12 @@ 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\tneed_object(ref);\n+\t\t\tbreak;\n+\t\t}\n \t}\n \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-\t\t    oid_to_hex(&ref->objectname), 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-\n-\tgrab_values(ref->value, 0, obj, buf, size);\n-\tif (!eaten)\n-\t\tfree(buf);\n-\n-\t/*\n-\t * If there is no atom that wants to know about tagged\n-\t * object, we are done.\n-\t */\n-\tif (!need_tagged || (obj->type != OBJ_TAG))\n-\t\treturn;\n-\n-\t/*\n-\t * If it is a tag object, see if we use a value that derefs\n-\t * the object, and if we do grab the object it refers to.\n-\t */\n-\ttagged = &((struct tag *)obj)->tagged->oid;\n-\n-\t/*\n-\t * NEEDSWORK: This derefs tag only once, which\n-\t * is good to deal with chains of trust, but\n-\t * is not consistent with what deref_tag() does\n-\t * which peels the onion to the core.\n-\t */\n-\tbuf = get_obj(tagged, &obj, &size, &eaten);\n-\tif (!buf)\n-\t\tdie(_(\"missing object %s for %s\"),\n-\t\t    oid_to_hex(tagged), ref->refname);\n-\tif (!obj)\n-\t\tdie(_(\"parse_object_buffer failed on %s for %s\"),\n-\t\t    oid_to_hex(tagged), ref->refname);\n-\tgrab_values(ref->value, 1, obj, buf, size);\n-\tif (!eaten)\n-\t\tfree(buf);\n }\n \n /*\n\n--\nhttps://github.com/git/git/pull/450\n"},{"id":"336233","messageId":"01020160db067c88-b3fd99cb-2155-43d7-875a-f3f0d2ad0e1e-000000@eu-west-1.amazonses.com","threadId":"47573","inReplyTo":"01020160db0679c9-799a0bc4-b6d1-43e2-ad3b-80be4e4c55e9-000000@eu-west-1.amazonses.com","subject":"[PATCH 15/20] cat-file: start reusing populate_value","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-01-09T13:05:23Z","receivedAt":"2018-01-09T13:05:55Z","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 | 16 +++-------------\n ref-filter.c       | 15 +++++++++++++++\n ref-filter.h       |  2 ++\n 3 files changed, 20 insertions(+), 13 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 1c92194faaede..e11dbf88e386c 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -284,21 +284,11 @@ 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;\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.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+\titem.start_of_request = obj_name;\n+\n+\tif (populate_value(&item)) return;\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 ed1b78943b8b4..7df6d7e3d6511 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -1469,6 +1469,21 @@ int populate_value(struct ref_array_item *ref)\n \t\t\tref->symref = \"\";\n \t}\n \n+\tif (cat_file_info) {\n+\t\tif (!cat_file_info->skip_object_info &&\n+\t\t    sha1_object_info_extended(ref->objectname.hash, &cat_file_info->info,\n+\t\t\t\t\t      OBJECT_INFO_LOOKUP_REPLACE) < 0) {\n+\t\t\tconst char *e = ref->start_of_request;\n+\t\t\tprintf(\"%s missing\\n\", e ? e : oid_to_hex(&ref->objectname));\n+\t\t\tfflush(stdout);\n+\t\t\treturn -1;\n+\t\t}\n+\t\tref->type = cat_file_info->type;\n+\t\tref->size = cat_file_info->size;\n+\t\tref->disk_size = cat_file_info->disk_size;\n+\t\tref->delta_base_oid = cat_file_info->delta_base_oid;\n+\t}\n+\n \t/* Fill in specials first */\n \tfor (i = 0; i < used_atom_cnt; i++) {\n \t\tstruct used_atom *atom = &used_atoms[i];\ndiff --git a/ref-filter.h b/ref-filter.h\nindex d541749f9b1dc..9e4444cf3ef9a 100644\n--- a/ref-filter.h\n+++ b/ref-filter.h\n@@ -45,6 +45,8 @@ struct ref_array_item {\n \toff_t disk_size;\n \tconst char *rest;\n \tstruct object_id delta_base_oid;\n+\t/* Need it for better explanation in error log. */\n+\tconst char *start_of_request;\n \tchar refname[FLEX_ARRAY];\n };\n \n\n--\nhttps://github.com/git/git/pull/450\n"},{"id":"336234","messageId":"01020160db067c8a-c3ce9582-bc4d-40fd-ac96-b530f93b2752-000000@eu-west-1.amazonses.com","threadId":"47573","inReplyTo":"01020160db0679c9-799a0bc4-b6d1-43e2-ad3b-80be4e4c55e9-000000@eu-west-1.amazonses.com","subject":"[PATCH 19/20] cat-file: move skip_object_info into ref-filter","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-01-09T13:05:23Z","receivedAt":"2018-01-09T13:06:01Z","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 5aac10b9808ff..19cee0d22fabe 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -395,16 +395,11 @@ static int batch_objects(struct batch_options *opt)\n \topt->format->cat_file_data = &data;\n \topt->format->is_cat = 1;\n \topt->format->split_on_whitespace = &data.split_on_whitespace;\n+\topt->format->all_objects = opt->all_objects;\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-\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 ee27edb2dad56..dbca6856432c0 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -766,6 +766,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 3228661414623..7f7b17e659241 100644\n--- a/ref-filter.h\n+++ b/ref-filter.h\n@@ -128,6 +128,7 @@ struct ref_format {\n \tstruct expand_data *cat_file_data;\n \tint is_cat;\n \tint *split_on_whitespace;\n+\tint all_objects;\n };\n \n #define REF_FORMAT_INIT { NULL, 0, -1 }\n\n--\nhttps://github.com/git/git/pull/450\n"},{"id":"336235","messageId":"01020160db067bda-4be1f1f1-22c8-45bf-983d-053ae428cb2d-000000@eu-west-1.amazonses.com","threadId":"47573","inReplyTo":"01020160db0679c9-799a0bc4-b6d1-43e2-ad3b-80be4e4c55e9-000000@eu-west-1.amazonses.com","subject":"[PATCH 14/20] cat-file: make populate_value global","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-01-09T13:05:23Z","receivedAt":"2018-01-09T13:06:03Z","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.\nAlso added return value for handling errors.\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 | 4 ++--\n ref-filter.h | 3 +++\n 2 files changed, 5 insertions(+), 2 deletions(-)\n\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 56d2687e07df9..ed1b78943b8b4 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -1456,7 +1456,7 @@ static void need_object(struct ref_array_item *ref) {\n /*\n  * Parse the object referred by ref, and grab needed value.\n  */\n-static void populate_value(struct ref_array_item *ref)\n+int populate_value(struct ref_array_item *ref)\n {\n \tint i;\n \n@@ -1577,7 +1577,7 @@ static void populate_value(struct ref_array_item *ref)\n \t\t\tbreak;\n \t\t}\n \t}\n-\treturn;\n+\treturn 0;\n }\n \n /*\ndiff --git a/ref-filter.h b/ref-filter.h\nindex 28774e8e0f771..d541749f9b1dc 100644\n--- a/ref-filter.h\n+++ b/ref-filter.h\n@@ -176,4 +176,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/450\n"},{"id":"336236","messageId":"01020160db067ca1-d14d3b76-31fe-44cc-a655-7a548a0fe17d-000000@eu-west-1.amazonses.com","threadId":"47573","inReplyTo":"01020160db0679c9-799a0bc4-b6d1-43e2-ad3b-80be4e4c55e9-000000@eu-west-1.amazonses.com","subject":"[PATCH 20/20] cat-file: make cat_file_info variable independent","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-01-09T13:05:23Z","receivedAt":"2018-01-09T13:06:05Z","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       | 28 ++++++++++++++--------------\n ref-filter.h       |  1 -\n 3 files changed, 15 insertions(+), 16 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 19cee0d22fabe..ffa8e61213e36 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -289,6 +289,7 @@ static void batch_object_write(const char *obj_name, struct batch_options *opt,\n \titem.start_of_request = obj_name;\n \n \tif (populate_value(&item)) return;\n+\tdata->type = item.type;\n \n \tstrbuf_expand(&buf, opt->format->format, expand_format, &item);\n \tstrbuf_addch(&buf, '\\n');\n@@ -392,7 +393,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->split_on_whitespace = &data.split_on_whitespace;\n \topt->format->all_objects = opt->all_objects;\ndiff --git a/ref-filter.c b/ref-filter.c\nindex dbca6856432c0..a8a93b488db37 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_atoms;\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@@ -739,7 +739,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@@ -768,8 +767,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@@ -1474,18 +1473,19 @@ int populate_value(struct ref_array_item *ref)\n \t}\n \n \tif (is_cat) {\n-\t\tif (!cat_file_info->skip_object_info &&\n-\t\t    sha1_object_info_extended(ref->objectname.hash, &cat_file_info->info,\n+\t\tif (!cat_file_info.info.typep) cat_file_info.info.typep = &cat_file_info.type;\n+\t\tif (!cat_file_info.skip_object_info &&\n+\t\t    sha1_object_info_extended(ref->objectname.hash, &cat_file_info.info,\n \t\t\t\t\t      OBJECT_INFO_LOOKUP_REPLACE) < 0) {\n \t\t\tconst char *e = ref->start_of_request;\n \t\t\tprintf(\"%s missing\\n\", e ? e : oid_to_hex(&ref->objectname));\n \t\t\tfflush(stdout);\n \t\t\treturn -1;\n \t\t}\n-\t\tref->type = cat_file_info->type;\n-\t\tref->size = cat_file_info->size;\n-\t\tref->disk_size = cat_file_info->disk_size;\n-\t\tref->delta_base_oid = cat_file_info->delta_base_oid;\n+\t\tref->type = cat_file_info.type;\n+\t\tref->size = cat_file_info.size;\n+\t\tref->disk_size = cat_file_info.disk_size;\n+\t\tref->delta_base_oid = cat_file_info.delta_base_oid;\n \t}\n \n \t/* Fill in specials first */\ndiff --git a/ref-filter.h b/ref-filter.h\nindex 7f7b17e659241..ebaed0412fac2 100644\n--- a/ref-filter.h\n+++ b/ref-filter.h\n@@ -125,7 +125,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 *split_on_whitespace;\n \tint all_objects;\n\n--\nhttps://github.com/git/git/pull/450\n"},{"id":"336237","messageId":"01020160db067ae8-81d31cf2-0f69-4f36-9de8-27e9716d2f4b-000000@eu-west-1.amazonses.com","threadId":"47573","inReplyTo":"01020160db0679c9-799a0bc4-b6d1-43e2-ad3b-80be4e4c55e9-000000@eu-west-1.amazonses.com","subject":"[PATCH 04/20] cat-file: make valid_atoms as a function parameter","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-01-09T13:05:23Z","receivedAt":"2018-01-09T13:06:07Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Make valid_atoms as a function parameter,\nthere could be another variable further.\nNeed that for further reusing of formatting logic in cat-file.c.\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 | 15 ++++++++++-----\n 1 file changed, 10 insertions(+), 5 deletions(-)\n\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 1426f0c28bce7..2d6e81fe1ab00 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\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_atoms, 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_atoms); i++) {\n+\tfor (i = 0; i < n_atoms; i++) {\n \t\tint len = strlen(valid_atoms[i].name);\n \t\tif (len == atom_len && !memcmp(valid_atoms[i].name, sp, len))\n \t\t\tbreak;\n \t}\n \n-\tif (ARRAY_SIZE(valid_atoms) <= 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_atoms,\n+\t\t\t\t\t   ARRAY_SIZE(valid_atoms), sp + 2, ep);\n \t\tcp = ep + 1;\n \n \t\tif (skip_prefix(used_atoms[at].name, \"color:\", &color))\n@@ -2139,7 +2141,9 @@ void format_ref_array_item(struct ref_array_item *info,\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   parse_ref_filter_atom(format, valid_atoms,\n+\t\t\t\t\t\t\t ARRAY_SIZE(valid_atoms),\n+\t\t\t\t\t\t\t sp + 2, ep),\n \t\t\t\t   &atomv);\n \t\tatomv->handler(atomv, &state);\n \t}\n@@ -2187,7 +2191,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_atoms,\n+\t\t\t\t     ARRAY_SIZE(valid_atoms), 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/450\n"},{"id":"336238","messageId":"01020160db067b4f-60d6012f-7cb8-4ba2-891f-1d1ed5bb5786-000000@eu-west-1.amazonses.com","threadId":"47573","inReplyTo":"01020160db0679c9-799a0bc4-b6d1-43e2-ad3b-80be4e4c55e9-000000@eu-west-1.amazonses.com","subject":"[PATCH 07/20] cat-file: reuse parse_ref_filter_atom","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-01-09T13:05:23Z","receivedAt":"2018-01-09T13:06:09Z","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 reducing of expand_atom_into_fields function.\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 | 73 +++++++++++++++++++++++++++++++++++++-----------------------\n 1 file changed, 45 insertions(+), 28 deletions(-)\n\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 98bb10185ae96..2bd9a8fc4e39c 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_atoms;\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_atoms[] = {\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@@ -392,6 +411,25 @@ 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 expand_atom_into_fields(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@@ -458,6 +496,8 @@ static int parse_ref_filter_atom(const struct ref_format *format,\n \t\tneed_tagged = 1;\n \tif (!strcmp(valid_atoms[i].name, \"symref\"))\n \t\tneed_symref = 1;\n+\tif (cat_file_info)\n+\t\texpand_atom_into_fields(atom, atom_len, cat_file_info);\n \treturn at;\n }\n \n@@ -693,31 +733,6 @@ static const char *find_next(const char *cp)\n \treturn NULL;\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_into_fields(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  * Make sure the format string is well formed, and parse out\n  * the used atoms.\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,9 +752,10 @@ 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\texpand_atom_into_fields(sp + 2, ep - sp - 2,\n-\t\t\t\t\t\tformat->cat_file_data);\n-\t\telse\n+\t\t{\n+\t\t\tat = parse_ref_filter_atom(format, valid_cat_file_atoms,\n+\t\t\t\t\t\t   ARRAY_SIZE(valid_cat_file_atoms), sp + 2, ep);\n+\t\t} else\n \t\t{\n \t\t\tat = parse_ref_filter_atom(format, valid_atoms,\n \t\t\t\t\t\t   ARRAY_SIZE(valid_atoms), sp + 2, ep);\n\n--\nhttps://github.com/git/git/pull/450\n"},{"id":"336239","messageId":"01020160db067af3-3108a276-f04a-4eb0-8434-5006f6596f56-000000@eu-west-1.amazonses.com","threadId":"47573","inReplyTo":"01020160db0679c9-799a0bc4-b6d1-43e2-ad3b-80be4e4c55e9-000000@eu-west-1.amazonses.com","subject":"[PATCH 12/20] cat-file: rename variable in ref-filter","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-01-09T13:05:23Z","receivedAt":"2018-01-09T13:06:11Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Rename variable for easier reading.\nIt points not to values, but to arrays.\nAdded \"s\" ending so that it could be obvious.\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 | 16 ++++++++--------\n ref-filter.h |  2 +-\n 2 files changed, 9 insertions(+), 9 deletions(-)\n\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 1b8c8787190a9..56d2687e07df9 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -1418,7 +1418,7 @@ static void need_object(struct ref_array_item *ref) {\n \t\tdie(_(\"parse_object_buffer failed on %s for %s\"),\n \t\t    oid_to_hex(&ref->objectname), ref->refname);\n \n-\tgrab_values(ref->value, 0, obj, buf, size);\n+\tgrab_values(ref->values, 0, obj, buf, size);\n \tif (!eaten)\n \t\tfree(buf);\n \n@@ -1448,7 +1448,7 @@ static void need_object(struct ref_array_item *ref) {\n \tif (!obj)\n \t\tdie(_(\"parse_object_buffer failed on %s for %s\"),\n \t\t    oid_to_hex(tagged), ref->refname);\n-\tgrab_values(ref->value, 1, obj, buf, size);\n+\tgrab_values(ref->values, 1, obj, buf, size);\n \tif (!eaten)\n \t\tfree(buf);\n }\n@@ -1460,7 +1460,7 @@ static void populate_value(struct ref_array_item *ref)\n {\n \tint i;\n \n-\tref->value = xcalloc(used_atom_cnt, sizeof(struct atom_value));\n+\tref->values = xcalloc(used_atom_cnt, sizeof(struct atom_value));\n \n \tif (need_symref && (ref->flag & REF_ISSYMREF) && !ref->symref) {\n \t\tref->symref = resolve_refdup(ref->refname, RESOLVE_REF_READING,\n@@ -1473,7 +1473,7 @@ static void populate_value(struct ref_array_item *ref)\n \tfor (i = 0; i < used_atom_cnt; i++) {\n \t\tstruct used_atom *atom = &used_atoms[i];\n \t\tconst char *name = used_atoms[i].name;\n-\t\tstruct atom_value *v = &ref->value[i];\n+\t\tstruct atom_value *v = &ref->values[i];\n \t\tint deref = 0;\n \t\tconst char *refname;\n \t\tstruct branch *branch = NULL;\n@@ -1571,7 +1571,7 @@ static void populate_value(struct ref_array_item *ref)\n \t}\n \n \tfor (i = 0; i < used_atom_cnt; i++) {\n-\t\tstruct atom_value *v = &ref->value[i];\n+\t\tstruct atom_value *v = &ref->values[i];\n \t\tif (v->s == NULL) {\n \t\t\tneed_object(ref);\n \t\t\tbreak;\n@@ -1586,11 +1586,11 @@ static void populate_value(struct ref_array_item *ref)\n  */\n static void get_ref_atom_value(struct ref_array_item *ref, int atom, struct atom_value **v)\n {\n-\tif (!ref->value) {\n+\tif (!ref->values) {\n \t\tpopulate_value(ref);\n-\t\tfill_missing_values(ref->value);\n+\t\tfill_missing_values(ref->values);\n \t}\n-\t*v = &ref->value[atom];\n+\t*v = &ref->values[atom];\n }\n \n /*\ndiff --git a/ref-filter.h b/ref-filter.h\nindex 590a60ffe034d..de3fd3263ac64 100644\n--- a/ref-filter.h\n+++ b/ref-filter.h\n@@ -39,7 +39,7 @@ struct ref_array_item {\n \tunsigned int kind;\n \tconst char *symref;\n \tstruct commit *commit;\n-\tstruct atom_value *value;\n+\tstruct atom_value *values;\n \tchar refname[FLEX_ARRAY];\n };\n \n\n--\nhttps://github.com/git/git/pull/450\n"},{"id":"336240","messageId":"01020160db067b66-c22a78cb-5297-426b-9b11-a20a8c27f74e-000000@eu-west-1.amazonses.com","threadId":"47573","inReplyTo":"01020160db0679c9-799a0bc4-b6d1-43e2-ad3b-80be4e4c55e9-000000@eu-west-1.amazonses.com","subject":"[PATCH 06/20] cat-file: start migrating to ref-filter","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-01-09T13:05:23Z","receivedAt":"2018-01-09T13:06:13Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Start moving all formatting stuff from cat-file to ref-filter.\nStart from simple moving, it would be integrated into\nall ref-filter processes 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 |  5 ++---\n ref-filter.c       | 42 +++++++++++++++++++++++++++++++++++++-----\n ref-filter.h       |  6 ++++++\n 3 files changed, 45 insertions(+), 8 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 7fd5b960ad698..0a3f4a47bf1ae 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -420,9 +420,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 2d6e81fe1ab00..98bb10185ae96 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -693,6 +693,31 @@ static const char *find_next(const char *cp)\n \treturn NULL;\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_into_fields(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  * Make sure the format string is well formed, and parse out\n  * the used atoms.\n@@ -709,12 +734,19 @@ 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_atoms,\n-\t\t\t\t\t   ARRAY_SIZE(valid_atoms), sp + 2, ep);\n-\t\tcp = ep + 1;\n \n-\t\tif (skip_prefix(used_atoms[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\texpand_atom_into_fields(sp + 2, ep - sp - 2,\n+\t\t\t\t\t\tformat->cat_file_data);\n+\t\telse\n+\t\t{\n+\t\t\tat = parse_ref_filter_atom(format, valid_atoms,\n+\t\t\t\t\t\t   ARRAY_SIZE(valid_atoms), sp + 2, ep);\n+\t\t\tif (skip_prefix(used_atoms[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 16d00e4b1bded..97169548939cd 100644\n--- a/ref-filter.h\n+++ b/ref-filter.h\n@@ -119,6 +119,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/450\n"},{"id":"336241","messageId":"01020160db067a62-874402f0-c7c0-4fb4-91c3-ac644fcf9a1f-000000@eu-west-1.amazonses.com","threadId":"47573","inReplyTo":"01020160db0679c9-799a0bc4-b6d1-43e2-ad3b-80be4e4c55e9-000000@eu-west-1.amazonses.com","subject":"[PATCH 02/20] cat-file: reuse struct ref_format","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-01-09T13:05:23Z","receivedAt":"2018-01-09T13:06:15Z","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 | 16 +++++++++-------\n 1 file changed, 9 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex f783b39b9bd5c..7655a9a726773 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@@ -353,7 +354,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@@ -446,8 +447,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@@ -456,7 +457,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@@ -548,7 +549,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@@ -557,7 +558,8 @@ 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 ref_format format = REF_FORMAT_INIT;\n+\tstruct batch_options batch = {&format};\n \tint unknown_type = 0;\n \n \tconst struct option options[] = {\n\n--\nhttps://github.com/git/git/pull/450\n"},{"id":"336242","messageId":"01020160db067c88-f01ed048-da02-43a7-8b61-db62027911bf-000000@eu-west-1.amazonses.com","threadId":"47573","inReplyTo":"01020160db0679c9-799a0bc4-b6d1-43e2-ad3b-80be4e4c55e9-000000@eu-west-1.amazonses.com","subject":"[PATCH 18/20] cat-file: add split_on_whitespace flag","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-01-09T13:05:23Z","receivedAt":"2018-01-09T13:06:21Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Add flag to ref_format struct so that we could pass needed info\nto 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 | 1 +\n ref-filter.c       | 4 ++--\n ref-filter.h       | 1 +\n 3 files changed, 4 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 289912ab1f858..5aac10b9808ff 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -394,6 +394,7 @@ 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->split_on_whitespace = &data.split_on_whitespace;\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 4259c9b9cd767..ee27edb2dad56 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -494,8 +494,8 @@ static int parse_ref_filter_atom(const struct ref_format *format,\n \t\tneed_tagged = 1;\n \tif (!strcmp(valid_atoms[i].name, \"symref\"))\n \t\tneed_symref = 1;\n-\tif (is_cat && !strcmp(valid_atoms[i].name, \"rest\"))\n-\t\tcat_file_info->split_on_whitespace = 1;\n+\tif (!strcmp(valid_atoms[i].name, \"rest\"))\n+\t\t*format->split_on_whitespace = 1;\n \treturn at;\n }\n \ndiff --git a/ref-filter.h b/ref-filter.h\nindex 5ba4724a472f6..3228661414623 100644\n--- a/ref-filter.h\n+++ b/ref-filter.h\n@@ -127,6 +127,7 @@ struct ref_format {\n \t */\n \tstruct expand_data *cat_file_data;\n \tint is_cat;\n+\tint *split_on_whitespace;\n };\n \n #define REF_FORMAT_INIT { NULL, 0, -1 }\n\n--\nhttps://github.com/git/git/pull/450\n"},{"id":"336243","messageId":"01020160db067baa-645d1cd7-0fa5-404e-b3f0-afba7dac7d18-000000@eu-west-1.amazonses.com","threadId":"47573","inReplyTo":"01020160db0679c9-799a0bc4-b6d1-43e2-ad3b-80be4e4c55e9-000000@eu-west-1.amazonses.com","subject":"[PATCH 13/20] cat-file: start use ref_array_item struct","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-01-09T13:05:23Z","receivedAt":"2018-01-09T13:06:23Z","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 | 30 +++++++++++++++++++-----------\n ref-filter.h       |  5 +++++\n 2 files changed, 24 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 1f331559e55c7..1c92194faaede 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -183,26 +183,26 @@ 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\tstrbuf_addstr(sb, data->rest);\n+\t\tstrbuf_addstr(sb, item->rest);\n \telse 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@@ -210,7 +210,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@@ -282,6 +282,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;\n \n \tif (!data->skip_object_info &&\n \t    sha1_object_info_extended(data->oid.hash, &data->info,\n@@ -292,7 +293,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 de3fd3263ac64..28774e8e0f771 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 *values;\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/450\n"},{"id":"336244","messageId":"01020160db067c89-c76828dd-d98c-45c6-8de1-2c9d7fc61841-000000@eu-west-1.amazonses.com","threadId":"47573","inReplyTo":"01020160db0679c9-799a0bc4-b6d1-43e2-ad3b-80be4e4c55e9-000000@eu-west-1.amazonses.com","subject":"[PATCH 17/20] cat-file: add is_cat flag in ref-filter","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-01-09T13:05:23Z","receivedAt":"2018-01-09T13:06:24Z","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 e11dbf88e386c..289912ab1f858 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -393,6 +393,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 112336edbe871..4259c9b9cd767 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -101,6 +101,7 @@ static struct used_atom {\n } *used_atoms;\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_atoms[i].name, \"symref\"))\n \t\tneed_symref = 1;\n-\tif (cat_file_info && !strcmp(valid_atoms[i].name, \"rest\"))\n+\tif (is_cat && !strcmp(valid_atoms[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{\n \t\t\tat = parse_ref_filter_atom(format, valid_cat_file_atoms,\n \t\t\t\t\t\t   ARRAY_SIZE(valid_cat_file_atoms), sp + 2, ep);\n@@ -1466,7 +1468,7 @@ int populate_value(struct ref_array_item *ref)\n \t\t\tref->symref = \"\";\n \t}\n \n-\tif (cat_file_info) {\n+\tif (is_cat) {\n \t\tif (!cat_file_info->skip_object_info &&\n \t\t    sha1_object_info_extended(ref->objectname.hash, &cat_file_info->info,\n \t\t\t\t\t      OBJECT_INFO_LOOKUP_REPLACE) < 0) {\ndiff --git a/ref-filter.h b/ref-filter.h\nindex 9e4444cf3ef9a..5ba4724a472f6 100644\n--- a/ref-filter.h\n+++ b/ref-filter.h\n@@ -126,6 +126,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/450\n"},{"id":"336245","messageId":"01020160db067c7c-74dd1ef6-598b-4010-bc2c-4315fd3125ee-000000@eu-west-1.amazonses.com","threadId":"47573","inReplyTo":"01020160db0679c9-799a0bc4-b6d1-43e2-ad3b-80be4e4c55e9-000000@eu-west-1.amazonses.com","subject":"[PATCH 16/20] cat-file: get rid of expand_atom_into_fields","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-01-09T13:05:23Z","receivedAt":"2018-01-09T13:06:28Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Remove expand_atom_into_fields function 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 7df6d7e3d6511..112336edbe871 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_atoms[] = {\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 expand_atom_into_fields(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_atoms[i].name, \"symref\"))\n \t\tneed_symref = 1;\n-\tif (cat_file_info)\n-\t\texpand_atom_into_fields(atom, atom_len, cat_file_info);\n+\tif (cat_file_info && !strcmp(valid_atoms[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/450\n"},{"id":"336246","messageId":"01020160db067bde-7f500636-b80e-4099-a84e-2613126c9aa1-000000@eu-west-1.amazonses.com","threadId":"47573","inReplyTo":"01020160db0679c9-799a0bc4-b6d1-43e2-ad3b-80be4e4c55e9-000000@eu-west-1.amazonses.com","subject":"[PATCH 03/20] cat-file: rename variables in ref-filter","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-01-09T13:05:23Z","receivedAt":"2018-01-09T13:06:34Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Rename some variables for easier reading.\nThey point not to values, but to arrays.\nAdded \"s\" ending so that it could be obvious.\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 | 60 ++++++++++++++++++++++++++++++------------------------------\n 1 file changed, 30 insertions(+), 30 deletions(-)\n\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 3f9161707e66b..1426f0c28bce7 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -98,7 +98,7 @@ static struct used_atom {\n \t\tstruct refname_atom refname;\n \t\tchar *head;\n \t} u;\n-} *used_atom;\n+} *used_atoms;\n static int used_atom_cnt, need_tagged, need_symref;\n \n static void color_atom_parser(const struct ref_format *format, struct used_atom *atom, const char *color_value)\n@@ -325,11 +325,11 @@ 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-} valid_atom[] = {\n+} valid_atoms[] = {\n \t{ \"refname\" , FIELD_STR, refname_atom_parser },\n \t{ \"objecttype\" },\n \t{ \"objectsize\", FIELD_ULONG },\n@@ -410,38 +410,38 @@ static int parse_ref_filter_atom(const struct ref_format *format,\n \n \t/* Do we have the atom already used elsewhere? */\n \tfor (i = 0; i < used_atom_cnt; i++) {\n-\t\tint len = strlen(used_atom[i].name);\n-\t\tif (len == ep - atom && !memcmp(used_atom[i].name, atom, len))\n+\t\tint len = strlen(used_atoms[i].name);\n+\t\tif (len == ep - atom && !memcmp(used_atoms[i].name, atom, len))\n \t\t\treturn i;\n \t}\n \n \t/*\n \t * If the atom name has a colon, strip it and everything after\n \t * it off - it specifies the format for this entry, and\n-\t * shouldn't be used for checking against the valid_atom\n+\t * shouldn't be used for checking against the valid_atoms\n \t * table.\n \t */\n \targ = memchr(sp, ':', ep - sp);\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-\t\tint len = strlen(valid_atom[i].name);\n-\t\tif (len == atom_len && !memcmp(valid_atom[i].name, sp, len))\n+\tfor (i = 0; i < ARRAY_SIZE(valid_atoms); i++) {\n+\t\tint len = strlen(valid_atoms[i].name);\n+\t\tif (len == atom_len && !memcmp(valid_atoms[i].name, sp, len))\n \t\t\tbreak;\n \t}\n \n-\tif (ARRAY_SIZE(valid_atom) <= i)\n+\tif (ARRAY_SIZE(valid_atoms) <= i)\n \t\tdie(_(\"unknown field name: %.*s\"), (int)(ep-atom), atom);\n \n \t/* Add it in, including the deref prefix */\n \tat = used_atom_cnt;\n \tused_atom_cnt++;\n-\tREALLOC_ARRAY(used_atom, used_atom_cnt);\n-\tused_atom[at].name = xmemdupz(atom, ep - atom);\n-\tused_atom[at].type = valid_atom[i].cmp_type;\n+\tREALLOC_ARRAY(used_atoms, used_atom_cnt);\n+\tused_atoms[at].name = xmemdupz(atom, ep - atom);\n+\tused_atoms[at].type = valid_atoms[i].cmp_type;\n \tif (arg) {\n-\t\targ = used_atom[at].name + (arg - atom) + 1;\n+\t\targ = used_atoms[at].name + (arg - atom) + 1;\n \t\tif (!*arg) {\n \t\t\t/*\n \t\t\t * Treat empty sub-arguments list as NULL (i.e.,\n@@ -450,12 +450,12 @@ static int parse_ref_filter_atom(const struct ref_format *format,\n \t\t\targ = NULL;\n \t\t}\n \t}\n-\tmemset(&used_atom[at].u, 0, sizeof(used_atom[at].u));\n-\tif (valid_atom[i].parser)\n-\t\tvalid_atom[i].parser(format, &used_atom[at], arg);\n+\tmemset(&used_atoms[at].u, 0, sizeof(used_atoms[at].u));\n+\tif (valid_atoms[i].parser)\n+\t\tvalid_atoms[i].parser(format, &used_atoms[at], arg);\n \tif (*atom == '*')\n \t\tneed_tagged = 1;\n-\tif (!strcmp(valid_atom[i].name, \"symref\"))\n+\tif (!strcmp(valid_atoms[i].name, \"symref\"))\n \t\tneed_symref = 1;\n \treturn at;\n }\n@@ -711,7 +711,7 @@ int verify_ref_format(struct ref_format *format)\n \t\tat = parse_ref_filter_atom(format, sp + 2, ep);\n \t\tcp = ep + 1;\n \n-\t\tif (skip_prefix(used_atom[at].name, \"color:\", &color))\n+\t\tif (skip_prefix(used_atoms[at].name, \"color:\", &color))\n \t\t\tformat->need_color_reset_at_eol = !!strcmp(color, \"reset\");\n \t}\n \tif (format->need_color_reset_at_eol && !want_color(format->use_color))\n@@ -762,7 +762,7 @@ static void grab_common_values(struct atom_value *val, int deref, struct object\n \tint i;\n \n \tfor (i = 0; i < used_atom_cnt; i++) {\n-\t\tconst char *name = used_atom[i].name;\n+\t\tconst char *name = used_atoms[i].name;\n \t\tstruct atom_value *v = &val[i];\n \t\tif (!!deref != (*name == '*'))\n \t\t\tcontinue;\n@@ -775,7 +775,7 @@ static void grab_common_values(struct atom_value *val, int deref, struct object\n \t\t\tv->s = xstrfmt(\"%lu\", sz);\n \t\t}\n \t\telse if (deref)\n-\t\t\tgrab_objectname(name, obj->oid.hash, v, &used_atom[i]);\n+\t\t\tgrab_objectname(name, obj->oid.hash, v, &used_atoms[i]);\n \t}\n }\n \n@@ -786,7 +786,7 @@ static void grab_tag_values(struct atom_value *val, int deref, struct object *ob\n \tstruct tag *tag = (struct tag *) obj;\n \n \tfor (i = 0; i < used_atom_cnt; i++) {\n-\t\tconst char *name = used_atom[i].name;\n+\t\tconst char *name = used_atoms[i].name;\n \t\tstruct atom_value *v = &val[i];\n \t\tif (!!deref != (*name == '*'))\n \t\t\tcontinue;\n@@ -808,7 +808,7 @@ static void grab_commit_values(struct atom_value *val, int deref, struct object\n \tstruct commit *commit = (struct commit *) obj;\n \n \tfor (i = 0; i < used_atom_cnt; i++) {\n-\t\tconst char *name = used_atom[i].name;\n+\t\tconst char *name = used_atoms[i].name;\n \t\tstruct atom_value *v = &val[i];\n \t\tif (!!deref != (*name == '*'))\n \t\t\tcontinue;\n@@ -938,7 +938,7 @@ static void grab_person(const char *who, struct atom_value *val, int deref, stru\n \tconst char *wholine = NULL;\n \n \tfor (i = 0; i < used_atom_cnt; i++) {\n-\t\tconst char *name = used_atom[i].name;\n+\t\tconst char *name = used_atoms[i].name;\n \t\tstruct atom_value *v = &val[i];\n \t\tif (!!deref != (*name == '*'))\n \t\t\tcontinue;\n@@ -976,7 +976,7 @@ static void grab_person(const char *who, struct atom_value *val, int deref, stru\n \tif (!wholine)\n \t\treturn;\n \tfor (i = 0; i < used_atom_cnt; i++) {\n-\t\tconst char *name = used_atom[i].name;\n+\t\tconst char *name = used_atoms[i].name;\n \t\tstruct atom_value *v = &val[i];\n \t\tif (!!deref != (*name == '*'))\n \t\t\tcontinue;\n@@ -1066,7 +1066,7 @@ static void grab_sub_body_contents(struct atom_value *val, int deref, struct obj\n \tunsigned long sublen = 0, bodylen = 0, nonsiglen = 0, siglen = 0;\n \n \tfor (i = 0; i < used_atom_cnt; i++) {\n-\t\tstruct used_atom *atom = &used_atom[i];\n+\t\tstruct used_atom *atom = &used_atoms[i];\n \t\tconst char *name = atom->name;\n \t\tstruct atom_value *v = &val[i];\n \t\tif (!!deref != (*name == '*'))\n@@ -1127,7 +1127,7 @@ static void fill_missing_values(struct atom_value *val)\n \n /*\n  * val is a list of atom_value to hold returned values.  Extract\n- * the values for atoms in used_atom array out of (obj, buf, sz).\n+ * the values for atoms in used_atoms array out of (obj, buf, sz).\n  * when deref is false, (obj, buf, sz) is the object that is\n  * pointed at by the ref itself; otherwise it is the object the\n  * ref (which is a tag) refers to.\n@@ -1376,8 +1376,8 @@ static void populate_value(struct ref_array_item *ref)\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];\n-\t\tconst char *name = used_atom[i].name;\n+\t\tstruct used_atom *atom = &used_atoms[i];\n+\t\tconst char *name = used_atoms[i].name;\n \t\tstruct atom_value *v = &ref->value[i];\n \t\tint deref = 0;\n \t\tconst char *refname;\n@@ -2059,7 +2059,7 @@ static int cmp_ref_sorting(struct ref_sorting *s, struct ref_array_item *a, stru\n {\n \tstruct atom_value *va, *vb;\n \tint cmp;\n-\tcmp_type cmp_type = used_atom[s->atom].type;\n+\tcmp_type cmp_type = used_atoms[s->atom].type;\n \tint (*cmp_fn)(const char *, const char *);\n \n \tget_ref_atom_value(a, s->atom, &va);\n\n--\nhttps://github.com/git/git/pull/450\n"},{"id":"336247","messageId":"01020160db067add-6a32c398-0438-4bd1-8622-d3870adf9167-000000@eu-west-1.amazonses.com","threadId":"47573","inReplyTo":"01020160db0679c9-799a0bc4-b6d1-43e2-ad3b-80be4e4c55e9-000000@eu-west-1.amazonses.com","subject":"[PATCH 08/20] cat-file: remove unused code","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-01-09T13:05:23Z","receivedAt":"2018-01-09T13:06:40Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"No further need in mark_query parameter.\nAll logic related to expand_atom_into_fields is not needed here also,\nwe are doing that in 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 | 25 +------------------------\n ref-filter.h       |  6 ------\n 2 files changed, 1 insertion(+), 30 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 0a3f4a47bf1ae..9055fa3a8b0ae 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 expand_atom_into_fields(struct strbuf *sb, const char *atom, int len,\n-\t\t\tstruct 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@@ -232,11 +213,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\texpand_atom_into_fields(sb, 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 \ndiff --git a/ref-filter.h b/ref-filter.h\nindex 97169548939cd..590a60ffe034d 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\n--\nhttps://github.com/git/git/pull/450\n"},{"id":"336248","messageId":"01020160db0679c9-799a0bc4-b6d1-43e2-ad3b-80be4e4c55e9-000000@eu-west-1.amazonses.com","threadId":"47573","inReplyTo":null,"subject":"[PATCH 01/20] cat-file: split expand_atom into 2 functions","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-01-09T13:05:22Z","receivedAt":"2018-01-09T13:06:43Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Split expand_atom function into 2 different functions,\nexpand_atom_into_fields prepares variable for further filling,\n(new) expand_atom creates resulting string.\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 | 73 +++++++++++++++++++++++++++++-------------------------\n 1 file changed, 39 insertions(+), 34 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex f5fa4fd75af26..f783b39b9bd5c 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -217,47 +217,49 @@ 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 expand_atom_into_fields(struct strbuf *sb, const char *atom, int len,\n+\t\t\tstruct 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} else if (is_atom(\"deltabase\", atom, len))\n+\t\tstrbuf_addstr(sb, oid_to_hex(&data->delta_base_oid));\n+\telse\n \t\tdie(\"unknown format element: %.*s\", len, atom);\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@@ -265,7 +267,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\texpand_atom_into_fields(sb, 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/450\n"},{"id":"336249","messageId":"01020160db067ae4-79bd5ef7-3402-4333-93c1-c9ae8059680c-000000@eu-west-1.amazonses.com","threadId":"47573","inReplyTo":"01020160db0679c9-799a0bc4-b6d1-43e2-ad3b-80be4e4c55e9-000000@eu-west-1.amazonses.com","subject":"[PATCH 05/20] cat-file: move struct expand_data into ref-filter","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-01-09T13:05:23Z","receivedAt":"2018-01-09T13:06:45Z","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 7655a9a726773..7fd5b960ad698 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 0d98342b34319..16d00e4b1bded 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/450\n"},{"id":"336321","messageId":"xmqqtvvu3d0a.fsf@gitster.mtv.corp.google.com","threadId":"47573","inReplyTo":"01020160db067bde-7f500636-b80e-4099-a84e-2613126c9aa1-000000@eu-west-1.amazonses.com","subject":"Re: [PATCH 03/20] cat-file: rename variables in ref-filter","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-01-09T22:04:21Z","receivedAt":"2018-01-09T22:04:28Z","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> Rename some variables for easier reading.\n> They point not to values, but to arrays.\n\nOnce the code is written and people start to build on top, a change\nlike this is not worth the code churn, especially because there are\ntwo equally valid schools of naming convention.\n\n - When you have an array, each of whose 20 slots holds a single\n   dosh, I would prefer to call the array dosh[20], not doshes[20],\n   so that I can refer to the seventh dosh as \"dosh[7]\".\n\n - If you more often refer to the array as a whole (than you refer\n   to individual elements) and want to stress the fact that the\n   array holds multiple elements in it, I can understand that you\n   may be tempted to call the whole array \"doshes[]\".\n\nSo please drop this and other \"rename variables\" patches from the\nseries.\n\n\n"},{"id":"336322","messageId":"xmqqpo6i3cg0.fsf@gitster.mtv.corp.google.com","threadId":"47573","inReplyTo":"01020160db067ae8-81d31cf2-0f69-4f36-9de8-27e9716d2f4b-000000@eu-west-1.amazonses.com","subject":"Re: [PATCH 04/20] cat-file: make valid_atoms as a function parameter","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-01-09T22:16:31Z","receivedAt":"2018-01-09T22:16:40Z","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> Make valid_atoms as a function parameter,\n> there could be another variable further.\n> Need that for further reusing of formatting logic in cat-file.c.\n>\n> Signed-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\n> Mentored-by: Christian Couder <christian.couder@gmail.com>\n> Mentored by: Jeff King <peff@peff.net>\n> ---\n>  ref-filter.c | 15 ++++++++++-----\n>  1 file changed, 10 insertions(+), 5 deletions(-)\n\nPlease be a bit more careful about your title.  This change does not\nseem to have anything to do with \"cat-file\".\n\nI was not sure what you meant by \"make X as a function parameter\"\nafter reading the proposed log message twice, but I am guessing that\nyou are allowing these functions to operate on not just the global\nsingleton but a different instance of array.  \n\nI also suspect that this step may make the references to the\nvalid_atom[] array somewhat inconsistent in that the functions that\nare touched by this patch would refer to the passed-in array while\nthe remainder of the existing code still works on the global\nsingleton.  For example, parse_ref_filter_atom() is called by\nverify_ref_format(), but this patch does not make _it_ take the\narray as a parameter, and instead uses the global singleton, so\nanybody who wants to use verify_ref_format() with different\nvalid_atom[] are SOL.  I am not saying that this inconsistency will\nbe a problem, but that the patch (including the proposed log\nmessage) does not explain why it is not---and it should.\n\nThanks.\n\n> diff --git a/ref-filter.c b/ref-filter.c\n> index 1426f0c28bce7..2d6e81fe1ab00 100644\n> --- a/ref-filter.c\n> +++ b/ref-filter.c\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_atoms, 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_atoms); i++) {\n> +\tfor (i = 0; i < n_atoms; i++) {\n>  \t\tint len = strlen(valid_atoms[i].name);\n>  \t\tif (len == atom_len && !memcmp(valid_atoms[i].name, sp, len))\n>  \t\t\tbreak;\n>  \t}\n>  \n> -\tif (ARRAY_SIZE(valid_atoms) <= 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_atoms,\n> +\t\t\t\t\t   ARRAY_SIZE(valid_atoms), sp + 2, ep);\n>  \t\tcp = ep + 1;\n>  \n>  \t\tif (skip_prefix(used_atoms[at].name, \"color:\", &color))\n> @@ -2139,7 +2141,9 @@ void format_ref_array_item(struct ref_array_item *info,\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   parse_ref_filter_atom(format, valid_atoms,\n> +\t\t\t\t\t\t\t ARRAY_SIZE(valid_atoms),\n> +\t\t\t\t\t\t\t sp + 2, ep),\n>  \t\t\t\t   &atomv);\n>  \t\tatomv->handler(atomv, &state);\n>  \t}\n> @@ -2187,7 +2191,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_atoms,\n> +\t\t\t\t     ARRAY_SIZE(valid_atoms), atom, end);\n>  }\n>  \n>  /*  If no sorting option is given, use refname to sort as default */\n>\n> --\n> https://github.com/git/git/pull/450\n"},{"id":"336329","messageId":"xmqqh8ru38y2.fsf@gitster.mtv.corp.google.com","threadId":"47573","inReplyTo":"01020160db067b4f-60d6012f-7cb8-4ba2-891f-1d1ed5bb5786-000000@eu-west-1.amazonses.com","subject":"Re: [PATCH 07/20] cat-file: reuse parse_ref_filter_atom","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-01-09T23:32:05Z","receivedAt":"2018-01-09T23:32:12Z","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> +static int is_atom(const char *atom, const char *s, int slen)\n> +{\n> +...\n> +}\n> +\n> +static void expand_atom_into_fields(const char *atom, int len,\n> +\t\t\t\t    struct expand_data *data)\n> +{\n> +...\n> +}\n> ...\n> -static int is_atom(const char *atom, const char *s, int slen)\n> -{\n> -...\n> -}\n> -\n> -static void expand_atom_into_fields(const char *atom, int len,\n> -\t\t\t\t    struct expand_data *data)\n> -{\n> -...\n> -}\n> -\n>  /*\n>   * Make sure the format string is well formed, and parse out\n>   * the used atoms.\n\nThere is no need to move these in this step if the previous step\nplanned ahead well, and that is something you can correct by\npretending to be perfect with \"rebase -i\" ;-) That also will help\nreduce reviewers' load.\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,9 +752,10 @@ 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\texpand_atom_into_fields(sp + 2, ep - sp - 2,\n> -\t\t\t\t\t\tformat->cat_file_data);\n> -\t\telse\n> +\t\t{\n> +\t\t\tat = parse_ref_filter_atom(format, valid_cat_file_atoms,\n> +\t\t\t\t\t\t   ARRAY_SIZE(valid_cat_file_atoms), sp + 2, ep);\n> +\t\t} else\n>  \t\t{\n>  \t\t\tat = parse_ref_filter_atom(format, valid_atoms,\n>  \t\t\t\t\t\t   ARRAY_SIZE(valid_atoms), sp + 2, ep);\n\nif/else with bodies that are compound statements are formatted like\nso:\n\n\tif (condition) {\n\t\tdo this;\n\t} else {\n\t\tdo that;\n\t\tdo that, too;\n\t}\n\n"},{"id":"336340","messageId":"CAL21BmnBcYD1ws+2e18o-X4awzFteMkZ0fGYtoJyYdB51JqdzQ@mail.gmail.com","threadId":"47573","inReplyTo":"xmqqtvvu3d0a.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH 03/20] cat-file: rename variables in ref-filter","fromName":"Оля Тележная","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-01-10T07:07:09Z","receivedAt":"2018-01-10T07:07:15Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"2018-01-10 1:04 GMT+03:00 Junio C Hamano <gitster@pobox.com>:\n> Olga Telezhnaya <olyatelezhnaya@gmail.com> writes:\n>\n>> Rename some variables for easier reading.\n>> They point not to values, but to arrays.\n>\n> Once the code is written and people start to build on top, a change\n> like this is not worth the code churn, especially because there are\n> two equally valid schools of naming convention.\n>\n>  - When you have an array, each of whose 20 slots holds a single\n>    dosh, I would prefer to call the array dosh[20], not doshes[20],\n>    so that I can refer to the seventh dosh as \"dosh[7]\".\n>\n>  - If you more often refer to the array as a whole (than you refer\n>    to individual elements) and want to stress the fact that the\n>    array holds multiple elements in it, I can understand that you\n>    may be tempted to call the whole array \"doshes[]\".\n>\n> So please drop this and other \"rename variables\" patches from the\n> series.\n>\n>\n\nOK, I will revert that. I have done this because it's hard for me to\nkeep in mind that it's not just a simple pointer to a single value,\nand I tried to make the code more intuitive.\n"}]}