Files
DIY_GIT_in_Python/how_to/Change_27.md

906 B
Raw Blame History

  • k: Iterate commits and parents

In addition to printing the refs, well also print all OIDs that are reachable from those refs. Well create iter_commits_and_parents, which is a generator that returns all commits that it can reach from a given set of OIDs.

Note that iter_commits_and_parents will return an OID once, even if its reachable from multiple refs. Here, for example:

o<----o<----o<----o<----@<----@<----@
^                  \                ^
first commit        -<--$<----$     refs/tags/tag1
                              ^
                              refs/tags/tag2

We can reach the first commit by following the parents of tag1 or by following the parents of tag2. Yet if we call iter_commits_and_parents({tag1, tag2}), the first commit will be yielded only once. This property will be useful later.

(Note that nothing is visualized yet, were preparing for that.)