Subject: Re: Pretty output in JSON format

From: Junio C Hamano <[email-masked]>
Date: Mon, 04 Aug 2025 14:19:08 -0700

Ron Ziroby Romero <[email-masked]> 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.