From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: Alan Stokes <alan@source.dev>,
Pablo Sabater <pabloosabaterr@gmail.com>,
git@vger.kernel.org
Subject: Re: [PATCH] cat-file: handle content request for --batch-command without type
Date: Tue, 28 Jul 2026 10:36:57 -0700 [thread overview]
Message-ID: <xmqqjyqfdnie.fsf@gitster.g> (raw)
In-Reply-To: <20260728150031.GA41931@coredump.intra.peff.net> (Jeff King's message of "Tue, 28 Jul 2026 11:00:31 -0400")
Jeff King <peff@peff.net> writes:
> We can fix it by tweaking the object_info on the fly as we receive each
> command. But we should be careful to restore it afterwards; otherwise a
> sequence of commands like:
>
> contents $one
> info $two
> info $three
>
> will pay the type-lookup price for $two and $three when it does not need
> to. This wouldn't be incorrect, but just slightly inefficient (and hence
> there are no tests for that part, because the externally-visible
> behavior is the same).
Woooo, tricky. I love this kind of attention to details.
The patch text obviously is correct.
Will queue and mark the topic for 'next'. Thanks.
> Reported-by: Alan Stokes <alan@source.dev>
> Helped-by: Pablo Sabater <pabloosabaterr@gmail.com>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> builtin/cat-file.c | 3 +++
> t/t1006-cat-file.sh | 8 ++++++++
> 2 files changed, 11 insertions(+)
>
> diff --git a/builtin/cat-file.c b/builtin/cat-file.c
> index 1458dd76d6..ac458c9737 100644
> --- a/builtin/cat-file.c
> +++ b/builtin/cat-file.c
> @@ -689,8 +689,11 @@ static void parse_cmd_contents(struct batch_options *opt,
> struct strbuf *output,
> struct expand_data *data)
> {
> + enum object_type *saved_typep = data->info.typep;
> + data->info.typep = &data->type;
> opt->batch_mode = BATCH_MODE_CONTENTS;
> batch_one_object(line, output, opt, data);
> + data->info.typep = saved_typep;
> }
>
> static void parse_cmd_info(struct batch_options *opt,
> diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh
> index 762c77c351..f085738082 100755
> --- a/t/t1006-cat-file.sh
> +++ b/t/t1006-cat-file.sh
> @@ -1351,6 +1351,14 @@ test_expect_success 'batch-command flush without --buffer' '
> test_grep "^fatal:.*flush is only for --buffer mode.*" err
> '
>
> +test_expect_success 'batch-command contents auto-handles type' '
> + echo "HEAD" |
> + git cat-file --batch="%(objectname)" >expect &&
> + echo "contents HEAD" |
> + git cat-file --batch-command="%(objectname)" >actual &&
> + test_cmp expect actual
> +'
> +
> perl_script='
> use warnings;
> use strict;
prev parent reply other threads:[~2026-07-28 17:36 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-27 9:30 Assertion failure with git cat-file --batch-command Alan Stokes
2026-07-27 9:57 ` Jeff King
2026-07-27 20:26 ` Pablo Sabater
2026-07-28 9:08 ` Alan Stokes
2026-07-28 15:00 ` [PATCH] cat-file: handle content request for --batch-command without type Jeff King
2026-07-28 17:36 ` Junio C Hamano [this message]
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=xmqqjyqfdnie.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=alan@source.dev \
--cc=git@vger.kernel.org \
--cc=pabloosabaterr@gmail.com \
--cc=peff@peff.net \
/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