Skip to content

Commit 8303e03

Browse files
codexByron
authored andcommitted
feat(gix): find merge bases and test ancestry natively
Use the native graph operations for two-revision merge bases, all bases and ancestry checks. Preserve the existing result format and no-base/non-ancestor status. Octopus, fork-point and other options retain the CLI implementation. 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.10s.
1 parent 95cf3e5 commit 8303e03

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

‎git/_backend.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,31 @@ def describe(local: Any) -> List[bytes]:
246246
return b"".join(records)
247247

248248

249+
def _merge_base(repo: Any, args: List[str], kwargs: Dict[str, Any]) -> bytes:
250+
if not hasattr(repo, "merge_base"):
251+
raise _Unsupported("revision feature disabled")
252+
ancestor = args[:1] == ["--is-ancestor"]
253+
if ancestor:
254+
args = args[1:]
255+
if len(args) != 3 or args[0] != "--":
256+
raise _Unsupported("merge-base options")
257+
one, two = (_oid(repo, value) for value in args[1:])
258+
if kwargs.get("all"):
259+
ids = repo.merge_bases_many(one, [two])
260+
else:
261+
base = repo.merge_base(one, two)
262+
ids = [base] if base is not None else []
263+
if not ids or (ancestor and ids[0] != one):
264+
raise GitCommandError(["git", "merge-base"], 1)
265+
return b"" if ancestor else b"".join(str(oid).encode("ascii") + b"\n" for oid in ids)
266+
267+
249268
_HANDLERS: Dict[str, Callable[[Any, List[str], Dict[str, Any]], bytes]] = {
250269
"rev_parse": _rev_parse,
251270
"ls_tree": _ls_tree,
252271
"symbolic_ref": _symbolic_ref,
253272
"for_each_ref": _for_each_ref,
273+
"merge_base": _merge_base,
254274
"config": _config,
255275
"worktree": _worktree,
256276
}

0 commit comments

Comments
 (0)