git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Add new git-graph command

From
Adam Simpkins <adam@adamsimpkins.net>
Date
Mar 31, 2008, 18:47 UTC
Message-ID
<20080331184737.GA28412@adamsimpkins.net>
In-Reply-To
<200803312017.28354.tlikonen@iki.fi>
On Mon, Mar 31, 2008 at 08:17:28PM +0300, Teemu Likonen wrote:
Show 13 quoted lines
> Adam Simpkins kirjoitti:
> 
> > Ultimately, it would probably be better to integrate this
> > functionality into git-log, instead of having it as a standalone
> > command.  For example, a new --graph option could be added to cause
> > the graph to be displayed alongside the existing git log output.
> > However, this would require tighter integration between the graphing
> > code and the log_tree.c and pretty.c code, which I'm not all that
> > familiar with.
> 
> I just want to say that I really like your 'git graph'. I would like to 
> see it integrated to 'git log', perhaps as 'git log --pretty=graph' 
> or 'git log --graph'.
Thanks!

I was thinking more about how to add it to 'git log', and it might not be all that difficult. Instead of providing the graphing functionality as a standalone command, it could be wrapped up in the following API:

  struct graph;
  void graph_update(struct graph *graph, struct commit *commit);
  void graph_next_line(struct graph *graph, struct strbuf *sb);
  bool graph_is_commit_finished(struct graph *graph);

While walking through the commit list, graph_update() should be called once for each commit. After graph_update() has been called, graph_next_line() can then be called to format the next line of the graph into the strbuf. It should be called multiple times, until graph_is_commit_finished() returns true. Then graph_update() can be called with the next commit.

If graph_next_line() is called when graph_is_commit_finished() returns, it would simply format straight lines for each column. For example, if there were currently 3 columns, it would format "| | |". This allows graph_next_line() to be used to vertically pad the graph.

This API would allow the 'git log' code to format each line of the graph into a strbuf, and print it out in front of each line of normal log output. This way, it could work even with something like "git log --graph --pretty=full". The graph would be prefixed to the normal output, and padded vertically for as long as necessary.

I'm just not sure how difficult it will be to change the log-tree.c code to invoke graph_next_line() before each individual line of output. It certainly shouldn't be that difficult just to implement 'git log --pretty=graph', but it may be more complicated if we want to make the graphing be a boolean option that can be enabled with any --pretty format.

I might try coding it up next weekend.
-- 
Adam Simpkins
adam@adamsimpkins.net
Previous: Teemu LikonenNext: Stephen Sinclair
Message 10 of 14 in “Add new git-graph command”
  1. Add new git-graph commandAdam Simpkins, Mar 30, 2008
  2. Jakub NarebskiMar 30, 2008
  3. Adam SimpkinsMar 30, 2008
  4. Matthieu MoyMar 30, 2008
  5. Adam SimpkinsMar 30, 2008
  6. Johannes SchindelinMar 30, 2008
  7. Junio C HamanoMar 30, 2008
  8. Adam SimpkinsMar 31, 2008
  9. Teemu LikonenMar 31, 2008
  10. Adam SimpkinsMar 31, 2008
  11. Stephen SinclairApr 1, 2008
  12. Teemu LikonenApr 1, 2008
  13. Jeff KingApr 1, 2008
  14. Teemu LikonenApr 1, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.