Given a git repository, the commits can be thought of as having the structure of a directed acyclic graph (DAG) with the commits being the vertices. There is a directed edge from each child commit to each of its parent commits, and a directed edge from each parent to each of its children.
The shell script:
- Discovers the .git directory.
- Gets the list of local branch names.
- Builds the commit graph. Each commit can be represented as an instance of the CommitNode class, which is defined as follows:
class CommitNode:
def __init__(self, commit_hash):
"""
:type commit_hash: str
"""
self.commit_hash = commit_hash
self.parents = set()
self.children = set()
- Generates a topological ordering of the commits in the graph.
- Prints the commit hashes in order.