Implement log
This commit is contained in:
27
ugit/base.py
27
ugit/base.py
@@ -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("/")
|
||||
|
||||
Reference in New Issue
Block a user