Skip to content

Commit 9010ac9

Browse files
codexByron
authored andcommitted
feat(gix): enumerate tree entries natively
Implement the managed full-tree NUL listing with native tree entries. Preserve Git's octal modes, object kinds, IDs and raw filename bytes for the existing tree parser. Other listing options continue through Git. The staged version passes Ruff and Python syntax checks. Its SHA-1/SHA-256 native smoke and focused pytest selection pass: 26 passed in 3.86s.
1 parent 9669742 commit 9010ac9

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

‎git/_backend.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,25 @@ def _rev_parse(repo: Any, args: List[str], kwargs: Dict[str, Any]) -> bytes:
148148
return str(_oid(repo, args[-1])).encode("ascii") + b"\n"
149149

150150

151+
def _ls_tree(repo: Any, args: List[str], kwargs: Dict[str, Any]) -> bytes:
152+
if len(args) != 3 or args[:2] != ["-z", "--full-tree"]:
153+
raise _Unsupported("tree options")
154+
with repo.find_tree(_oid(repo, args[2])).iter() as entries:
155+
return b"".join(
156+
b"%06o %s %s\t%s\0"
157+
% (
158+
entry.mode(),
159+
b"tree" if entry.kind() == "tree" else b"commit" if entry.kind() == "commit" else b"blob",
160+
str(entry.id()).encode("ascii"),
161+
entry.filename(),
162+
)
163+
for entry in entries
164+
)
165+
166+
151167
_HANDLERS: Dict[str, Callable[[Any, List[str], Dict[str, Any]], bytes]] = {
152168
"rev_parse": _rev_parse,
169+
"ls_tree": _ls_tree,
153170
}
154171

155172

0 commit comments

Comments
 (0)