{"thread":{"id":"48514","subject":"[PATCH RFC v2 4/4] ref-filter: add deltabase formatting option","startedAt":"2018-05-18T09:11:03Z","lastAt":"2018-05-18T09:11:41Z","messageCount":4,"participants":["Olga Telezhnaya"],"isPatch":true,"patchVersion":2,"patchTotal":4},"messages":[{"id":"347972","messageId":"010201637254ca34-c7632c6b-dcab-439f-a2fb-cf270a881534-000000@eu-west-1.amazonses.com","threadId":"48514","inReplyTo":"010201637254c969-a346030e-0b75-41ad-8ef3-2ac7e04ba4fb-000000@eu-west-1.amazonses.com","subject":"[PATCH RFC v2 4/4] ref-filter: add deltabase formatting option","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-05-18T08:19:09Z","receivedAt":"2018-05-18T09:11:03Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Add %(deltabase) support. It is still not working for deref:\nI am thinking how to support it in a more elegant way.\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\n---\n ref-filter.c | 12 ++++++++++++\n 1 file changed, 12 insertions(+)\n\ndiff --git a/ref-filter.c b/ref-filter.c\nindex c00de58455301..989ccdb356a32 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -276,6 +276,14 @@ static int objecttype_atom_parser(const struct ref_format *format, struct used_a\n \treturn 0;\n }\n \n+static int deltabase_atom_parser(const struct ref_format *format, struct used_atom *atom,\n+\t\t\t\t  const char *arg, struct strbuf *unused_err)\n+{\n+\toi_data.use_data = 1;\n+\toi_data.info.delta_base_sha1 = oi_data.delta_base_oid.hash;\n+\treturn 0;\n+}\n+\n static int objectsize_atom_parser(const struct ref_format *format, struct used_atom *atom,\n \t\t\t\t  const char *arg, struct strbuf *err)\n {\n@@ -409,6 +417,7 @@ static struct {\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{ \"deltabase\", FIELD_STR, deltabase_atom_parser },\n \t{ \"tree\" },\n \t{ \"parent\" },\n \t{ \"numparent\", FIELD_ULONG },\n@@ -1572,6 +1581,9 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)\n \t\t\t\tv->s = xstrfmt(\"%lu\", oi_data.disk_size);\n \t\t\t}\n \t\t\tcontinue;\n+\t\t} else if (!deref && !strcmp(name, \"deltabase\") && oi_data.use_data) {\n+\t\t\tv->s = xstrdup(oid_to_hex(&oi_data.delta_base_oid));\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 \t\t\t\tv->s = \"*\";\n\n--\nhttps://github.com/git/git/pull/493\n"},{"id":"347973","messageId":"010201637254ca06-74d231ce-8927-4928-964c-5170b1a919f8-000000@eu-west-1.amazonses.com","threadId":"48514","inReplyTo":"010201637254c969-a346030e-0b75-41ad-8ef3-2ac7e04ba4fb-000000@eu-west-1.amazonses.com","subject":"[PATCH RFC v2 3/4] ref-filter: add tests for objectsize:disk","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-05-18T08:19:09Z","receivedAt":"2018-05-18T09:11:21Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Add tests for %(objectsize:disk) atom.\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\n---\n t/t6300-for-each-ref.sh | 2 ++\n 1 file changed, 2 insertions(+)\n\ndiff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh\nindex 295d1475bde01..570bb606045d7 100755\n--- a/t/t6300-for-each-ref.sh\n+++ b/t/t6300-for-each-ref.sh\n@@ -83,6 +83,7 @@ test_atom head push:strip=1 remotes/myfork/master\n test_atom head push:strip=-1 master\n test_atom head objecttype commit\n test_atom head objectsize 171\n+test_atom head objectsize:disk 138\n test_atom head objectname $(git rev-parse refs/heads/master)\n test_atom head objectname:short $(git rev-parse --short refs/heads/master)\n test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/master)\n@@ -124,6 +125,7 @@ test_atom tag upstream ''\n test_atom tag push ''\n test_atom tag objecttype tag\n test_atom tag objectsize 154\n+test_atom tag objectsize:disk 138\n test_atom tag objectname $(git rev-parse refs/tags/testtag)\n test_atom tag objectname:short $(git rev-parse --short refs/tags/testtag)\n test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/master)\n\n--\nhttps://github.com/git/git/pull/493\n"},{"id":"347974","messageId":"010201637254c9fc-6c6958f9-5b32-44df-abbe-8455d4ca9535-000000@eu-west-1.amazonses.com","threadId":"48514","inReplyTo":"010201637254c969-a346030e-0b75-41ad-8ef3-2ac7e04ba4fb-000000@eu-west-1.amazonses.com","subject":"[PATCH RFC v2 2/4] ref-filter: add objectsize:disk formatting option","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-05-18T08:19:09Z","receivedAt":"2018-05-18T09:11:28Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Add %(objectsize:disk) support. It is still not working for deref:\nI am thinking how to support it in a more elegant way.\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\n---\n ref-filter.c | 21 ++++++++++++++++-----\n 1 file changed, 16 insertions(+), 5 deletions(-)\n\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 4008351553391..c00de58455301 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -277,10 +277,15 @@ static int objecttype_atom_parser(const struct ref_format *format, struct used_a\n }\n \n static int objectsize_atom_parser(const struct ref_format *format, struct used_atom *atom,\n-\t\t\t\t  const char *arg, struct strbuf *unused_err)\n+\t\t\t\t  const char *arg, struct strbuf *err)\n {\n+\tif (!arg)\n+\t\toi_data.info.sizep = &oi_data.size;\n+\telse if (!strcmp(arg, \"disk\"))\n+\t\toi_data.info.disk_sizep = &oi_data.disk_size;\n+\telse\n+\t\treturn strbuf_addf_ret(err, -1, _(\"unrecognized %%(objectsize) argument: %s\"), arg);\n \toi_data.use_data = 1;\n-\toi_data.info.sizep = &oi_data.size;\n \treturn 0;\n }\n \n@@ -1557,9 +1562,15 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)\n \t\t} else if (!deref && !strcmp(name, \"objecttype\") && oi_data.use_data) {\n \t\t\tv->s = type_name(oi_data.type);\n \t\t\tcontinue;\n-\t\t} else if (!deref && !strcmp(name, \"objectsize\") && oi_data.use_data) {\n-\t\t\tv->value = oi_data.size;\n-\t\t\tv->s = xstrfmt(\"%lu\", oi_data.size);\n+\t\t} else if (!deref && starts_with(name, \"objectsize\") && oi_data.use_data) {\n+\t\t\tif (!strcmp(name, \"objectsize\")) {\n+\t\t\t\tv->value = oi_data.size;\n+\t\t\t\tv->s = xstrfmt(\"%lu\", oi_data.size);\n+\t\t\t} else {\n+\t\t\t\t/* It can be only objectsize:disk, we checked it in parser */\n+\t\t\t\tv->value = oi_data.disk_size;\n+\t\t\t\tv->s = xstrfmt(\"%lu\", oi_data.disk_size);\n+\t\t\t}\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\n--\nhttps://github.com/git/git/pull/493\n"},{"id":"347975","messageId":"010201637254c969-a346030e-0b75-41ad-8ef3-2ac7e04ba4fb-000000@eu-west-1.amazonses.com","threadId":"48514","inReplyTo":"010201635e16d282-89bdd0cd-df10-4509-bad7-fd49fd80ff2b-000000@eu-west-1.amazonses.com","subject":"[PATCH RFC v2 1/4] ref-filter: start using oid_object_info","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-05-18T08:19:09Z","receivedAt":"2018-05-18T09:11:41Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Start using oid_object_info_extended(). So, if info from this function\nis enough, we do not need to get and parse whole object (as it was before).\nIt's good for 3 reasons:\n1. Some Git commands potentially will work faster.\n2. It's much easier to add support for objectsize:disk and deltabase.\n   (I have plans to add this support further)\n3. It's easier to move formatting from cat-file command to this logic\n   (It pretends to be unified formatting logic in the end)\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\n---\n ref-filter.c | 47 +++++++++++++++++++++++++++++++++++++++++++----\n ref-filter.h | 21 +++++++++++++++++++++\n 2 files changed, 64 insertions(+), 4 deletions(-)\n\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 39e2744c949bb..4008351553391 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+static struct expand_data oi_data;\n \n /*\n  * Expand string, append it to strbuf *sb, then return error code ret.\n@@ -267,6 +268,22 @@ static int contents_atom_parser(const struct ref_format *format, struct used_ato\n \treturn 0;\n }\n \n+static int objecttype_atom_parser(const struct ref_format *format, struct used_atom *atom,\n+\t\t\t\t  const char *arg, struct strbuf *unused_err)\n+{\n+\toi_data.use_data = 1;\n+\toi_data.info.typep = &oi_data.type;\n+\treturn 0;\n+}\n+\n+static int objectsize_atom_parser(const struct ref_format *format, struct used_atom *atom,\n+\t\t\t\t  const char *arg, struct strbuf *unused_err)\n+{\n+\toi_data.use_data = 1;\n+\toi_data.info.sizep = &oi_data.size;\n+\treturn 0;\n+}\n+\n static int objectname_atom_parser(const struct ref_format *format, struct used_atom *atom,\n \t\t\t\t  const char *arg, struct strbuf *err)\n {\n@@ -383,9 +400,9 @@ static struct {\n \tint (*parser)(const struct ref_format *format, struct used_atom *atom,\n \t\t      const char *arg, struct strbuf *err);\n } valid_atom[] = {\n-\t{ \"refname\" , FIELD_STR, refname_atom_parser },\n-\t{ \"objecttype\" },\n-\t{ \"objectsize\", FIELD_ULONG },\n+\t{ \"refname\", FIELD_STR, refname_atom_parser },\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@@ -1207,7 +1224,8 @@ static void fill_missing_values(struct atom_value *val)\n  */\n static void grab_values(struct atom_value *val, int deref, struct object *obj, void *buf, unsigned long sz)\n {\n-\tgrab_common_values(val, deref, obj, buf, sz);\n+\tif (deref || !oi_data.use_data)\n+\t\tgrab_common_values(val, deref, obj, buf, sz);\n \tswitch (obj->type) {\n \tcase OBJ_TAG:\n \t\tgrab_tag_values(val, deref, obj, buf, sz);\n@@ -1536,6 +1554,13 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)\n \t\t\tcontinue;\n \t\t} else if (!deref && grab_objectname(name, &ref->objectname, v, atom)) {\n \t\t\tcontinue;\n+\t\t} else if (!deref && !strcmp(name, \"objecttype\") && oi_data.use_data) {\n+\t\t\tv->s = type_name(oi_data.type);\n+\t\t\tcontinue;\n+\t\t} else if (!deref && !strcmp(name, \"objectsize\") && oi_data.use_data) {\n+\t\t\tv->value = oi_data.size;\n+\t\t\tv->s = xstrfmt(\"%lu\", oi_data.size);\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 \t\t\t\tv->s = \"*\";\n@@ -2156,8 +2181,17 @@ static int cmp_ref_sorting(struct ref_sorting *s, struct ref_array_item *a, stru\n \tint (*cmp_fn)(const char *, const char *);\n \tstruct strbuf err = STRBUF_INIT;\n \n+\toi_data.oid = a->objectname;\n+\tif (oi_data.use_data &&\n+\t    oid_object_info_extended(&oi_data.oid, &oi_data.info, OBJECT_INFO_LOOKUP_REPLACE) < 0)\n+\t\tdie(_(\"missing object %s for %s\"), oid_to_hex(&a->objectname), a->refname);\n \tif (get_ref_atom_value(a, s->atom, &va, &err))\n \t\tdie(\"%s\", err.buf);\n+\n+\toi_data.oid = b->objectname;\n+\tif (oi_data.use_data &&\n+\t    oid_object_info_extended(&oi_data.oid, &oi_data.info, OBJECT_INFO_LOOKUP_REPLACE) < 0)\n+\t\tdie(_(\"missing object %s for %s\"), oid_to_hex(&b->objectname), b->refname);\n \tif (get_ref_atom_value(b, s->atom, &vb, &err))\n \t\tdie(\"%s\", err.buf);\n \tstrbuf_release(&err);\n@@ -2226,6 +2260,11 @@ 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+\toi_data.oid = info->objectname;\n+\tif (oi_data.use_data &&\n+\t    oid_object_info_extended(&oi_data.oid, &oi_data.info, OBJECT_INFO_LOOKUP_REPLACE) < 0)\n+\t\treturn strbuf_addf_ret(error_buf, -1, _(\"missing object %s for %s\"),\n+\t\t\t\t       oid_to_hex(&info->objectname), info->refname);\n \n \tstate.quote_style = format->quote_style;\n \tpush_stack_element(&state.stack);\ndiff --git a/ref-filter.h b/ref-filter.h\nindex 85c8ebc3b904e..857e8c5318a8f 100644\n--- a/ref-filter.h\n+++ b/ref-filter.h\n@@ -85,6 +85,27 @@ struct ref_format {\n \tint need_color_reset_at_eol;\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+\tstruct object_id delta_base_oid;\n+\n+\t/*\n+\t * This object_info is set up to be passed to oid_object_info_extended.\n+\t * It will point to the data elements above, so you can retrieve\n+\t * the response from there.\n+\t */\n+\tstruct object_info info;\n+\n+\t/*\n+\t * This flag will be true if the requested format and options\n+\t * require us to call oid_object_info_extended.\n+\t */\n+\tunsigned use_data : 1;\n+};\n+\n #define REF_FORMAT_INIT { NULL, 0, -1 }\n \n /*  Macros for checking --merged and --no-merged options */\n\n--\nhttps://github.com/git/git/pull/493\n"}]}