Skip to content

Commit c43175a

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 b60c3e7 commit c43175a

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

144144

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

149166

0 commit comments

Comments
 (0)