

Git log in JSON format - adonisk
https://gist.github.com/varemenos/e95c2e098e657c7688fd

======
m1el
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](https://gist.github.com/m1el/42472327b4be382b02eb)

~~~
jaseemabid
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] ?

~~~
zokier
If we are nitpicking then why not

    
    
        map(fn, data)
    
    ?

~~~
bpicolo
List comprehensions are more direct, support more than just a function call,
and in py3 map returns an iterable instead of a list (granted, easily solvable
by list(map()) but it's an extra concern)

List comprehensions are the very recommended strategy for constructing python
lists, not to mention they're simply a fantastic language feature. Very
direct, readable, and hard to get wrong.

Python loses out a lot on it's functional sorts of functions (filter, map)
because you can't use method chaining on a list for them, imo

------
rossy
> 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.

~~~
tracker1
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...](http://www.theasciicode.com.ar/ascii-control-
characters/record-separator-ascii-code-30.html)

------
pjtr
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
      ...

------
lowmagnet
Only somewhat related, the really neat tool code-maat[0] can do a lot with
your commit data, but it uses plain CSV. It provides a bunch of canned reports
you can run on your repo as well.

[0] [https://github.com/adamtornhill/code-
maat](https://github.com/adamtornhill/code-maat)

