MrRontgen
MrRontgen

Reputation: 132

How to parse commit tree from git log?

I want to retrieve commit tree of some repo using only git log output. To get log I use following command:

git log --parents --all --source --numstat

My output looks like (just omit unnecessary metadata):

commit e32c46de36343a0cdad2eac18b5167c0a2831f4d 55dae2809b9e8484ab2466adb6cbed0b1a48fbc9 c070bfc4ed1610d12a1500e307f1323ce9f91653 refs/origin/some_branch
Date:   <commit date>

commit 6d5b6ed00daea7abbb1643cbdd6d2c9d12b5c10a eb539e82860c8c56d18a57e1121d691484aa62cf refs/tags/one_more_tag
Date:   <commit date>

What should be the algorithm to correctly retrieve commit tree?

Upvotes: 1

Views: 559

Answers (1)

torek
torek

Reputation: 489083

The %P style parent hashes from git log give you the outgoing arcs for the graph, with each commit's hash (%H) giving you the node ID for each vertex. Using git rev-list --parents HEAD would give you more or less the minimal input needed to construct a graph:

89ea799ffcc5c8a0547d3c9075eb979256ee95b8 3505ddecbdd4a2eaf3d2aaea746dc18d7a0b6a6b 5a1f5c3060427375de30d609d72ac032516be4c2
3505ddecbdd4a2eaf3d2aaea746dc18d7a0b6a6b e539a834555583a482c780b11927b885f8777e90
e539a834555583a482c780b11927b885f8777e90 36d75581a4966f5d56403d1a01d60e4dc45a8ab0 00ec50e56d136de41f43c33f39cdbee83f3e4458
36d75581a4966f5d56403d1a01d60e4dc45a8ab0 5066a008bb6a810f908c020de02a646cf3c92f34 049e64aa5024a9fa2fbe6116d413da1ffc7f497a
...

Constructing the graph is now trivial: if you're into graph algorithms, you can see that the above is your G = <V, E> set right there. In other words, you're already done, you have the set G. The first column is all the vertices and the second and later columns are all the outgoing arcs.

Drawing the graph, however, is potentially much harder, depending on what problem(s) you want to solve. If git log --graph (perhaps with --oneline) does not do it for you, you will need to be more specific.

Upvotes: 4

Related Questions