From: Jeff King <peff@peff.net>
To: Pablo Sabater <pabloosabaterr@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>,
git@vger.kernel.org, chandrapratap3519@gmail.com,
karthik.188@gmail.com
Subject: Re: [PATCH GSoC v2 4/6] fetch-object-info: parse type from server response
Date: Sat, 1 Aug 2026 19:14:37 -0400 [thread overview]
Message-ID: <20260801231437.GA2097059@coredump.intra.peff.net> (raw)
In-Reply-To: <DKDYGQRTSF2W.25OU81K306HJN@gmail.com>
On Sun, Aug 02, 2026 at 12:20:28AM +0200, Pablo Sabater wrote:
> > We are probably using this pointer indirection to say "ah, '.typep'
> > is NULL so the caller did not ask for this information and the
> > object layer does not have to provide it", plus "'.typep' is NULL
> > so the engine did not give this information for the object". But we
> > can do so with two bitfields
> >
> > unsigned type_asked:1,
> > type_valid:1;
> >
> > instead of paying ~24 bytes or more of heap allocation overhead.
Yes, this conditional loading is exactly how we use the pointers. I
agree that a bool would be smaller, though I doubt it really matters in
practice. You shouldn't have a large number of object_info structs. You
should have one that you use over and over. And it does not point to a
heap allocation, but usually to a stack variable in the caller.
I don't think you'd need type_valid (at least not as the object_info
code is written now). If you ask for it, then either the query is
satisfied, or we return an error.
I think the pointer system goes all the way back to 9a49059022
(sha1_object_info_extended(): expose a bit more info, 2011-05-12). It is
mostly just mirroring the pointers that would be passed directly to the
function (but marshalling them in a struct so callers don't have to pass
a zillion NULLs). So:
read_object_info(oid, &size);
became:
struct object_info query;
query.sizep = &size;
read_object_info(oid, &query);
One minor benefit the pointer system gets you is that the compiler can
more easily tell what has been loaded. Imagine that we had a type_asked
bool, but you forgot to set it. Now you look at oi.type, and it's
garbage (or maybe some sentinel value). But the compiler has no clue
without looking at the innards of the read_object_info() function.
Whereas with the pointers, you do this:
enum object_type type;
struct object_info oi = OBJECT_INFO_INIT;
oi.typep = &type; /* what if we forget this? */
read_object_info(oid, &oi);
do_something(type);
If you forget the pointer assignment, the compiler will realize that
"type" never got passed to anybody and complain.
I don't know how valuable that is in practice, though.
Anyway, that is the history.
> This is related to what had to be done to fix a bug at "contents"
> commands a few days ago [1].
>
> In that patch it had to save the previous state of typep and then
> restore it, because other commands like "info" and this series one
> "remote-object-info" use this pointer for the "is this asked?" question.
Yes, though you'd have the same thing with bools. You'd have to save
type_asked, set it, and then restore it.
> If we take a look at expand_atom():
>
> ...
> } else if (is_atom("objecttype", atom, len)) {
> if (data->mark_query) {
> data->info.typep = &data->type;
> } else {
> const char *t = type_name(data->type);
> strbuf_addstr(sb, t ? t : "");
> }
> ...
>
> expand_atom() has two responsibilities, it is called at the start to map
> which atoms are asked (when data->mark_query), and a second to expand
> those atoms.
Yep. But again, you'd have to set the bools somewhere. And it would be
here (in the mark_query half).
> For example, typep being non-NULL does this effect on these commands:
>
> info: makes a type lookup, and fills type.
>
> remote-object-info: typep is directly used to know whether a client has
> asked for %(objecttype).
>
> For both commands what we pay is extra work because at the end the data
> shown is the one expanded from the format.
There should be no extra work. We do a single read_object_info() that
grabs all of the data and writes it into expand_data. If we are getting
data from elsewhere (say, a remote server) then we should not be using
object_info at all! The concrete data goes into expand_data, which is a
data structure specific to cat-file expansion.
-Peff
next prev parent reply other threads:[~2026-08-01 23:14 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-25 11:55 [PATCH GSoC 0/5] cat-file: extend remote-object-info to support %(objecttype) Pablo Sabater
2026-07-25 11:55 ` [PATCH GSoC 1/5] protocol-caps: add type support to object-info Pablo Sabater
2026-07-29 9:53 ` Chandra Pratap
2026-07-29 11:18 ` Pablo Sabater
2026-07-29 15:40 ` Junio C Hamano
2026-07-29 22:39 ` Karthik Nayak
2026-07-25 11:55 ` [PATCH GSoC 2/5] fetch-object-info: parse type from server response Pablo Sabater
2026-07-29 9:57 ` Chandra Pratap
2026-07-29 12:05 ` Pablo Sabater
2026-07-29 17:06 ` Chandra Pratap
2026-07-29 22:47 ` Karthik Nayak
2026-07-29 22:53 ` Karthik Nayak
2026-07-25 11:55 ` [PATCH GSoC 3/5] fetch-object-info: request all supported options dynamically Pablo Sabater
2026-07-29 9:57 ` Chandra Pratap
2026-07-29 12:07 ` Pablo Sabater
2026-07-25 11:55 ` [PATCH GSoC 4/5] serve: advertise type capability Pablo Sabater
2026-07-29 9:58 ` Chandra Pratap
2026-07-29 12:15 ` Pablo Sabater
2026-07-25 11:55 ` [PATCH GSoC 5/5] cat-file: unify default format Pablo Sabater
2026-07-29 9:59 ` Chandra Pratap
2026-07-29 12:23 ` Pablo Sabater
2026-07-29 9:52 ` [PATCH GSoC 0/5] cat-file: extend remote-object-info to support %(objecttype) Chandra Pratap
2026-07-29 12:34 ` Pablo Sabater
2026-07-31 19:49 ` [PATCH GSoC v2 0/6] " Pablo Sabater
2026-07-31 19:49 ` [PATCH GSoC v2 1/6] fetch-object-info: request all supported options dynamically Pablo Sabater
2026-07-31 23:16 ` Junio C Hamano
2026-07-31 19:49 ` [PATCH GSoC v2 2/6] t5701: use the test_file_size() helper Pablo Sabater
2026-08-01 4:27 ` Junio C Hamano
2026-08-01 20:49 ` Pablo Sabater
2026-07-31 19:49 ` [PATCH GSoC v2 3/6] protocol-caps: add type support to object-info Pablo Sabater
2026-08-01 4:55 ` Junio C Hamano
2026-07-31 19:49 ` [PATCH GSoC v2 4/6] fetch-object-info: parse type from server response Pablo Sabater
2026-08-01 5:04 ` Junio C Hamano
2026-08-01 13:38 ` Junio C Hamano
2026-08-01 22:20 ` Pablo Sabater
2026-08-01 23:14 ` Jeff King [this message]
2026-08-01 23:29 ` Jeff King
2026-08-02 2:02 ` Junio C Hamano
2026-08-01 21:28 ` Pablo Sabater
2026-07-31 19:49 ` [PATCH GSoC v2 5/6] serve: advertise type capability Pablo Sabater
2026-08-01 12:12 ` Chandra Pratap
2026-08-01 21:30 ` Pablo Sabater
2026-07-31 19:49 ` [PATCH GSoC v2 6/6] cat-file: unify default format Pablo Sabater
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=20260801231437.GA2097059@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=chandrapratap3519@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=karthik.188@gmail.com \
--cc=pabloosabaterr@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