Compare commits
2 Commits
db7d608010
...
7fbf6640f6
| Author | SHA1 | Date | |
|---|---|---|---|
| 7fbf6640f6 | |||
| dad9077515 |
21
how_to/Change_27.md
Normal file
21
how_to/Change_27.md
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
- k: Iterate commits and parents
|
||||||
|
|
||||||
|
In addition to printing the refs, we'll also print all OIDs that are reachable
|
||||||
|
from those refs. We'll 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 it's
|
||||||
|
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, we're preparing for that.)
|
||||||
@@ -110,6 +110,14 @@ def tag(args):
|
|||||||
|
|
||||||
|
|
||||||
def k(args):
|
def k(args):
|
||||||
|
oids = set()
|
||||||
for refname, ref in data.iter_refs():
|
for refname, ref in data.iter_refs():
|
||||||
print(refname, ref)
|
print(refname, ref)
|
||||||
|
oids.add(ref)
|
||||||
|
|
||||||
|
for oid in base.iter_commits_and_parents(oids):
|
||||||
|
commit = base.get_commit(oid)
|
||||||
|
print(oid)
|
||||||
|
if commit.parent:
|
||||||
|
print("Parent", commit.parent)
|
||||||
# TODO visualize refs
|
# TODO visualize refs
|
||||||
|
|||||||
Reference in New Issue
Block a user