5 ms·
Git log in JSON format
- rossy 11y ago> 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.
- lmitchell 11y agoI 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.
- tracker1 11y agoAgreed 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/record-separator-ascii-code-30.html http://www.theasciicode.com.ar/ascii-control-characters/reco...
- lowmagnet 11y agoOnly 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
- m1el 11y agoEvery 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 11y agoEvery 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] ?
- wingerlang 11y agoFirst 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.
- merb 11y agoYou are kidding. The Map one exactly describe what it does. it 'maps' the data. Which means it describes it in the way function fn is telling it. Which is really easy to read if you understand english...
- wingerlang 11y ago> Which is really easy to read if you understand english Maybe I missed something, but how does this > [fn(i) for i in data] read easier if you know english? You need to know the syntax of "[...]" to know what it does. The top/first example, however, actually reads like english.
- tschuy 11y agoList comprehension are a very common thing in Python. If you knew Python you'd know exactly what that means. But zokier is right, a map is probably a better choice here.
- s_kilk 11y ago>> You need to know the syntax of "[...]" to know what it does. Anyone with even a basic understanding of python (the language of the examples we've been discussing here) should know this syntax. If they didn't I'd be worried.
- pjtr 11y agoMercurial 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 ...