Source file: Modules/graph.py
Modules/graph.py provides ancestry helpers for commit traversal, branch comparison, and merge-base discovery. Leaf stores commits in log.json, but graph operations are easier after that list is converted into a dictionary keyed by commit ID.
Leaf supports both legacy single-parent metadata and modern multi-parent metadata:
parentstores the first parent.parentsstores all parents and is used for merge commits.
The graph helpers normalize these formats so other modules can work with a consistent parent list.
Converts the commit log list into a dictionary:
{
"commit-id": commit_metadata
}This makes lookups faster and keeps traversal code simple.
Returns a clean list of parent IDs for a commit. It prefers the parents list when present and falls back to the single parent value.
Builds a full ancestry chain from a commit ID. It follows all parents breadth-first, skips missing IDs, and avoids revisiting commits.
This is used by log output and ancestry checks.
Builds the first-parent chain only. Rebuild uses this function so file state follows the mainline sequence of commits.
Returns whether one commit appears in another commit’s ancestry. This supports merge decisions such as already-up-to-date and fast-forward checks.
Finds a common ancestor between two commits. Merge uses this base commit to compare target branch changes with source branch changes during three-way merge.
base commit
├── current branch commit
└── source branch commit
Leaf rebuilds all three states, compares each file, and either produces a clean merged file or writes conflict markers.