2.0 KiB · text 5af55d9
defmodule GitGud.Git.Nif do
@moduledoc """
gitoxide-backed git backend via Rustler.
The Rust crate at `native/gitgud_gix` provides the actual NIFs. The
stubs below are replaced at load time by Rustler with the real
implementations from `native/gitgud_gix/src/lib.rs`.
Not every operation has a gix implementation yet — see the module
source. The facade `GitGud.Git` does NOT auto-fall back per-call; if
the NIF backend is selected but a specific NIF returns
`{:error, :unsupported}`, the caller is expected to handle it (and
in practice the facade routes through one backend at a time).
"""
@behaviour GitGud.Git.Backend
use Rustler, otp_app: :git_gud, crate: "gitgud_gix"
# The functions below act as stubs the NIF overrides at load time.
# If the NIF fails to load, calling them raises :nif_not_loaded —
# which `Git.pick_backend/0` avoids by gating on `available?/0`.
def nif_loaded, do: false
@impl true
def available?, do: function_exported?(__MODULE__, :nif_loaded, 0) and nif_loaded()
@impl true
def init_bare(_path), do: nif_error()
@impl true
def list_refs(_path), do: nif_error()
@impl true
def log(_path, _start_sha, _opts), do: nif_error()
@impl true
def commit(_path, _sha), do: nif_error()
@impl true
def tree(_path, _sha), do: nif_error()
@impl true
def blob_bytes(_path, _sha), do: nif_error()
@impl true
def blob_meta(_path, _sha), do: nif_error()
@impl true
def diff_stats(_path, _base, _head), do: nif_error()
@impl true
def diff(_path, _base, _head, _opts), do: {:error, :unsupported}
@impl true
def resolve(_path, _ref_or_sha), do: nif_error()
@impl true
def merge_base(_path, _a, _b), do: nif_error()
@impl true
def merge_tree(_path, _base, _a, _b), do: nif_error()
@impl true
def commit_tree(_path, _tree_sha, _parents, _message, _opts), do: nif_error()
@impl true
def update_ref(_path, _ref, _new_sha, _expected_old), do: nif_error()
defp nif_error, do: :erlang.nif_error(:nif_not_loaded)
end