From: Junio C Hamano <gitster@pobox.com>
To: Olga Telezhnaya <olyatelezhnaya@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH RFC] ref-filter: start using oid_object_info
Date: Tue, 15 May 2018 12:24:50 +0900 [thread overview]
Message-ID: <xmqqd0xxa9dp.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <010201635e16d282-89bdd0cd-df10-4509-bad7-fd49fd80ff2b-000000@eu-west-1.amazonses.com> (Olga Telezhnaya's message of "Mon, 14 May 2018 09:59:04 +0000")
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?
next prev parent reply other threads:[~2018-05-15 3:24 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-14 9:59 [PATCH RFC] ref-filter: start using oid_object_info Olga Telezhnaya
2018-05-15 3:24 ` Junio C Hamano [this message]
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 4/4] ref-filter: add deltabase formatting option Olga Telezhnaya
2018-05-18 8:19 ` [PATCH RFC v2 2/4] ref-filter: add objectsize:disk " Olga Telezhnaya
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqd0xxa9dp.fsf@gitster-ct.c.googlers.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=olyatelezhnaya@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 NNTP newsgroup(s).