Re: Pretty output in JSON format
- From
Ron Ziroby Romero <ziroby@gmail.com>
- Date
- Aug 4, 2025, 20:39 UTC
- Message-ID
- <CAGW8g7kMVqsi6+JkdjDS-czKJQ=01ULUz36sZrGom+QPVtRF3A@mail.gmail.com>
- In-Reply-To
- <CANgJU+Xs-sQgAOCPL-5skaZGq7eHmhg0MaFGDr8N57=CK67iog@mail.gmail.com>
On Fri, 27 Sept 2024 at 10:30, demerphq <demerphq@gmail.com> wrote:
Show 30 quoted lines
> > On Thu, 26 Sept 2024 at 23:04, brian m. carlson <sandals@crustytoothpaste.net> wrote: >> >> On 2024-09-25 at 18:45:54, Sean Allred wrote: >> > "brian m. carlson" <sandals@crustytoothpaste.net> writes: >> > >> > > On 2024-09-24 at 21:52:35, Ron Ziroby Romero wrote: >> > >> What do y'all think? >> > > >> > > I think this is ultimately a bad idea. JSON requires that the output be >> > > UTF-8, but Git processes a large amount of data, including file names, >> > > ref names, commit messages, author and committer identities, diff >> > > output, and other file contents, that are not restricted to UTF-8. >> > >> > This strikes me with a little bit of 'perfect as the enemy of good' >> > here. I'm sure there are ways to signal an encoding failure. I would, >> > however, caution against trying to provide diff output in JSON. That >> > just seems... odd. Maybe base64 it first? (I don't know -- I just >> > struggle to see the use-case here.) >> >> I understand JSON output would be useful, but it's also not useful to >> randomly fail to do git for-each-ref (for example) because someone has a >> non-UTF-8 ref, or to fail to do a git log because of encoding problems > > > I dont really follow your argument, and I find it weird how you are talking about a specific encoding of unicode instead of Unicode itself. > > It is possible to represent every binary string as Unicode encoded as UTF-8 (or any of the UTF encodings). It may not be bytewise equivalent with the original, but why should that matter? There are a set of clear rules for doing the required transformations, and there is a huge body of tooling to do so. As long as you know the target encoding, you should be able to round trip data properly. > > IMO CBOR would just complicate what should be a relatively simple problem to solve.
Hi. I've been working with the code and trying to figure out how to do this. I've also started work on a formal proposal. Two things have come up that I wanted to discuss:
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? This would also go hand in hand with changing from "--pretty=json" to simply "--json"
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.
## References
[1] Patrick Steinhardt, “Re: [PATCH] diff: add --json output format,” message to git@vger.kernel.org, July 29, 2025. https://public-inbox.org/git/pull.1937.git.1753856826464.gitgitgadget@gmail.com/
Show 8 quoted lines
> > cheers, > Yves > > > > -- > perl -Mre=debug -e "/just|another|perl|hacker/"
Cheers, Ziroby Ron Romero