Skip to content

Commit 7a90cc1

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 9f91902 commit 7a90cc1

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
@@ -242,11 +242,31 @@ def describe(local: Any) -> List[bytes]:
242242
return b"".join(records)
243243

244244

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

0 commit comments

Comments
 (0)