Re: [PATCH GSoC v3 1/8] t5701: use test_file_size() to get the size of a file
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Aug 3, 2026, 17:21 UTC
- Message-ID
- <xmqqbjbjyv9s.fsf@gitster.g>
- In-Reply-To
- <20260803-objecttype-support-v3-1-7176fecf7950@gmail.com>
Pablo Sabater <pabloosabaterr@gmail.com> writes:
Show 7 quoted lines
> The 'basics of object-info' test runs 'wc -c | xargs' twice to get the > size of two.t. The pipe to xargs is only there to strip the blanks > that some platforms pad the output of wc with. > > Use the test_file_size() helper, which outputs the size directly, and > store the result in a variable. Because 'git rev-parse two:two.t' is > also run twice, store its output in a variable as well.
It also has the benefit of retaining the exit status from commands run inside a $( ... ) construct placed within a HERE-document. Earlier, if your "git rev-parse" failed, you would not have noticed it directly (though you would probably have seen the "expect" file containing unexpected content). Now your assignment fails when you compute two_oid, if your "git rev-parse" segfaults.
Show 38 quoted lines
> Mentored-by: Karthik Nayak <karthik.188@gmail.com> > Mentored-by: Chandra Pratap <chandrapratap3519@gmail.com> > Signed-off-by: Pablo Sabater <pabloosabaterr@gmail.com> > --- > t/t5701-git-serve.sh | 11 +++++++---- > 1 file changed, 7 insertions(+), 4 deletions(-) > > diff --git a/t/t5701-git-serve.sh b/t/t5701-git-serve.sh > index 9a575aa098..51d5dd1ae6 100755 > --- a/t/t5701-git-serve.sh > +++ b/t/t5701-git-serve.sh > @@ -344,20 +344,23 @@ test_expect_success 'unexpected lines are not allowed in fetch request' ' > test_expect_success 'basics of object-info' ' > test_config transfer.advertiseObjectInfo true && > > + two_oid=$(git rev-parse two:two.t) && > + two_size=$(test_file_size two.t) && > + > test-tool pkt-line pack >in <<-EOF && > command=object-info > object-format=$(test_oid algo) > 0001 > size > - oid $(git rev-parse two:two.t) > - oid $(git rev-parse two:two.t) > + oid $two_oid > + oid $two_oid > 0000 > EOF > > cat >expect <<-EOF && > size > - $(git rev-parse two:two.t) $(wc -c <two.t | xargs) > - $(git rev-parse two:two.t) $(wc -c <two.t | xargs) > + $two_oid $two_size > + $two_oid $two_size > 0000 > EOF