Live data from Hacker News

Git log in JSON format

gist.github.com

1–10 of 17 posts

Re: Git log in JSON format

#2
> What if there's a double quote in a commit message?

This is what I want to know too. Unless I'm missing something, it doesn't do any escaping. The last time I did something like this, I used %n and %x00 to delimit the output of git log, and converted it to a JavaScript object on the JavaScript side. Git log isn't smart enough to write JSON by itself.

Re: Git log in JSON format

#4
post #2

> What if there's a double quote in a commit message? This is what I want to know too. Unless I'm missing something, it doesn't do any escaping. The last time I did something like this, I used %n and %x00 to delimit the output of git log, and converted it to a JavaScript object on the JavaScript side. Git log isn't smart enough to write JSON by itself.

I did something very similar for work last summer and we basically realized the same thing - null-delimited fields seemed like the only way to really be safe.

Re: Git log in JSON format

#5
post #2

> What if there's a double quote in a commit message? This is what I want to know too. Unless I'm missing something, it doesn't do any escaping. The last time I did something like this, I used %n and %x00 to delimit the output of git log, and converted it to a JavaScript object on the JavaScript side. Git log isn't smart enough to write JSON by itself.

Agreed on better output to text, then process, but I'd suggest the record & group separators... It always surprises me when people use more exotic characters for something that's been defined forever (practically) in computer terms for this purpose.

http://www.theasciicode.com.ar/ascii-control-characters/reco...

Re: Git log in JSON format

#7
Mercurial has a properly designed extensible generic template system for that built-in.

  hg log -T json
  hg log -T xml
  hg status -T json
  hg tags -T json
  ...

Re: Git log in JSON format

#8
post #6

Every time I see people using printf to generate structured data formats, a part of me dies inside. Here's how I would do it, using libgit2 and proper JSON output: https://gist.github.com/m1el/42472327b4be382b02eb

Every time I see this pattern, a part of me dies inside.

    collection = []
    for i in data:
        collection.append(fn(i))
Why not just

    [fn(i) for i in data] ?

Re: Git log in JSON format

#9
post #6

Every time I see people using printf to generate structured data formats, a part of me dies inside. Here's how I would do it, using libgit2 and proper JSON output: https://gist.github.com/m1el/42472327b4be382b02eb

Every time I see this pattern, a part of me dies inside. collection = [] for i in data: collection.append(fn(i)) Why not just [fn(i) for i in data] ?

First example is way, WAY, more readable. Honestly, if I didn't read the first one I would probably not have figured out what the other one does without research.

Re: Git log in JSON format

#10
post #6

Every time I see people using printf to generate structured data formats, a part of me dies inside. Here's how I would do it, using libgit2 and proper JSON output: https://gist.github.com/m1el/42472327b4be382b02eb

Every time I see this pattern, a part of me dies inside. collection = [] for i in data: collection.append(fn(i)) Why not just [fn(i) for i in data] ?

If we are nitpicking then why not

    map(fn, data)

?
Post reply on HN