Re: [PATCH] [GSOC] cat-file: fix --batch report changed-type bug
- From
Jeff King <peff@peff.net>
- Date
- May 31, 2021, 14:44 UTC
- Message-ID
- <YLT2UfCZyQIXWIOv@coredump.intra.peff.net>
- In-Reply-To
- <CAOLTT8Q0zbxh8X03ZmgAzHadTbE4-Af+AB3POOUF2n22u8RExw@mail.gmail.com>
On Mon, May 31, 2021 at 09:20:34PM +0800, ZheNing Hu wrote:
Show 5 quoted lines
> > But I think we'd want to solve it by swapping the two conditionals I > > showed above, which restores the assumption made in print_object_or_die(). > > This method is correct. This will ensure that skip_object_info will not > be set when print_contents is set.
OK, good, it sounds like we are on the same page. :)
> By the way, maybe we can merge this two "if (opt->all_objects)" block to one. > [...]
Yes, I think that would make sense to do. It might be worth doing as a separate patch on top of the bug-fix, though, to make it clear that it's just cosmetic and separate from the bug-fix.
Show 13 quoted lines
> > > +test_expect_success 'cat-file --batch="batman" with --batch-all-objects will work' ' > > > + git -C all-two cat-file --batch-all-objects --batch="%(objectname)" | wc -l >expect && > > > + git -C all-two cat-file --batch-all-objects --batch="batman" | wc -l >actual && > > > + test_cmp expect actual > > > +' > > > > Is it worth testing both of these? The %(objectname) one will fail in > > the same way (because we do not need to run oid_object_info() to get the > > oid, which we already have). I'm OK doing both for better coverage, but > > it may be worth mentioning either in a comment or in the commit message > > that we expect both to fail, and why. > > Yes, these damages need to be pointed out in the commit message.
I think what confused me here is that you are using "%(objectname)" as the "expect" output, but it also exhibits the bug. So I'd expect this test to pass even before your patch (though I didn't try it).
Really, the symptom of the bug is that _neither_ of those cat-file invocations will exit with a success code. But because they're on the left-hand side of a pipe, we wouldn't even notice.
The simplest test is just:
git -C all-two cat-file --batch-all-objects --batch="%(objectname)" >/dev/null
which will currently fail. It would be nice to verify that its output is sensible, but I'm not sure how to easily do that (it will spew a bunch of binary tree data, and it cannot even be parsed reliably since we haven't output the sizes).
-Peff