hare-git +x86_64 +linux

git provides an incomplete implementation of Git.

Index

Types

type blob;
type commit;
type hash_alg;
type ident;
type object;
type objtype;
type oid;
type repo;
type tag;
type tree;
type tree_entry;

Errors

type error;

Functions

fn blob_finish(b: blob) void;
fn blob_parse(body: []u8) (blob | nomem);
fn blob_serialize(b: blob) ([]u8 | nomem);
fn commit_finish(c: commit) void;
fn commit_parse(r: repo, body: []u8) (commit | errors::invalid | strconv::invalid | strconv::overflow | utf8::invalid | nomem);
fn commit_serialize(c: commit) ([]u8 | nomem);
fn ident_finish(p: ident) void;
fn ident_serialize(p: ident) ([]u8 | nomem);
fn loose_read(r: repo, id: oid) (object | fs::error | io::error | errors::invalid | strconv::invalid | strconv::overflow | nomem | utf8::invalid);
fn loose_read_typed(r: repo, id: oid) ((objtype, []u8) | fs::error | io::error | errors::invalid | errors::noentry | strconv::invalid | strconv::overflow | utf8::invalid | nomem);
fn object_finish(o: object) void;
fn object_read(r: repo, id: oid) (object | fs::error | io::error | errors::invalid | strconv::invalid | strconv::overflow | nomem);
fn object_serialize(o: object) ([]u8 | errors::invalid | nomem);
fn object_verify_oid(r: repo, buf: []u8, want: oid) (bool | nomem);
fn object_verify_typed(r: repo, ty: objtype, body: []u8, want: oid) (bool | nomem);
fn oid_equal(a: oid, b: oid) bool;
fn oid_len(id: oid) size;
fn oid_parse(r: repo, s: const str) (oid | nomem | errors::invalid);
fn oid_stringify(id: oid) (const str | nomem);
fn oid_zero(sz: size) (oid | errors::invalid);
fn pack_read(r: repo, id: oid) (object | fs::error | io::error | errors::invalid | strconv::invalid | strconv::overflow | errors::noentry | utf8::invalid | nomem);
fn ref_resolve(r: repo, refname: const str) (oid | error);
fn ref_resolve_head(r: repo) (oid | error);
fn repo_close(r: repo) void;
fn repo_open(path: const str, hash_id: hash_alg) (repo | fs::error | errors::invalid);
fn tag_finish(t: tag) void;
fn tag_parse(r: repo, body: []u8) (tag | errors::invalid | strconv::invalid | strconv::overflow | utf8::invalid | nomem);
fn tag_serialize(t: tag) ([]u8 | errors::invalid | nomem);
fn tree_entry_finish(te: tree_entry) void;
fn tree_finish(t: tree) void;
fn tree_parse(r: repo, body: []u8) (tree | errors::invalid | strconv::invalid | strconv::overflow | utf8::invalid | nomem);
fn tree_resolve_path(r: repo, root: const tree, path: const []u8) (tree | blob | errors::invalid | fs::error | io::error | strconv::invalid | strconv::overflow | nomem);
fn tree_serialize(t: tree) ([]u8 | nomem);

Types

type blob[permalink]

type blob = struct {
	data: []u8,
};

A simple Git blob with its object ID and raw data.

type commit[permalink]

type commit = struct {
	tree: oid,
	parents: []oid,
	author: ident,
	committer: ident,
	message: []u8,
};

A Git commit object.

type hash_alg[permalink]

type hash_alg = enum u8 {
	SHA1 = 1,
	SHA256 = 2,
};

Hash algorithm identifiers used for object IDs.

type ident[permalink]

type ident = struct {
	name: []u8,
	email: []u8,
	when: i64,
	ofs: i32,
};

Author/committer identity and its associated timestamp and timezone offset.

type object[permalink]

type object = (blob | tree | commit | tag);

Any Git object.

type objtype[permalink]

type objtype = enum u8 {
	OBJ_INVALID = 0u8,
	OBJ_COMMIT = 1u8,
	OBJ_TREE = 2u8,
	OBJ_BLOB = 3u8,
	OBJ_TAG = 4u8,
	OBJ_FUTURE = 5u8,
	OBJ_OFS_DELTA = 6u8,
	OBJ_REF_DELTA = 7u8,
};

Object/pack type tags.

These are not typically used as we could represent objects with tagged unions. However, they may be useful in scenarios where a full object is undesirable or unavailable.

type oid[permalink]

type oid = struct {
	sz: size,
	data: [hash_max_size]u8,
};

A Git object ID, parameterized by the repository hash algorithm.

type repo[permalink]

type repo = struct {
	root: *fs::fs,
	hash_id: hash_alg,
	hash_size: size,
};

A Git repository.

type tag[permalink]

type tag = struct {
	target: oid,
	target_type: objtype,
	name: []u8,
	tagger: (void | ident),
	message: []u8,
};

A Git annotated tag object.

type tree[permalink]

type tree = struct {
	entries: []tree_entry,
};

A Git tree object.

type tree_entry[permalink]

type tree_entry = struct {
	mode: u32,
	name: []u8,
	oid: oid,
};

A single entry in a Git tree. In general, the oid either refers to a blob (file) or another tree (directory).

Errors

type error[permalink]

type error = !(fs::error | io::error | errors::invalid | strconv::invalid | strconv::overflow | utf8::invalid | nomem);

Errors possible while handling Git repositories.

Functions

fn blob_finish[permalink]

fn blob_finish(b: blob) void;

Frees resources associated with a blob.

