Use iter_commits_and_parents
This commit is contained in:
@@ -3,7 +3,7 @@ import operator
|
|||||||
import os
|
import os
|
||||||
import string
|
import string
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import deque, namedtuple
|
||||||
from pathlib import Path, PurePath
|
from pathlib import Path, PurePath
|
||||||
|
|
||||||
from . import data
|
from . import data
|
||||||
@@ -130,18 +130,19 @@ def get_commit(oid):
|
|||||||
|
|
||||||
|
|
||||||
def iter_commits_and_parents(oids):
|
def iter_commits_and_parents(oids):
|
||||||
oids = set(oids)
|
oids = deque(oids)
|
||||||
visited = set()
|
visited = set()
|
||||||
|
|
||||||
while oids:
|
while oids:
|
||||||
oid = oids.pop()
|
oid = oids.popleft()
|
||||||
if not oid or oid in visited:
|
if not oid or oid in visited:
|
||||||
continue
|
continue
|
||||||
visited.add(oid)
|
visited.add(oid)
|
||||||
yield oid
|
yield oid
|
||||||
|
|
||||||
commit = get_commit(oid)
|
commit = get_commit(oid)
|
||||||
oids.add(commit.parent)
|
# Return parent next
|
||||||
|
oids.appendleft(commit.parent)
|
||||||
|
|
||||||
|
|
||||||
def get_oid(name):
|
def get_oid(name):
|
||||||
|
|||||||
@@ -91,16 +91,13 @@ def commit(args):
|
|||||||
|
|
||||||
|
|
||||||
def log(args):
|
def log(args):
|
||||||
oid = args.oid
|
for oid in base.iter_commits_and_parents({args.oid}):
|
||||||
while oid:
|
|
||||||
commit = base.get_commit(oid)
|
commit = base.get_commit(oid)
|
||||||
|
|
||||||
print(f"commit {oid}\n")
|
print(f"commit {oid}\n")
|
||||||
print(textwrap.indent(commit.message, " "))
|
print(textwrap.indent(commit.message, " "))
|
||||||
print("")
|
print("")
|
||||||
|
|
||||||
oid = commit.parent
|
|
||||||
|
|
||||||
|
|
||||||
def checkout(args):
|
def checkout(args):
|
||||||
base.checkout(args.oid)
|
base.checkout(args.oid)
|
||||||
|
|||||||
Reference in New Issue
Block a user