* [PATCH RFC] ref-filter: start using oid_object_info @ 2018-05-14 9:59 Olga Telezhnaya 2018-05-15 3:24 ` Junio C Hamano 2018-05-18 8:19 ` [PATCH RFC v2 1/4] " Olga Telezhnaya 0 siblings, 2 replies; 7+ messages in thread From: Olga Telezhnaya @ 2018-05-14 9:59 UTC (permalink / raw) To: git Start using oid_object_info_extended(). So, if info from this function is enough, we do not need to get and parse whole object (as it was before). It's good for 3 reasons: 1. Some Git commands potentially will work faster. 2. It's much easier to add support for objectsize:disk and deltabase. (I have plans to add this support further) 3. It's easier to move formatting from cat-file command to this logic (It pretends to be unified formatting logic in the end) Signed-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com> --- ref-filter.c | 34 +++++++++++++++++++++++++++++++--- ref-filter.h | 21 +++++++++++++++++++++ 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/ref-filter.c b/ref-filter.c index 39e2744c949bb..7c4693ed084bb 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -100,6 +100,7 @@ static struct used_atom { } u; } *used_atom; static int used_atom_cnt, need_tagged, need_symref; +static struct expand_data format_data; /* * Expand string, append it to strbuf *sb, then return error code ret. @@ -267,6 +268,22 @@ static int contents_atom_parser(const struct ref_format *format, struct used_ato return 0; } +static int objecttype_atom_parser(const struct ref_format *format, struct used_atom *atom, + const char *arg, struct strbuf *unused_err) +{ + format_data.use_data = 1; + format_data.info.typep = &format_data.type; + return 0; +} + +static int objectsize_atom_parser(const struct ref_format *format, struct used_atom *atom, + const char *arg, struct strbuf *unused_err) +{ + format_data.use_data = 1; + format_data.info.sizep = &format_data.size; + return 0; +} + static int objectname_atom_parser(const struct ref_format *format, struct used_atom *atom, const char *arg, struct strbuf *err) { @@ -383,9 +400,9 @@ static struct { int (*parser)(const struct ref_format *format, struct used_atom *atom, const char *arg, struct strbuf *err); } valid_atom[] = { - { "refname" , FIELD_STR, refname_atom_parser }, - { "objecttype" }, - { "objectsize", FIELD_ULONG }, + { "refname", FIELD_STR, refname_atom_parser }, + { "objecttype", FIELD_STR, objecttype_atom_parser }, + { "objectsize", FIELD_ULONG, objectsize_atom_parser }, { "objectname", FIELD_STR, objectname_atom_parser }, { "tree" }, { "parent" }, @@ -1536,6 +1553,13 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err) continue; } else if (!deref && grab_objectname(name, &ref->objectname, v, atom)) { continue; + } else if (!deref && !strcmp(name, "objecttype")) { + v->s = type_name(format_data.type); + continue; + } else if (!deref && !strcmp(name, "objectsize")) { + v->value = format_data.size; + v->s = xstrfmt("%lu", format_data.size); + continue; } else if (!strcmp(name, "HEAD")) { if (atom->u.head && !strcmp(ref->refname, atom->u.head)) v->s = "*"; @@ -2226,6 +2250,10 @@ int format_ref_array_item(struct ref_array_item *info, { const char *cp, *sp, *ep; struct ref_formatting_state state = REF_FORMATTING_STATE_INIT; + format_data.oid = info->objectname; + if (format_data.use_data && oid_object_info_extended(&format_data.oid, &format_data.info, + OBJECT_INFO_LOOKUP_REPLACE) < 0) + return strbuf_addf_ret(error_buf, -1, "format: could not get object info"); state.quote_style = format->quote_style; push_stack_element(&state.stack); diff --git a/ref-filter.h b/ref-filter.h index 85c8ebc3b904e..857e8c5318a8f 100644 --- a/ref-filter.h +++ b/ref-filter.h @@ -85,6 +85,27 @@ struct ref_format { int need_color_reset_at_eol; }; +struct expand_data { + struct object_id oid; + enum object_type type; + unsigned long size; + off_t disk_size; + struct object_id delta_base_oid; + + /* + * This object_info is set up to be passed to oid_object_info_extended. + * It will point to the data elements above, so you can retrieve + * the response from there. + */ + struct object_info info; + + /* + * This flag will be true if the requested format and options + * require us to call oid_object_info_extended. + */ + unsigned use_data : 1; +}; + #define REF_FORMAT_INIT { NULL, 0, -1 } /* Macros for checking --merged and --no-merged options */ -- https://github.com/git/git/pull/493 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH RFC] ref-filter: start using oid_object_info 2018-05-14 9:59 [PATCH RFC] ref-filter: start using oid_object_info Olga Telezhnaya @ 2018-05-15 3:24 ` Junio C Hamano 2018-05-15 3:53 ` Junio C Hamano 2018-05-18 8:19 ` [PATCH RFC v2 1/4] " Olga Telezhnaya 1 sibling, 1 reply; 7+ messages in thread From: Junio C Hamano @ 2018-05-15 3:24 UTC (permalink / raw) To: Olga Telezhnaya; +Cc: git Olga Telezhnaya <olyatelezhnaya@gmail.com> writes: > Start using oid_object_info_extended(). So, if info from this function > is enough, we do not need to get and parse whole object (as it was before). > It's good for 3 reasons: > 1. Some Git commands potentially will work faster. > 2. It's much easier to add support for objectsize:disk and deltabase. > (I have plans to add this support further) > 3. It's easier to move formatting from cat-file command to this logic > (It pretends to be unified formatting logic in the end) > > Signed-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com> > --- > ref-filter.c | 34 +++++++++++++++++++++++++++++++--- > ref-filter.h | 21 +++++++++++++++++++++ > 2 files changed, 52 insertions(+), 3 deletions(-) >... > @@ -383,9 +400,9 @@ static struct { > int (*parser)(const struct ref_format *format, struct used_atom *atom, > const char *arg, struct strbuf *err); > } valid_atom[] = { > - { "refname" , FIELD_STR, refname_atom_parser }, > - { "objecttype" }, > - { "objectsize", FIELD_ULONG }, > + { "refname", FIELD_STR, refname_atom_parser }, > + { "objecttype", FIELD_STR, objecttype_atom_parser }, > + { "objectsize", FIELD_ULONG, objectsize_atom_parser }, > { "objectname", FIELD_STR, objectname_atom_parser }, > { "tree" }, > { "parent" }, Hmph, so this patch does not teach us to interpolate any new %(field-type) but changes the way %(objecttype) and %(objectsize) are computed. > @@ -1536,6 +1553,13 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err) > continue; > } else if (!deref && grab_objectname(name, &ref->objectname, v, atom)) { > continue; > + } else if (!deref && !strcmp(name, "objecttype")) { > + v->s = type_name(format_data.type); > + continue; > + } else if (!deref && !strcmp(name, "objectsize")) { > + v->value = format_data.size; > + v->s = xstrfmt("%lu", format_data.size); > + continue; > } else if (!strcmp(name, "HEAD")) { > if (atom->u.head && !strcmp(ref->refname, atom->u.head)) > v->s = "*"; Because this addition is made to the early "Fill in specials first" loop of the populate_value() function, we may be able to satisfy some requests early without calling get_object() which then calls parse_object(). > @@ -2226,6 +2250,10 @@ int format_ref_array_item(struct ref_array_item *info, > { > const char *cp, *sp, *ep; > struct ref_formatting_state state = REF_FORMATTING_STATE_INIT; > + format_data.oid = info->objectname; > + if (format_data.use_data && oid_object_info_extended(&format_data.oid, &format_data.info, Style: fold the line after " &&". And this checks the .use_data field to see if these fields whose value could be computed by a call to oid_object_info_extended() without calling parse_object(). If there is one, we call it; otherwise we don't. So there are three possible cases: - The request does not ask for these fields that can be filled from "format_data" (by the way, that is a horrible name---all the data in this codepath is for formatting, and in that sense the variable is not named after its most significant trait, which is that it is to grab data needed for formatting via a call to a function in the object_info() family. Perhaps object_info_data or oi_data for brevity). We do not call object_info() and the performance characteristic of the code stays as before. - The request asks for these fields that are helped by "object-info" and no other fields. We make a call to "object-info", instead of parse_object(), which hopefully is more efficient (we need to measure, if we are selling this as an optimization). - The request asks for both. We end up calling object-info and also parse_object(), so presumably there is degradation of performance. In the third case, after v->s and v->value are filled by the new code that copies from format_data, grab_values() will again fill objecttype/objectsize by overwriting v->s field. Doesn't this cause memory leaks? type_name() returns a constant string that does not leak, but your objectsize seems to use xstrfmt(), so... I think it was OK before this patch as grab_common_values() was the only place that did v->s = xstrfmt() for the field, but now the code with this patch can do the same assignment from two places, we would need to be a bit more careful about memory ownership? ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH RFC] ref-filter: start using oid_object_info 2018-05-15 3:24 ` Junio C Hamano @ 2018-05-15 3:53 ` Junio C Hamano 0 siblings, 0 replies; 7+ messages in thread From: Junio C Hamano @ 2018-05-15 3:53 UTC (permalink / raw) To: Olga Telezhnaya; +Cc: git Junio C Hamano <gitster@pobox.com> writes: > Olga Telezhnaya <olyatelezhnaya@gmail.com> writes: > >> Start using oid_object_info_extended(). So, if info from this function >> is enough, we do not need to get and parse whole object (as it was before). >> It's good for 3 reasons: >> 1. Some Git commands potentially will work faster. >> 2. It's much easier to add support for objectsize:disk and deltabase. >> (I have plans to add this support further) >> 3. It's easier to move formatting from cat-file command to this logic >> (It pretends to be unified formatting logic in the end) >> >> Signed-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com> >> --- >> ref-filter.c | 34 +++++++++++++++++++++++++++++++--- >> ref-filter.h | 21 +++++++++++++++++++++ >> 2 files changed, 52 insertions(+), 3 deletions(-) >>... >> @@ -383,9 +400,9 @@ static struct { >> int (*parser)(const struct ref_format *format, struct used_atom *atom, >> const char *arg, struct strbuf *err); >> } valid_atom[] = { >> - { "refname" , FIELD_STR, refname_atom_parser }, >> - { "objecttype" }, >> - { "objectsize", FIELD_ULONG }, >> + { "refname", FIELD_STR, refname_atom_parser }, >> + { "objecttype", FIELD_STR, objecttype_atom_parser }, >> + { "objectsize", FIELD_ULONG, objectsize_atom_parser }, >> { "objectname", FIELD_STR, objectname_atom_parser }, >> { "tree" }, >> { "parent" }, > > Hmph, so this patch does not teach us to interpolate any new %(field-type) > but changes the way %(objecttype) and %(objectsize) are computed. > >> @@ -1536,6 +1553,13 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err) >> continue; >> } else if (!deref && grab_objectname(name, &ref->objectname, v, atom)) { >> continue; >> + } else if (!deref && !strcmp(name, "objecttype")) { >> + v->s = type_name(format_data.type); >> + continue; >> + } else if (!deref && !strcmp(name, "objectsize")) { >> + v->value = format_data.size; >> + v->s = xstrfmt("%lu", format_data.size); >> + continue; >> } else if (!strcmp(name, "HEAD")) { >> if (atom->u.head && !strcmp(ref->refname, atom->u.head)) >> v->s = "*"; > > Because this addition is made to the early "Fill in specials first" > loop of the populate_value() function, we may be able to satisfy > some requests early without calling get_object() which then calls > parse_object(). > >> @@ -2226,6 +2250,10 @@ int format_ref_array_item(struct ref_array_item *info, >> { >> const char *cp, *sp, *ep; >> struct ref_formatting_state state = REF_FORMATTING_STATE_INIT; >> + format_data.oid = info->objectname; >> + if (format_data.use_data && oid_object_info_extended(&format_data.oid, &format_data.info, > > Style: fold the line after " &&". > > And this checks the .use_data field to see if these fields whose > value could be computed by a call to oid_object_info_extended() > without calling parse_object(). If there is one, we call it; > otherwise we don't. > > So there are three possible cases: > > - The request does not ask for these fields that can be filled from > "format_data" (by the way, that is a horrible name---all the data > in this codepath is for formatting, and in that sense the > variable is not named after its most significant trait, which is > that it is to grab data needed for formatting via a call to > a function in the object_info() family. Perhaps object_info_data > or oi_data for brevity). We do not call object_info() and the > performance characteristic of the code stays as before. > > - The request asks for these fields that are helped by > "object-info" and no other fields. We make a call to > "object-info", instead of parse_object(), which hopefully is more > efficient (we need to measure, if we are selling this as an > optimization). > > - The request asks for both. We end up calling object-info and > also parse_object(), so presumably there is degradation of > performance. > > In the third case, after v->s and v->value are filled by the new > code that copies from format_data, grab_values() will again fill > objecttype/objectsize by overwriting v->s field. Doesn't this cause > memory leaks? type_name() returns a constant string that does not > leak, but your objectsize seems to use xstrfmt(), so... > > I think it was OK before this patch as grab_common_values() was the > only place that did v->s = xstrfmt() for the field, but now the code > with this patch can do the same assignment from two places, we would > need to be a bit more careful about memory ownership? Another thing that came to my mind while reading the patch aloud in my previous message was if we can easily tell the latter two cases apart, before actually going into the populate_value() codepath. We can easily tell that fields that can benefit from object-info were requested with your .use_data field technique. If we can also easily tell that fields that do need full get_object() and call to parse_object(), then we can avoid calling object_info() and grab values for objectsize etc. in the old way. Of course, if you plan to extend the set of fields further so that some traits about an object that can only be learned by calling object_info(), then we may have to make calls to both object_info() and parse_object(). And when that happens we'd restructure the code again, but until then, the above sounds like an optimization worth considering. Thanks. ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH RFC v2 1/4] ref-filter: start using oid_object_info 2018-05-14 9:59 [PATCH RFC] ref-filter: start using oid_object_info Olga Telezhnaya 2018-05-15 3:24 ` Junio C Hamano @ 2018-05-18 8:19 ` Olga Telezhnaya 2018-05-18 8:19 ` [PATCH RFC v2 3/4] ref-filter: add tests for objectsize:disk Olga Telezhnaya ` (2 more replies) 1 sibling, 3 replies; 7+ messages in thread From: Olga Telezhnaya @ 2018-05-18 8:19 UTC (permalink / raw) To: git Start using oid_object_info_extended(). So, if info from this function is enough, we do not need to get and parse whole object (as it was before). It's good for 3 reasons: 1. Some Git commands potentially will work faster. 2. It's much easier to add support for objectsize:disk and deltabase. (I have plans to add this support further) 3. It's easier to move formatting from cat-file command to this logic (It pretends to be unified formatting logic in the end) Signed-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com> --- ref-filter.c | 47 +++++++++++++++++++++++++++++++++++++++++++---- ref-filter.h | 21 +++++++++++++++++++++ 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/ref-filter.c b/ref-filter.c index 39e2744c949bb..4008351553391 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -100,6 +100,7 @@ static struct used_atom { } u; } *used_atom; static int used_atom_cnt, need_tagged, need_symref; +static struct expand_data oi_data; /* * Expand string, append it to strbuf *sb, then return error code ret. @@ -267,6 +268,22 @@ static int contents_atom_parser(const struct ref_format *format, struct used_ato return 0; } +static int objecttype_atom_parser(const struct ref_format *format, struct used_atom *atom, + const char *arg, struct strbuf *unused_err) +{ + oi_data.use_data = 1; + oi_data.info.typep = &oi_data.type; + return 0; +} + +static int objectsize_atom_parser(const struct ref_format *format, struct used_atom *atom, + const char *arg, struct strbuf *unused_err) +{ + oi_data.use_data = 1; + oi_data.info.sizep = &oi_data.size; + return 0; +} + static int objectname_atom_parser(const struct ref_format *format, struct used_atom *atom, const char *arg, struct strbuf *err) { @@ -383,9 +400,9 @@ static struct { int (*parser)(const struct ref_format *format, struct used_atom *atom, const char *arg, struct strbuf *err); } valid_atom[] = { - { "refname" , FIELD_STR, refname_atom_parser }, - { "objecttype" }, - { "objectsize", FIELD_ULONG }, + { "refname", FIELD_STR, refname_atom_parser }, + { "objecttype", FIELD_STR, objecttype_atom_parser }, + { "objectsize", FIELD_ULONG, objectsize_atom_parser }, { "objectname", FIELD_STR, objectname_atom_parser }, { "tree" }, { "parent" }, @@ -1207,7 +1224,8 @@ static void fill_missing_values(struct atom_value *val) */ static void grab_values(struct atom_value *val, int deref, struct object *obj, void *buf, unsigned long sz) { - grab_common_values(val, deref, obj, buf, sz); + if (deref || !oi_data.use_data) + grab_common_values(val, deref, obj, buf, sz); switch (obj->type) { case OBJ_TAG: grab_tag_values(val, deref, obj, buf, sz); @@ -1536,6 +1554,13 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err) continue; } else if (!deref && grab_objectname(name, &ref->objectname, v, atom)) { continue; + } else if (!deref && !strcmp(name, "objecttype") && oi_data.use_data) { + v->s = type_name(oi_data.type); + continue; + } else if (!deref && !strcmp(name, "objectsize") && oi_data.use_data) { + v->value = oi_data.size; + v->s = xstrfmt("%lu", oi_data.size); + continue; } else if (!strcmp(name, "HEAD")) { if (atom->u.head && !strcmp(ref->refname, atom->u.head)) v->s = "*"; @@ -2156,8 +2181,17 @@ static int cmp_ref_sorting(struct ref_sorting *s, struct ref_array_item *a, stru int (*cmp_fn)(const char *, const char *); struct strbuf err = STRBUF_INIT; + oi_data.oid = a->objectname; + if (oi_data.use_data && + oid_object_info_extended(&oi_data.oid, &oi_data.info, OBJECT_INFO_LOOKUP_REPLACE) < 0) + die(_("missing object %s for %s"), oid_to_hex(&a->objectname), a->refname); if (get_ref_atom_value(a, s->atom, &va, &err)) die("%s", err.buf); + + oi_data.oid = b->objectname; + if (oi_data.use_data && + oid_object_info_extended(&oi_data.oid, &oi_data.info, OBJECT_INFO_LOOKUP_REPLACE) < 0) + die(_("missing object %s for %s"), oid_to_hex(&b->objectname), b->refname); if (get_ref_atom_value(b, s->atom, &vb, &err)) die("%s", err.buf); strbuf_release(&err); @@ -2226,6 +2260,11 @@ int format_ref_array_item(struct ref_array_item *info, { const char *cp, *sp, *ep; struct ref_formatting_state state = REF_FORMATTING_STATE_INIT; + oi_data.oid = info->objectname; + if (oi_data.use_data && + oid_object_info_extended(&oi_data.oid, &oi_data.info, OBJECT_INFO_LOOKUP_REPLACE) < 0) + return strbuf_addf_ret(error_buf, -1, _("missing object %s for %s"), + oid_to_hex(&info->objectname), info->refname); state.quote_style = format->quote_style; push_stack_element(&state.stack); diff --git a/ref-filter.h b/ref-filter.h index 85c8ebc3b904e..857e8c5318a8f 100644 --- a/ref-filter.h +++ b/ref-filter.h @@ -85,6 +85,27 @@ struct ref_format { int need_color_reset_at_eol; }; +struct expand_data { + struct object_id oid; + enum object_type type; + unsigned long size; + off_t disk_size; + struct object_id delta_base_oid; + + /* + * This object_info is set up to be passed to oid_object_info_extended. + * It will point to the data elements above, so you can retrieve + * the response from there. + */ + struct object_info info; + + /* + * This flag will be true if the requested format and options + * require us to call oid_object_info_extended. + */ + unsigned use_data : 1; +}; + #define REF_FORMAT_INIT { NULL, 0, -1 } /* Macros for checking --merged and --no-merged options */ -- https://github.com/git/git/pull/493 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH RFC v2 3/4] ref-filter: add tests for objectsize:disk 2018-05-18 8:19 ` [PATCH RFC v2 1/4] " Olga Telezhnaya @ 2018-05-18 8:19 ` Olga Telezhnaya 2018-05-18 8:19 ` [PATCH RFC v2 2/4] ref-filter: add objectsize:disk formatting option Olga Telezhnaya 2018-05-18 8:19 ` [PATCH RFC v2 4/4] ref-filter: add deltabase " Olga Telezhnaya 2 siblings, 0 replies; 7+ messages in thread From: Olga Telezhnaya @ 2018-05-18 8:19 UTC (permalink / raw) To: git Add tests for %(objectsize:disk) atom. Signed-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com> --- t/t6300-for-each-ref.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh index 295d1475bde01..570bb606045d7 100755 --- a/t/t6300-for-each-ref.sh +++ b/t/t6300-for-each-ref.sh @@ -83,6 +83,7 @@ test_atom head push:strip=1 remotes/myfork/master test_atom head push:strip=-1 master test_atom head objecttype commit test_atom head objectsize 171 +test_atom head objectsize:disk 138 test_atom head objectname $(git rev-parse refs/heads/master) test_atom head objectname:short $(git rev-parse --short refs/heads/master) test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/master) @@ -124,6 +125,7 @@ test_atom tag upstream '' test_atom tag push '' test_atom tag objecttype tag test_atom tag objectsize 154 +test_atom tag objectsize:disk 138 test_atom tag objectname $(git rev-parse refs/tags/testtag) test_atom tag objectname:short $(git rev-parse --short refs/tags/testtag) test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/master) -- https://github.com/git/git/pull/493 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH RFC v2 2/4] ref-filter: add objectsize:disk formatting option 2018-05-18 8:19 ` [PATCH RFC v2 1/4] " Olga Telezhnaya 2018-05-18 8:19 ` [PATCH RFC v2 3/4] ref-filter: add tests for objectsize:disk Olga Telezhnaya @ 2018-05-18 8:19 ` Olga Telezhnaya 2018-05-18 8:19 ` [PATCH RFC v2 4/4] ref-filter: add deltabase " Olga Telezhnaya 2 siblings, 0 replies; 7+ messages in thread From: Olga Telezhnaya @ 2018-05-18 8:19 UTC (permalink / raw) To: git Add %(objectsize:disk) support. It is still not working for deref: I am thinking how to support it in a more elegant way. Signed-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com> --- ref-filter.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/ref-filter.c b/ref-filter.c index 4008351553391..c00de58455301 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -277,10 +277,15 @@ static int objecttype_atom_parser(const struct ref_format *format, struct used_a } static int objectsize_atom_parser(const struct ref_format *format, struct used_atom *atom, - const char *arg, struct strbuf *unused_err) + const char *arg, struct strbuf *err) { + if (!arg) + oi_data.info.sizep = &oi_data.size; + else if (!strcmp(arg, "disk")) + oi_data.info.disk_sizep = &oi_data.disk_size; + else + return strbuf_addf_ret(err, -1, _("unrecognized %%(objectsize) argument: %s"), arg); oi_data.use_data = 1; - oi_data.info.sizep = &oi_data.size; return 0; } @@ -1557,9 +1562,15 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err) } else if (!deref && !strcmp(name, "objecttype") && oi_data.use_data) { v->s = type_name(oi_data.type); continue; - } else if (!deref && !strcmp(name, "objectsize") && oi_data.use_data) { - v->value = oi_data.size; - v->s = xstrfmt("%lu", oi_data.size); + } else if (!deref && starts_with(name, "objectsize") && oi_data.use_data) { + if (!strcmp(name, "objectsize")) { + v->value = oi_data.size; + v->s = xstrfmt("%lu", oi_data.size); + } else { + /* It can be only objectsize:disk, we checked it in parser */ + v->value = oi_data.disk_size; + v->s = xstrfmt("%lu", oi_data.disk_size); + } continue; } else if (!strcmp(name, "HEAD")) { if (atom->u.head && !strcmp(ref->refname, atom->u.head)) -- https://github.com/git/git/pull/493 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH RFC v2 4/4] ref-filter: add deltabase formatting option 2018-05-18 8:19 ` [PATCH RFC v2 1/4] " Olga Telezhnaya 2018-05-18 8:19 ` [PATCH RFC v2 3/4] ref-filter: add tests for objectsize:disk Olga Telezhnaya 2018-05-18 8:19 ` [PATCH RFC v2 2/4] ref-filter: add objectsize:disk formatting option Olga Telezhnaya @ 2018-05-18 8:19 ` Olga Telezhnaya 2 siblings, 0 replies; 7+ messages in thread From: Olga Telezhnaya @ 2018-05-18 8:19 UTC (permalink / raw) To: git Add %(deltabase) support. It is still not working for deref: I am thinking how to support it in a more elegant way. Signed-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com> --- ref-filter.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ref-filter.c b/ref-filter.c index c00de58455301..989ccdb356a32 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -276,6 +276,14 @@ static int objecttype_atom_parser(const struct ref_format *format, struct used_a return 0; } +static int deltabase_atom_parser(const struct ref_format *format, struct used_atom *atom, + const char *arg, struct strbuf *unused_err) +{ + oi_data.use_data = 1; + oi_data.info.delta_base_sha1 = oi_data.delta_base_oid.hash; + return 0; +} + static int objectsize_atom_parser(const struct ref_format *format, struct used_atom *atom, const char *arg, struct strbuf *err) { @@ -409,6 +417,7 @@ static struct { { "objecttype", FIELD_STR, objecttype_atom_parser }, { "objectsize", FIELD_ULONG, objectsize_atom_parser }, { "objectname", FIELD_STR, objectname_atom_parser }, + { "deltabase", FIELD_STR, deltabase_atom_parser }, { "tree" }, { "parent" }, { "numparent", FIELD_ULONG }, @@ -1572,6 +1581,9 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err) v->s = xstrfmt("%lu", oi_data.disk_size); } continue; + } else if (!deref && !strcmp(name, "deltabase") && oi_data.use_data) { + v->s = xstrdup(oid_to_hex(&oi_data.delta_base_oid)); + continue; } else if (!strcmp(name, "HEAD")) { if (atom->u.head && !strcmp(ref->refname, atom->u.head)) v->s = "*"; -- https://github.com/git/git/pull/493 ^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2018-05-18 9:11 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2018-05-14 9:59 [PATCH RFC] ref-filter: start using oid_object_info Olga Telezhnaya 2018-05-15 3:24 ` Junio C Hamano 2018-05-15 3:53 ` Junio C Hamano 2018-05-18 8:19 ` [PATCH RFC v2 1/4] " Olga Telezhnaya 2018-05-18 8:19 ` [PATCH RFC v2 3/4] ref-filter: add tests for objectsize:disk Olga Telezhnaya 2018-05-18 8:19 ` [PATCH RFC v2 2/4] ref-filter: add objectsize:disk formatting option Olga Telezhnaya 2018-05-18 8:19 ` [PATCH RFC v2 4/4] ref-filter: add deltabase " Olga Telezhnaya
Code repositories for project(s) associated with this public inbox https://80x24.org/mirrors/git.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).