Here's how I would do it, using libgit2 and proper JSON output: https://gist.github.com/m1el/42472327b4be382b02eb
collection = []
for i in data:
collection.append(fn(i))
Why not just [fn(i) for i in data] ?However, in this particular case, IMO, it would make things worse because I would have to write a multi-line list comprehension. Multi-line list comprehensions have bad readability. The object literal is too big to be included in list comprehension.
I could move commit->object conversion to a function, but then I would have used map. And it would have created one more indirection.
The current state is my deliberate choice.
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.
http://www.theasciicode.com.ar/ascii-control-characters/reco...
hg log -T json
hg log -T xml
hg status -T json
hg tags -T json
...