fn blob_parse[permalink]

fn blob_parse(body: []u8) (blob | nomem);

Parses a blob from its raw data. The data is copied and the resulting blob must be finished with blob_finish.

fn blob_serialize[permalink]

fn blob_serialize(b: blob) ([]u8 | nomem);

Serializes a blob into the uncompressed on-disk format.

fn commit_finish[permalink]

fn commit_finish(c: commit) void;

Frees resources associated with a commit.

fn commit_parse[permalink]

fn commit_parse(r: repo, body: []u8) (commit | errors::invalid | strconv::invalid | strconv::overflow | utf8::invalid | nomem);

Parses a commit from its raw data and object ID.

fn commit_serialize[permalink]

fn commit_serialize(c: commit) ([]u8 | nomem);

Serializes a commit into its uncompressed on-disk format.

fn ident_finish[permalink]

fn ident_finish(p: ident) void;

Frees resources associated with an ident.

fn ident_serialize[permalink]

fn ident_serialize(p: ident) ([]u8 | nomem);

Returns the canonical form for an ident.

fn loose_read[permalink]

fn loose_read(r: repo, id: oid) (object | fs::error | io::error | errors::invalid | strconv::invalid | strconv::overflow | nomem | utf8::invalid);

Reads a loose object from the repository by its ID.

fn loose_read_typed[permalink]

fn loose_read_typed(r: repo, id: oid) ((objtype, []u8) | fs::error | io::error | errors::invalid | errors::noentry | strconv::invalid | strconv::overflow | utf8::invalid | nomem);

Reads a loose object from the repository by its ID, returning its type and raw data.

fn object_finish[permalink]

fn object_finish(o: object) void;

Frees resources associated with any Git object.

fn object_read[permalink]

fn object_read(r: repo, id: oid) (object | fs::error | io::error | errors::invalid | strconv::invalid | strconv::overflow | nomem);

Reads a Git object from the repository by its ID.

fn object_serialize[permalink]

fn object_serialize(o: object) ([]u8 | errors::invalid | nomem);

Serializes an object into its on-disk representation.

fn object_verify_oid[permalink]

fn object_verify_oid(r: repo, buf: []u8, want: oid) (bool | nomem);

Verifies that the given buffer (which must be the exact on-disk format structured as "type size\0body") matches the given object ID.

fn object_verify_typed[permalink]

fn object_verify_typed(r: repo, ty: objtype, body: []u8, want: oid) (bool | nomem);

Verifies that the given typed body matches the given object ID.

fn oid_equal[permalink]

fn oid_equal(a: oid, b: oid) bool;

Compare two object IDs for equality.

fn oid_len[permalink]

fn oid_len(id: oid) size;

Returns the length, in bytes, of an object ID.

fn oid_parse[permalink]

fn oid_parse(r: repo, s: const str) (oid | nomem | errors::invalid);

Parses a hex-encoded string representation of an oid for the given repo.

fn oid_stringify[permalink]

fn oid_stringify(id: oid) (const str | nomem);

Returns a hex-encoded string representation of the given oid. The returned string is allocated on the heap and must be freed by the caller.

fn oid_zero[permalink]

fn oid_zero(sz: size) (oid | errors::invalid);

Initialize a zeroed object ID with the given length.

fn pack_read[permalink]

fn pack_read(r: repo, id: oid) (object | fs::error | io::error | errors::invalid | strconv::invalid | strconv::overflow | errors::noentry | utf8::invalid | nomem);

Reads a packed object by its ID from the given repository.

fn ref_resolve[permalink]

fn ref_resolve(r: repo, refname: const str) (oid | error);

Resolve a Git ref to its object ID from its fully qualified ref name.

fn ref_resolve_head[permalink]

fn ref_resolve_head(r: repo) (oid | error);

Reads and resolves the HEAD ref to its object ID.

fn repo_close[permalink]

fn repo_close(r: repo) void;

Close a repository, freeing its resources.

fn repo_open[permalink]

fn repo_open(path: const str, hash_id: hash_alg) (repo | fs::error | errors::invalid);

Open a repository at the given path, using the provided hash algorithm.

The hash algorithm shall be automatically detected in the future.

fn tag_finish[permalink]

fn tag_finish(t: tag) void;

Frees resources associated with a tag.

fn tag_parse[permalink]

fn tag_parse(r: repo, body: []u8) (tag | errors::invalid | strconv::invalid | strconv::overflow | utf8::invalid | nomem);

Parses a tag from its raw data.

fn tag_serialize[permalink]

fn tag_serialize(t: tag) ([]u8 | errors::invalid | nomem);

Serializes a commit into its uncompressed on-disk format.

fn tree_entry_finish[permalink]

fn tree_entry_finish(te: tree_entry) void;

Frees resources associated with a tree_entry.

fn tree_finish[permalink]

fn tree_finish(t: tree) void;

Frees resources associated with a tree.

fn tree_parse[permalink]

fn tree_parse(r: repo, body: []u8) (tree | errors::invalid | strconv::invalid | strconv::overflow | utf8::invalid | nomem);

Parses a tree from its raw data and object ID.

fn tree_resolve_path[permalink]

fn tree_resolve_path(r: repo, root: const tree, path: const []u8) (tree | blob | errors::invalid | fs::error | io::error | strconv::invalid | strconv::overflow | nomem);

Recursively looks up a tree or blob at the given path,

fn tree_serialize[permalink]

fn tree_serialize(t: tree) ([]u8 | nomem);

Serializes a tree into its uncompressed on-disk format.