First, one obtains a list of commits (as with git rev-list
), and parents of each commit. A “column reservation list” is kept in memory.
For each commit then:
- If the commit has no column reserved for it, assign it to a free column. This is how the branch heads will start.
- Print the tree graphics according to the column reservation list, and then the commit message
- The reservation’s list entry for the current column/commit is updated with the first parent of the current commit, such that the parent is going to be printed in the same column.
- Other parents get a new free column.
- If this was a merge, the next line will try to link the second parent to a column where the commit is expected (this makes for the loops and the “≡ bridge”)
Example showing output of git-forest
on aufs2-util with an extra commit to have more than one branch).
With lookahead, one can anticipate how far down the merge point will be and squeeze the wood between two columns to give a more aesthetically pleasing result.