Gitility.OID (Gitility v0.4.0)

Copy Markdown View Source

A Git object identifier: a hash algorithm plus the raw digest bytes.

Every OID in Gitility carries its algorithm explicitly — nothing in the library assumes 20-byte digests. Query execution is SHA-1-only until the engine's SHA-256 support lands, but every type, cursor, and protocol is hash-agnostic from day one.

Public functions accept full lowercase or uppercase hex strings as a convenience, but Gitility always returns typed OIDs.

iex> {:ok, oid} = Gitility.OID.parse("da39a3ee5e6b4b0d3255bfef95601890afd80709")
iex> oid.algorithm
:sha1
iex> Gitility.OID.to_string(oid)
"da39a3ee5e6b4b0d3255bfef95601890afd80709"

Summary

Types

Supported Git object hash algorithms.

t()

A typed object ID: algorithm plus raw digest bytes.

Functions

The digest size in bytes for algorithm.

Builds an OID from an algorithm and raw digest bytes.

Like new/2 but raises Gitility.Error on invalid input.

Parses a full hex object ID string, inferring the algorithm from length (40 hex chars → SHA-1, 64 → SHA-256). Accepts upper or lower case.

Like parse/1 but raises Gitility.Error on invalid input.

Formats an OID as a lowercase hex string.

Types

algorithm()

@type algorithm() :: :sha1 | :sha256

Supported Git object hash algorithms.

t()

@type t() :: %Gitility.OID{algorithm: algorithm(), bytes: binary()}

A typed object ID: algorithm plus raw digest bytes.

Functions

digest_size(algorithm)

@spec digest_size(algorithm()) :: pos_integer()

The digest size in bytes for algorithm.

new(algorithm, bytes)

@spec new(algorithm(), binary()) :: {:ok, t()} | {:error, Gitility.Error.t()}

Builds an OID from an algorithm and raw digest bytes.

Returns {:error, %Gitility.Error{code: :invalid_oid}} if the byte size does not match the algorithm's digest size.

new!(algorithm, bytes)

@spec new!(algorithm(), binary()) :: t()

Like new/2 but raises Gitility.Error on invalid input.

parse(hex)

@spec parse(String.t()) :: {:ok, t()} | {:error, Gitility.Error.t()}

Parses a full hex object ID string, inferring the algorithm from length (40 hex chars → SHA-1, 64 → SHA-256). Accepts upper or lower case.

Abbreviated IDs are not accepted here; only stores that can prove uniqueness resolve prefixes (see Gitility.ODB).

parse!(hex)

@spec parse!(String.t()) :: t()

Like parse/1 but raises Gitility.Error on invalid input.

to_string(oid)

@spec to_string(t()) :: String.t()

Formats an OID as a lowercase hex string.