How does 'git log --graph' or 'hg graphlog' work?

后端 未结 4 1818
一向
一向 2020-12-04 23:57

I know that the history in Git is stored in a data structure called a DAG. I\'ve heard about DFS and know it\'s somewhat related.

I\'m curious, how do programs such

4条回答
  •  一向
    一向 (楼主)
    2020-12-05 00:25

    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.

提交回复
热议问题