log is the payoff of the commit graph: start at HEAD and follow parent links back through history. Today you walk the chain and list commits newest first.
Walk from HEAD through parent links, listing commit ids newest to oldest.
log is where the graph you have been building becomes visible. Resolve HEAD to a
commit, then walk: read the commit, emit its id, follow its first parent, and
repeat until you reach a commit with no parent. That yields history newest first,
which is how git log presents it. The traversal is pure graph-walking over
objects you can already read.
Following only the first parent keeps this linear, which is all a simple history
needs; a merge commit’s other parents would branch the walk, but our chain has
none. The stopping condition is the parentless root commit, and getting that right
means the walk terminates cleanly instead of dereferencing an empty parent. Two
commits in, Log() returns 9bae7f0a... then f18e98d3..., the same order and
ids git log --format=%H prints.
// start at Resolve("HEAD"); ReadCommit; emit; follow parents[0]; repeatfunc (r *Repo) Log() ([]string, error) {id, _ := r.Resolve("HEAD")for id != "" {// append id; c, _ := r.ReadCommit(id)// id = first parent, or "" if none}}