Skip to content

Commit 0395092

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 48c3e0c commit 0395092

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
@@ -315,12 +315,42 @@ def history(command: Any, rev: str, paths: Any, options: Dict[str, Any], *, coun
315315
return result
316316

317317

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

0 commit comments

Comments
 (0)