Implement log

This commit is contained in:
2024-03-20 19:43:58 +01:00
parent 78044a877a
commit cd91f18da6
2 changed files with 44 additions and 3 deletions

View File

@@ -1,6 +1,10 @@
from pathlib import Path, PurePath
import itertools
import operator
import os
from collections import namedtuple
from pathlib import Path, PurePath
from . import data
@@ -93,5 +97,26 @@ def commit(message):
return oid
Commit = namedtuple("Commit", ["tree", "parent", "message"])
def get_commit(oid):
parent = None
commit = data.get_object(oid, "commit").decode()
lines = iter(commit.splitlines())
for line in itertools.takewhile(operator.truth, lines):
key, value = line.split(" ", 1)
if key == "tree":
tree = value
elif key == "parent":
parent = value
else:
assert False, f"Unknown field {key}"
message = "\n".join(lines)
return Commit(tree=tree, parent=parent, message=message)
def is_ignored(path):
return ".ugit" in path.split("/")