Re: Pretty output in JSON format
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Aug 4, 2025, 21:19 UTC
- Message-ID
- <xmqqldny4wfn.fsf@gitster.g>
- In-Reply-To
- <CAGW8g7kMVqsi6+JkdjDS-czKJQ=01ULUz36sZrGom+QPVtRF3A@mail.gmail.com>
Ron Ziroby Romero <ziroby@gmail.com> writes:
> First, I'm questioning my approach of hacking pretty.c with a series > of 'if json' blocks. Would it be better to make a new file, > json-log.c, and divorce myself from the pretty flow entirely?
The same question to the other thread applies: why json?
If the objective is to give a parseable output for machines to robustly read, then I do not think you want to use any of the infrastructure laid by and for the pretty_print_commit() function, whose purpose is quite the opposite, like squeezing inter paragraph spaces, trimming trailing whitespaces, indenting even an empty line by 4 spaces, etc., etc.
> Second, I see that someone is adding a --json flag to git status[1]. I > figure that argues for git log to use the --json flag. I don't think > that affects me other than making the case for this JSON output.
Please don't.
That other thread is getting discouraged from introducing a new option just for a single new format. Unfortunately "status" does not have the --format={short,long,...} so we need to add one new option to allow new formats to be added in a more generic way, but once that is done, the next new format would not have to add a new option. Compared to it, "log" already has --pretty={...}, so we do not have to add --json just for this single format, which makes us luckier than the other thread.