{"thread":{"id":"50101","subject":"[PATCH v2 6/6] ref-filter: add docs for new options","startedAt":"2018-12-24T13:24:33Z","lastAt":"2018-12-28T20:13:00Z","messageCount":7,"participants":["Olga Telezhnaya","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":6},"messages":[{"id":"365778","messageId":"01020167e0636912-b5ab3444-ff8a-4958-916e-e155a80dcc37-000000@eu-west-1.amazonses.com","threadId":"50101","inReplyTo":"01020167e063687c-37a43a09-0a5f-4335-8c21-ec15a0a67882-000000@eu-west-1.amazonses.com","subject":"[PATCH v2 6/6] ref-filter: add docs for new options","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-12-24T13:24:30Z","receivedAt":"2018-12-24T13:24:33Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Add documentation for formatting options objectsize:disk\nand deltabase.\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\n---\n Documentation/git-for-each-ref.txt | 21 ++++++++++++++++++++-\n 1 file changed, 20 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt\nindex 901faef1bfdce..774cecc7ede78 100644\n--- a/Documentation/git-for-each-ref.txt\n+++ b/Documentation/git-for-each-ref.txt\n@@ -128,13 +128,18 @@ objecttype::\n \n objectsize::\n \tThe size of the object (the same as 'git cat-file -s' reports).\n-\n+\tAppend `:disk` to get the size, in bytes, that the object takes up on\n+\tdisk. See the note about on-disk sizes in the `CAVEATS` section below.\n objectname::\n \tThe object name (aka SHA-1).\n \tFor a non-ambiguous abbreviation of the object name append `:short`.\n \tFor an abbreviation of the object name with desired length append\n \t`:short=<length>`, where the minimum length is MINIMUM_ABBREV. The\n \tlength may be exceeded to ensure unique object names.\n+deltabase::\n+\tThis expands to the object name of the delta base for the\n+\tgiven object, if it is stored as a delta.  Otherwise it\n+\texpands to the null object name (all zeroes).\n \n upstream::\n \tThe name of a local ref which can be considered ``upstream''\n@@ -361,6 +366,20 @@ This prints the authorname, if present.\n git for-each-ref --format=\"%(refname)%(if)%(authorname)%(then) Authored by: %(authorname)%(end)\"\n ------------\n \n+CAVEATS\n+-------\n+\n+Note that the sizes of objects on disk are reported accurately, but care\n+should be taken in drawing conclusions about which refs or objects are\n+responsible for disk usage. The size of a packed non-delta object may be\n+much larger than the size of objects which delta against it, but the\n+choice of which object is the base and which is the delta is arbitrary\n+and is subject to change during a repack.\n+\n+Note also that multiple copies of an object may be present in the object\n+database; in this case, it is undefined which copy's size or delta base\n+will be reported.\n+\n SEE ALSO\n --------\n linkgit:git-show-ref[1]\n\n--\nhttps://github.com/git/git/pull/552\n"},{"id":"365779","messageId":"01020167e06368eb-576f5c6e-b54d-4169-971d-a1affed08551-000000@eu-west-1.amazonses.com","threadId":"50101","inReplyTo":"01020167e063687c-37a43a09-0a5f-4335-8c21-ec15a0a67882-000000@eu-west-1.amazonses.com","subject":"[PATCH v2 4/6] ref-filter: add deltabase option","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-12-24T13:24:30Z","receivedAt":"2018-12-24T13:24:34Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Add new formatting option: deltabase.\nIf the object is stored as a delta on-disk, this expands\nto the 40-hex sha1 of the delta base object.\nOtherwise, expands to the null sha1 (40 zeroes).\nWe have same option in cat-file command.\nHopefully, in the end I will remove formatting code from\ncat-file and reuse formatting parts from ref-filter.\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\n---\n ref-filter.c | 16 +++++++++++++++-\n 1 file changed, 15 insertions(+), 1 deletion(-)\n\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 45c558bcbd521..debb8cacad067 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -246,6 +246,18 @@ static int objectsize_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 *err)\n+{\n+\tif (arg)\n+\t\treturn strbuf_addf_ret(err, -1, _(\"%%(deltabase) does not take arguments\"));\n+\tif (*atom->name == '*')\n+\t\toi_deref.info.delta_base_sha1 = oi_deref.delta_base_oid.hash;\n+\telse\n+\t\toi.info.delta_base_sha1 = oi.delta_base_oid.hash;\n+\treturn 0;\n+}\n+\n static int body_atom_parser(const struct ref_format *format, struct used_atom *atom,\n \t\t\t    const char *arg, struct strbuf *err)\n {\n@@ -437,6 +449,7 @@ static struct {\n \t{ \"objecttype\", SOURCE_OTHER, FIELD_STR, objecttype_atom_parser },\n \t{ \"objectsize\", SOURCE_OTHER, FIELD_ULONG, objectsize_atom_parser },\n \t{ \"objectname\", SOURCE_OTHER, FIELD_STR, objectname_atom_parser },\n+\t{ \"deltabase\", SOURCE_OTHER, FIELD_STR, deltabase_atom_parser },\n \t{ \"tree\", SOURCE_OBJ },\n \t{ \"parent\", SOURCE_OBJ },\n \t{ \"numparent\", SOURCE_OBJ, FIELD_ULONG },\n@@ -892,7 +905,8 @@ static void grab_common_values(struct atom_value *val, int deref, struct expand_\n \t\t} else if (!strcmp(name, \"objectsize\")) {\n \t\t\tv->value = oi->size;\n \t\t\tv->s = xstrfmt(\"%\"PRIuMAX , (uintmax_t)oi->size);\n-\t\t}\n+\t\t} else if (!strcmp(name, \"deltabase\"))\n+\t\t\tv->s = xstrdup(oid_to_hex(&oi->delta_base_oid));\n \t\telse if (deref)\n \t\t\tgrab_objectname(name, &oi->oid, v, &used_atom[i]);\n \t}\n\n--\nhttps://github.com/git/git/pull/552\n"},{"id":"365780","messageId":"01020167e06368d8-783d15ea-9847-48bc-b3be-aa57b45ffe92-000000@eu-west-1.amazonses.com","threadId":"50101","inReplyTo":"01020167e063687c-37a43a09-0a5f-4335-8c21-ec15a0a67882-000000@eu-west-1.amazonses.com","subject":"[PATCH v2 3/6] ref-filter: add tests for objectsize:disk","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-12-24T13:24:30Z","receivedAt":"2018-12-24T13:24:36Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Test new formatting atom.\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\n---\n t/t6300-for-each-ref.sh | 3 +++\n 1 file changed, 3 insertions(+)\n\ndiff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh\nindex 97bfbee6e8d69..097fdf21fe196 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,8 @@ 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 '*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/552\n"},{"id":"365781","messageId":"01020167e06368ee-092ccd7f-6f37-425b-9eb3-bdd9b1cb8358-000000@eu-west-1.amazonses.com","threadId":"50101","inReplyTo":"01020167e063687c-37a43a09-0a5f-4335-8c21-ec15a0a67882-000000@eu-west-1.amazonses.com","subject":"[PATCH v2 5/6] ref-filter: add tests for deltabase","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-12-24T13:24:30Z","receivedAt":"2018-12-24T13:24:37Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Test new formatting option deltabase.\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\n---\n t/t6300-for-each-ref.sh | 3 +++\n 1 file changed, 3 insertions(+)\n\ndiff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh\nindex 097fdf21fe196..0ffd63071392e 100755\n--- a/t/t6300-for-each-ref.sh\n+++ b/t/t6300-for-each-ref.sh\n@@ -84,6 +84,7 @@ 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 deltabase 0000000000000000000000000000000000000000\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@@ -127,6 +128,8 @@ test_atom tag objecttype tag\n test_atom tag objectsize 154\n test_atom tag objectsize:disk 138\n test_atom tag '*objectsize:disk' 138\n+test_atom tag deltabase 0000000000000000000000000000000000000000\n+test_atom tag '*deltabase' 0000000000000000000000000000000000000000\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/552\n"},{"id":"365782","messageId":"01020167e063687c-37a43a09-0a5f-4335-8c21-ec15a0a67882-000000@eu-west-1.amazonses.com","threadId":"50101","inReplyTo":"CAL21BmnmfxpMgbW_Yz9D=FVZk_AzWF0uyrNZeSGPCs63PH1oag@mail.gmail.com","subject":"[PATCH v2 1/6] ref-filter: add objectsize:disk option","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-12-24T13:24:30Z","receivedAt":"2018-12-24T13:24:38Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"Add new formatting option objectsize:disk to know\nexact size that object takes up on disk.\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\n---\n ref-filter.c | 23 ++++++++++++++++-------\n 1 file changed, 16 insertions(+), 7 deletions(-)\n\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 5de616befe46e..fd95547676047 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -231,12 +231,18 @@ static int objecttype_atom_parser(const struct ref_format *format, struct used_a\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-\tif (arg)\n-\t\treturn strbuf_addf_ret(err, -1, _(\"%%(objectsize) does not take arguments\"));\n-\tif (*atom->name == '*')\n-\t\toi_deref.info.sizep = &oi_deref.size;\n-\telse\n-\t\toi.info.sizep = &oi.size;\n+\tif (!arg) {\n+\t\tif (*atom->name == '*')\n+\t\t\toi_deref.info.sizep = &oi_deref.size;\n+\t\telse\n+\t\t\toi.info.sizep = &oi.size;\n+\t} else if (!strcmp(arg, \"disk\")) {\n+\t\tif (*atom->name == '*')\n+\t\t\toi_deref.info.disk_sizep = &oi_deref.disk_size;\n+\t\telse\n+\t\t\toi.info.disk_sizep = &oi.disk_size;\n+\t} else\n+\t\treturn strbuf_addf_ret(err, -1, _(\"unrecognized %%(objectsize) argument: %s\"), arg);\n \treturn 0;\n }\n \n@@ -880,7 +886,10 @@ static void grab_common_values(struct atom_value *val, int deref, struct expand_\n \t\t\tname++;\n \t\tif (!strcmp(name, \"objecttype\"))\n \t\t\tv->s = xstrdup(type_name(oi->type));\n-\t\telse if (!strcmp(name, \"objectsize\")) {\n+\t\telse if (!strcmp(name, \"objectsize:disk\")) {\n+\t\t\tv->value = oi->disk_size;\n+\t\t\tv->s = xstrfmt(\"%\"PRIuMAX, (intmax_t)oi->disk_size);\n+\t\t} else if (!strcmp(name, \"objectsize\")) {\n \t\t\tv->value = oi->size;\n \t\t\tv->s = xstrfmt(\"%\"PRIuMAX , (uintmax_t)oi->size);\n \t\t}\n\n--\nhttps://github.com/git/git/pull/552\n"},{"id":"365783","messageId":"01020167e06368cb-7c85a9f8-c94c-47a6-9068-929e11104cec-000000@eu-west-1.amazonses.com","threadId":"50101","inReplyTo":"01020167e063687c-37a43a09-0a5f-4335-8c21-ec15a0a67882-000000@eu-west-1.amazonses.com","subject":"[PATCH v2 2/6] ref-filter: add check for negative file size","fromName":"Olga Telezhnaya","fromEmail":"olyatelezhnaya@gmail.com","sentAt":"2018-12-24T13:24:30Z","receivedAt":"2018-12-24T13:24:44Z","isPatch":true,"sender":{"key":"olyatelezhnaya@gmail.com","avatar":"https://avatars.githubusercontent.com/u/11246099?v=4"},"body":"If we have negative file size, we are doing something wrong.\n\nSigned-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>\n---\n ref-filter.c | 2 ++\n 1 file changed, 2 insertions(+)\n\ndiff --git a/ref-filter.c b/ref-filter.c\nindex fd95547676047..45c558bcbd521 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -1491,6 +1491,8 @@ static int get_object(struct ref_array_item *ref, int deref, struct object **obj\n \t\t\t\t     OBJECT_INFO_LOOKUP_REPLACE))\n \t\treturn strbuf_addf_ret(err, -1, _(\"missing object %s for %s\"),\n \t\t\t\t       oid_to_hex(&oi->oid), ref->refname);\n+\tif (oi->info.disk_sizep && oi->disk_size < 0)\n+\t\tBUG(\"Object size is less than zero.\");\n \n \tif (oi->info.contentp) {\n \t\t*obj = parse_object_buffer(the_repository, &oi->oid, oi->type, oi->size, oi->content, &eaten);\n\n--\nhttps://github.com/git/git/pull/552\n"},{"id":"365922","messageId":"xmqqwontmmuv.fsf@gitster-ct.c.googlers.com","threadId":"50101","inReplyTo":"01020167e063687c-37a43a09-0a5f-4335-8c21-ec15a0a67882-000000@eu-west-1.amazonses.com","subject":"Re: [PATCH v2 1/6] ref-filter: add objectsize:disk option","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-12-26T20:44:07Z","receivedAt":"2018-12-28T20:13:00Z","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> @@ -880,7 +886,10 @@ static void grab_common_values(struct atom_value *val, int deref, struct expand_\n>  \t\t\tname++;\n>  \t\tif (!strcmp(name, \"objecttype\"))\n>  \t\t\tv->s = xstrdup(type_name(oi->type));\n> -\t\telse if (!strcmp(name, \"objectsize\")) {\n> +\t\telse if (!strcmp(name, \"objectsize:disk\")) {\n> +\t\t\tv->value = oi->disk_size;\n> +\t\t\tv->s = xstrfmt(\"%\"PRIuMAX, (intmax_t)oi->disk_size);\n\nShouldn't this cast the field to (uintmax_t) type, as we'd format\nwith %PRIuMAX and we know the size on-disk is not negative?\n\nOther than that, looks good.\n\nLet me rewind the tip of 'next' and replace the previous round with\nthis iteration.\n\nThanks.\n\n> +\t\t} else if (!strcmp(name, \"objectsize\")) {\n>  \t\t\tv->value = oi->size;\n>  \t\t\tv->s = xstrfmt(\"%\"PRIuMAX , (uintmax_t)oi->size);\n>  \t\t}\n>\n> --\n> https://github.com/git/git/pull/552\n"}]}