gitgraph.js icon indicating copy to clipboard operation
gitgraph.js copied to clipboard

[Question] parsing a git log into an accurate graph?

Open arnotes opened this issue 5 years ago • 5 comments

Has anyone ever been successful on parsing a git log into an accurate graph using this library?

I initially started a project to make my own graph but this library somewhat starts with all branches connecting to a single root. Ive also ran into this where commits merged into its own branch formed a straight line instead of a leaf.(might have something to do with my bad algorithm)

anyway. I ditched that project but I plan to try again. but before I try again I wanna make sure that someone has actually done this before using this library

arnotes avatar Dec 15 '19 10:12 arnotes

Take a look at 4-imports.stories (https://github.com/nicoespeon/gitgraph.js/blob/master/packages/stories/src/gitgraph-react/4-imports.stories.tsx) Each storybook example starts by importing a wad of JSON representing the entire git history. Your challenge then is to take git log output and get it into this JSON format. Perhaps https://github.com/steveukx/git-js or https://github.com/steveukx/git-js or similar could yield the history. Sprinkle in a function to convert their json into gitgraph's json, and you may have a winner.

robrich avatar Jan 06 '20 05:01 robrich

https://github.com/nicoespeon/gitgraph.js/issues/277 actually shows an elegant example using https://www.npmjs.com/package/git2json, which appears to use idential JSON format. It looks like it could be cake.

robrich avatar Jan 06 '20 05:01 robrich

If it really would be so easy using git2json, then it should also be easy to put something together that can be run from the command line in a git repository to render a gitgraph.js! Maybe also providing a custom git subcommand so you could just run something along the lines ofwould be so easy using git2json, a tool to git graphjs and get a nice visual log that opens in your browser? I might see if I can take a crack at it. @arnotes do you think you'd be interested in working on that?

kinseytamsin avatar Jan 26 '20 01:01 kinseytamsin

There is apparently something similar in concept here, but from the samples I've seen I definitely like gitgraph.js's aesthetic more.

kinseytamsin avatar Jan 26 '20 01:01 kinseytamsin

blecher-at's git2json/gitline look interesting, it appears to run git log --format=..., fparse that into JSON and build the graph based on that. Another approach I can think of is instead running git log --graph --format=... and actually parsing all those | * / / characters to reconstruct branches, and transforming them into something pretty. This way, you can skip all logic and trust the cli for a nice visualization instead. I tried this approach and can recommend it, it was only a few lines of code. I'll probably put this into some sort of VSCode extension at some point (visually very much like https://github.com/mhutchie/vscode-git-graph/)

This has nothing to do with gitgraph.js anymore however, so sorry for going off topic.

phil294 avatar May 30 '22 00:05 phil294