Skip to content

Commit ec2e424

Browse files
codexByron
authored andcommitted
feat(gix): resolve revisions and repository metadata natively
Handle verified revisions and repository metadata exposed by GixPython. Keep Git's initial repository validation and unsupported discovery options. Message searches, dirty suffixes and describe-shaped names fall back because the native grammar differs in regex handling and exact-tag precedence (`GIX-14`/`GIX-17`). Keep `rev-parse --show-ref-format` on the CLI: GixPython 0.1.0 exposes no repository reference-storage-format getter (`GIX-1`). Rejecting reftable elsewhere is not a native query, so do not fabricate a `files` answer. This restores one CLI invocation per such query (previously zero after wrapper initialization); the fallback regression checks this explicitly. Validation: focused backend and revision tests passed with Gix first (26 passed in 18.67s), then CLI (22 passed, 1 skipped in 19.54s). Ruff lint/format and `git diff --check` passed.
1 parent 3b6be62 commit ec2e424

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

‎git/_backend.py‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,27 @@ def object_data(command: Any, ref: bytes, *, stream: bool = False) -> Any:
124124
return result
125125

126126

127-
_HANDLERS: Dict[str, Callable[[Any, List[str], Dict[str, Any]], bytes]] = {}
127+
def _rev_parse(repo: Any, args: List[str], kwargs: Dict[str, Any]) -> bytes:
128+
if args == ["--path-format=absolute", "--git-common-dir"]:
129+
return os.fsencode(os.path.abspath(repo.common_dir())) + b"\n"
130+
if args == ["--is-bare-repository"]:
131+
return b"true\n" if repo.is_bare() else b"false\n"
132+
if args == ["--show-object-format"]:
133+
return str(repo.object_hash()).encode("ascii") + b"\n"
134+
if args == ["--show-ref-format"]:
135+
raise _Unsupported("reference storage format query (GIX-1)")
136+
if args == ["--show-toplevel"] and repo.workdir() is not None:
137+
return os.fsencode(os.path.abspath(repo.workdir())) + b"\n"
138+
if args[:1] != ["--verify"] or args[-2:-1] != ["--end-of-options"]:
139+
raise _Unsupported("discovery or revision options")
140+
if args[:-2] not in (["--verify"], ["--verify", "--quiet"]):
141+
raise _Unsupported("revision options")
142+
return str(_oid(repo, args[-1])).encode("ascii") + b"\n"
143+
144+
145+
_HANDLERS: Dict[str, Callable[[Any, List[str], Dict[str, Any]], bytes]] = {
146+
"rev_parse": _rev_parse,
147+
}
128148

129149

130150
def dispatch(

‎test/test_gix_backend.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ def test_unknown_command_and_storage_environment_use_cli(repo):
3030
assert repo.git._call_process_safe("for_each_ref", "--format=%(refname)", "--", "refs/*") == "fallback"
3131
with repo.git.custom_environment(GIT_INDEX_FILE=".git/index"):
3232
assert repo.git._call_process_safe("ls_files", "--stage", "-v", "-z", "--full-name") == "fallback"
33-
assert cli.call_count == 2
33+
assert repo.git._call_process_safe("rev_parse", "--show-ref-format") == "fallback"
34+
assert cli.call_count == 3
3435

3536

3637
def test_partial_native_stream_does_not_corrupt_next_read(repo):

0 commit comments

Comments
 (0)