Use iter_commits_and_parents

This commit is contained in:
David Doblas Jiménez 2024-05-24 14:45:06 +02:00
parent 7896b80c42
commit 7fe3e0f497
2 changed files with 6 additions and 8 deletions

View File

@ -3,7 +3,7 @@ import operator
import os
import string
from collections import namedtuple
from collections import deque, namedtuple
from pathlib import Path, PurePath
from . import data
@ -130,18 +130,19 @@ def get_commit(oid):
def iter_commits_and_parents(oids):
oids = set(oids)
oids = deque(oids)
visited = set()
while oids:
oid = oids.pop()
oid = oids.popleft()
if not oid or oid in visited:
continue
visited.add(oid)
yield oid
commit = get_commit(oid)
oids.add(commit.parent)
# Return parent next
oids.appendleft(commit.parent)
def get_oid(name):

View File

@ -91,16 +91,13 @@ def commit(args):
def log(args):
oid = args.oid
while oid:
for oid in base.iter_commits_and_parents({args.oid}):
commit = base.get_commit(oid)
print(f"commit {oid}\n")
print(textwrap.indent(commit.message, " "))
print("")
oid = commit.parent
def checkout(args):
base.checkout(args.oid)