Skip to content

Commit 8ab427b

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 fc02a24 commit 8ab427b

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
@@ -144,8 +144,25 @@ def _rev_parse(repo: Any, args: List[str], kwargs: Dict[str, Any]) -> bytes:
144144
return str(_oid(repo, args[-1])).encode("ascii") + b"\n"
145145

146146

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

151168

0 commit comments

Comments
 (0)