git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Feature request: --format=json

From
Ddemerphq <demerphq@gmail.com>
Date
Apr 18, 2017, 11:16 UTC
Message-ID
<CANgJU+WbbF2yzg53D7NasN_nxqytOh=UoutmMPak77JhiJHx4A@mail.gmail.com>
In-Reply-To
<CAJgfmqXqfp3A+A74dfkKjQb_26ZNH9anY52-G2L5ipg=+6--2w@mail.gmail.com>
On 18 April 2017 at 10:44, Fred .Flintstone <eldmannen@gmail.com> wrote:
Show 6 quoted lines
> Well the easiest way to work with that would be JSON.
> So the best would be if Git could output the data I want in JSON format.
> Then it would be easy for me to work with data.
>
> With git rev-list and git-cat file, its not so easy to reliably parse
> that output.

Doesn't seem too hard to work with rev-list to me. As far as I can tell the following produces what you want. You need perl installed obviously, and the JSON::PP module is required, but should come bundled with recent perls.

git rev-list master --pretty=raw | perl -MJSON::PP=encode_json -ane'if(/^(\w+) (.*)/) { if ($1 eq "commit") { push @objs, $o if $o; $o={}; } $o->{$1} = $2; } else { $o->{text} .= $_; } END{ push @objs, $o if $o; for $o (@objs) { s/^ //mg, s/^\n// for $o->{text}; ($o->{message},$o->{long_message})= split /\n\n/, delete $o->{text}; } print JSON::PP->new->pretty->encode(\@objs);}'

You might consider an alternative approach than stating that working with JSON is "the easiest", especially to people who clearly are making do without it. :-)

A better argument might be that exposing data through a well defined and widely used and simple data format would trivially expand the range of projects that might interoperate with git or enhance the git ecosystem. For instance you could argue that having clean JSON output would make it easier to integrate into search engines and other indexing tools that already know how to speak JSON. Maybe a regular contributor on this list might agree with your arguments and make it happen.

Until then you can parse rev-list like the rest of us. :-)

cheers, Yves

Previous: Fred .FlintstoneNext: Sebastian Schuberth
Message 11 of 14 in “Feature request: --format=json”
  1. Fred .FlintstoneApr 8, 2017
  2. Ævar Arnfjörð BjarmasonApr 8, 2017
  3. Junio C HamanoApr 17, 2017
  4. Fred .FlintstoneApr 17, 2017
  5. Duy NguyenApr 17, 2017
  6. Fred .FlintstoneApr 17, 2017
  7. Junio C HamanoApr 18, 2017
  8. Fred .FlintstoneApr 18, 2017
  9. Samuel LijinApr 18, 2017
  10. Fred .FlintstoneApr 18, 2017
  11. demerphqApr 18, 2017
  12. Sebastian SchuberthApr 17, 2017
  13. Duy NguyenApr 24, 2017
  14. shawn wilsonApr 24, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.