git
git provides an incomplete implementation of Git.
Currently, only the SHA-256 object format is supported, as we wish to encourage its adoption.
Index
Types
type blob = struct {
data: []u8,
};
type commit = struct {
tree: oid,
parents: []oid,
author: ident,
committer: ident,
message: []u8,
};
type error = (fs::error | io::error | errors::invalid | strconv::invalid | strconv::overflow | utf8::invalid | nomem);
type ident = struct {
name: []u8,
email: []u8,
when: i64,
ofs: i32,
};
type object = (blob | tree | commit | tag);
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,
};
type oid = [sha256::SZ]u8;
type repo = struct {
root: *fs::fs,
};
type tag = struct {
target: oid,
target_type: objtype,
name: []u8,
tagger: (void | ident),
message: []u8,
};
type tree = struct {
entries: []tree_entry,
};
type tree_entry = struct {
mode: u32,
name: []u8,
oid: oid,
};
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(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 | nomem);
fn loose_write(r: repo, o: object) (oid | fs::error | io::error | errors::invalid | nomem);
fn loose_write_typed(r: repo, ty: objtype, body: []u8) (oid | fs::error | io::error | errors::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(buf: []u8, want: oid) bool;
fn object_verify_typed(ty: objtype, body: []u8, want: oid) bool;
fn oid_parse(s: const str) (oid | nomem | errors::invalid);
fn oid_stringify(id: oid) (const str | nomem);
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) (repo | fs::error);
fn tag_finish(t: tag) void;
fn tag_parse(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(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);
fn walk_recent_commits(r: repo, start: oid, limit: int) ([]commit | error);
Types
type blob
type blob = struct {
data: []u8,
};
A simple Git blob with its object ID and raw data.
type commit
type commit = struct {
tree: oid,
parents: []oid,
author: ident,
committer: ident,
message: []u8,
};
A Git commit object.
type error
type error = (fs::error | io::error | errors::invalid | strconv::invalid | strconv::overflow | utf8::invalid | nomem);
Errors possible while handling Git repositories.
type ident
type ident = struct {
name: []u8,
email: []u8,
when: i64,
ofs: i32,
};
Author/committer identity and its associated timestamp and timezone offset.
type object
type object = (blob | tree | commit | tag);
Any Git object.
type objtype
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
type oid = [sha256::SZ]u8;
A Git object ID. Currently, only SHA-256 is supported.
type repo
type repo = struct {
root: *fs::fs,
};
A Git repository.
type tag
type tag = struct {
target: oid,
target_type: objtype,
name: []u8,
tagger: (void | ident),
message: []u8,
};
A Git annotated tag object.
type tree
type tree = struct {
entries: []tree_entry,
};
A Git tree object.
type tree_entry
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).
Functions
fn blob_finish
fn blob_finish(b: blob) void;
Frees resources associated with a blob.
fn blob_parse
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
fn blob_serialize(b: blob) ([]u8 | nomem);
Serializes a blob into the uncompressed on-disk format.
fn commit_finish
fn commit_finish(c: commit) void;
Frees resources associated with a commit.
fn commit_parse
fn commit_parse(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
fn commit_serialize(c: commit) ([]u8 | nomem);
Serializes a commit into its uncompressed on-disk format.
fn ident_finish
fn ident_finish(p: ident) void;
Frees resources associated with an ident.
fn ident_serialize
fn ident_serialize(p: ident) ([]u8 | nomem);
Returns the canonical form for an ident.
fn loose_read
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
fn loose_read_typed(r: repo, id: oid) ((objtype, []u8) | fs::error | io::error | errors::invalid | errors::noentry | strconv::invalid | strconv::overflow | nomem);
Reads a loose object from the repository by its ID, returning its type and raw data.
fn loose_write
fn loose_write(r: repo, o: object) (oid | fs::error | io::error | errors::invalid | nomem);
Writes a loose object, returning the new ID.
fn loose_write_typed
fn loose_write_typed(r: repo, ty: objtype, body: []u8) (oid | fs::error | io::error | errors::invalid | nomem);
Writes a loose object given its type tag and raw body, returning the new ID.
fn object_finish
fn object_finish(o: object) void;
Frees resources associated with any Git object.
fn object_read
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
fn object_serialize(o: object) ([]u8 | errors::invalid | nomem);
Serializes an object into its on-disk representation.
fn object_verify_oid
fn object_verify_oid(buf: []u8, want: oid) bool;
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
fn object_verify_typed(ty: objtype, body: []u8, want: oid) bool;
Verifies that the given typed body matches the given object ID.
fn oid_parse
fn oid_parse(s: const str) (oid | nomem | errors::invalid);
Parses a hex-encoded string representation of an oid.
fn oid_stringify
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 pack_read
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
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
fn ref_resolve_head(r: repo) (oid | error);
Reads and resolves the HEAD ref to its object ID.
fn repo_close
fn repo_close(r: repo) void;
Close a repository, freeing its resources.
fn repo_open
fn repo_open(path: const str) (repo | fs::error);
Open a repository at the given path.
fn tag_finish
fn tag_finish(t: tag) void;
Frees resources associated with a tag.
fn tag_parse
fn tag_parse(body: []u8) (tag | errors::invalid | strconv::invalid | strconv::overflow | utf8::invalid | nomem);
Parses a tag from its raw data.
fn tag_serialize
fn tag_serialize(t: tag) ([]u8 | errors::invalid | nomem);
Serializes a commit into its uncompressed on-disk format.
fn tree_entry_finish
fn tree_entry_finish(te: tree_entry) void;
Frees resources associated with a tree_entry.
fn tree_finish
fn tree_finish(t: tree) void;
Frees resources associated with a tree.
fn tree_parse
fn tree_parse(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
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
fn tree_serialize(t: tree) ([]u8 | nomem);
Serializes a tree into its uncompressed on-disk format.
fn walk_recent_commits
fn walk_recent_commits(r: repo, start: oid, limit: int) ([]commit | error);
List recent commits starting from the given commit ID, following first parents only. TODO: Consider cases with merge commits.