Skip to content

Commit 788f059

Browse files
codexByron
authored andcommitted
feat(gix): read index entries natively
Serialize native index entries into the existing staged NUL-listing format, preserving stage, mode, object ID, assume-valid and skip-worktree flags. Custom, relative and sparse index paths fall back because the current binding cannot load or expand them with the required semantics (GIX-3/4). The staged version passes Ruff and Python syntax checks. Its SHA-1/SHA-256 native smoke and focused pytest selection pass: 5 passed in 1.10s.
1 parent 21b54a7 commit 788f059

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

‎git/_backend.py‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,12 +319,42 @@ def history(command: Any, rev: str, paths: Any, options: Dict[str, Any], *, coun
319319
return result
320320

321321

322+
def _index(repo: Any, kwargs: Dict[str, Any]) -> Any:
323+
if not hasattr(repo, "index_or_empty"):
324+
raise _Unsupported("index feature disabled")
325+
path = kwargs.get("env", {}).get("GIT_INDEX_FILE", os.environ.get("GIT_INDEX_FILE"))
326+
if path and not os.path.isabs(path):
327+
raise _Unsupported("relative index path")
328+
if path and os.path.abspath(path) != os.path.abspath(repo.index_path()):
329+
raise _Unsupported("custom index path (GIX-3)")
330+
index = repo.index_or_empty()
331+
if index.is_sparse():
332+
raise _Unsupported("sparse index (GIX-4)")
333+
return index
334+
335+
336+
def _ls_files(repo: Any, args: List[str], kwargs: Dict[str, Any]) -> bytes:
337+
if args != ["--stage", "-v", "-z", "--full-name"]:
338+
raise _Unsupported("index listing options")
339+
with _index(repo, kwargs).entries() as entries:
340+
output = []
341+
for entry in entries:
342+
flag = b"S" if entry.flags & (1 << 30) else b"M" if entry.stage() else b"H"
343+
if entry.flags & (1 << 15):
344+
flag = flag.lower()
345+
output.append(
346+
b"%s %06o %s %d\t%s\0" % (flag, entry.mode, str(entry.id).encode("ascii"), entry.stage(), entry.path())
347+
)
348+
return b"".join(output)
349+
350+
322351
_HANDLERS: Dict[str, Callable[[Any, List[str], Dict[str, Any]], bytes]] = {
323352
"rev_parse": _rev_parse,
324353
"ls_tree": _ls_tree,
325354
"symbolic_ref": _symbolic_ref,
326355
"for_each_ref": _for_each_ref,
327356
"merge_base": _merge_base,
357+
"ls_files": _ls_files,
328358
"config": _config,
329359
"worktree": _worktree,
330360
}

0 commit comments

Comments
 (0)