Re: [PATCH v7 26/30] t/helper/hexdump: add helper to print hexdump of stdin
- From
- Jeff Hostetler <git@jeffhostetler.com>
- Date
- May 24, 2022, 14:44 UTC
- Message-ID
- <1fe2e843-20d1-4ea9-7ea2-c05330da17c2@jeffhostetler.com>
- In-Reply-To
- <xmqqk0acosks.fsf@gitster.g>
On 5/23/22 5:19 PM, Junio C Hamano wrote:
Show 28 quoted lines
> "Jeff Hostetler via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
>> +int cmd__hexdump(int argc, const char **argv)
>> +{
>> + char buf[1024];
>> + ssize_t i, len;
>> +
>> + for (;;) {
>> + len = xread(0, buf, sizeof(buf));
>> + if (len < 0)
>> + die_errno("failure reading stdin");
>> + if (!len)
>> + break;
>> +
>> + for (i = 0; i < len; i++)
>> + printf("%02x ", (unsigned char)buf[i]);
>> + }
>> +
>> + return 0;
>> +}
>
> It is meant to be consumed by machine, so I do not think we would
> mind too much about a single long line, but given that consumers
> include "grep", it would probably be better to avoid emitting an
> incomplete line, especially since addition of this tool is all about
> portability across platforms.
>
> An extra putchar('\n'); after the loop would fix it easily.Yes, I should have added a final LF. I was more focused on cleaning up the test cases.
Would you prefer a send a V8 or would you be willing to push a fixup commit on top?
Jeff