Skip to content

Commit c6b2272

Browse files
codexByron
authored andcommitted
feat(gix): enumerate reference names natively
List native reference names in Git's order for the managed `for-each-ref` format and literal prefixes. Keep glob patterns, pseudo refs and other formats on the CLI rather than interpreting them as plain prefixes. The staged version passes Ruff and Python syntax checks. Its SHA-1/SHA-256 native smoke and focused pytest selection pass: 6 passed in 1.88s.
1 parent a8e1f5b commit c6b2272

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

‎git/_backend.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,29 @@ def _symbolic_ref(repo: Any, args: List[str], kwargs: Dict[str, Any]) -> bytes:
172172
return target + b"\n"
173173

174174

175+
def _for_each_ref(repo: Any, args: List[str], kwargs: Dict[str, Any]) -> bytes:
176+
if not args or args[0] != "--format=%(refname)":
177+
raise _Unsupported("reference format/options")
178+
split = args.index("--") if "--" in args else len(args)
179+
if args[1:split] or len(args[split + 1 :]) > 1:
180+
raise _Unsupported("root refs or reference options")
181+
prefix = os.fsencode(args[-1]) if len(args) > split + 1 else b""
182+
if any(char in prefix for char in b"*?["):
183+
raise _Unsupported("reference glob patterns")
184+
with repo.references().all() as refs:
185+
names = [ref.name() for ref in refs]
186+
return b"".join(
187+
name + b"\n"
188+
for name in sorted(names)
189+
if not prefix or name == prefix or name.startswith(prefix.rstrip(b"/") + b"/")
190+
)
191+
192+
175193
_HANDLERS: Dict[str, Callable[[Any, List[str], Dict[str, Any]], bytes]] = {
176194
"rev_parse": _rev_parse,
177195
"ls_tree": _ls_tree,
178196
"symbolic_ref": _symbolic_ref,
197+
"for_each_ref": _for_each_ref,
179198
}
180199

181200

0 commit comments

Comments
 (0)