silt

silt / reference

silt/object

The git object model: content-addressed blob, tree, and commit values with git-canonical SHA-1 ids, and the decoders that read their JSON bodies back into typed values. Pure logic over content — it owns no store.

import
import silt/object

Types

type

Person

also on silt #
pub type Person {
  Person(name: String, email: String, date: String)
}

A commit author or committer identity — the name, email, and date carried on a commit.

type

TreeEntry

also on silt #
pub type TreeEntry {
  TreeEntry(
    path: String,
    mode: String,
    kind: String,
    size: Int,
    sha: String,
  )
}

A single entry within a tree object. kind is "blob" or "tree"; mode is the git file mode (default "100644"); sha points at the child object.

type

Commit

also on silt #
pub type Commit {
  Commit(
    tree: String,
    parents: List(String),
    message: String,
    author: Person,
    committer: Person,
  )
}

A decoded commit object: the tree it snapshots, its parents, the message, and the author / committer identities.

Ids & hashing

fn

object_id

also on silt #
pub fn object_id(
  kind: String,
  body: String,
) -> Result(String, Nil)

Compute the content-addressed id for an object body of the given kind — the plural REST form "blobs", "trees", or "commits".

Blobs use git-canonical framing ("blob " <len> \0 <content>") so the id matches a real git object id. Trees and commits hash their serialized body directly. Any other kind is an Error(Nil).

fn

sha1

#
pub fn sha1(body: BitArray) -> String

The lowercase hex SHA-1 of the given bytes. The primitive under object_id, exposed for callers that already hold framed bytes.

fn

blob_content

#
pub fn blob_content(
  content: String,
  encoding: String,
) -> Result(BitArray, Nil)

Decode the raw bytes carried by a blob body given its declared encoding"utf-8" or "base64". Any other encoding is an Error(Nil).

Decoders

fn

decode_blob

#
pub fn decode_blob(
  body: String,
) -> Result(#(String, String), Nil)

Decode a blob body into its #(content, encoding). A missing encoding field defaults to "utf-8".

fn

decode_tree

#
pub fn decode_tree(
  body: String,
) -> Result(List(TreeEntry), Nil)

Decode a tree body into its TreeEntry list. Per-entry defaults: mode "100644", type "blob", size 0.

fn

decode_commit

#
pub fn decode_commit(
  body: String,
) -> Result(Commit, Nil)

Decode a commit body into a Commit. parents defaults to [], message to "", and a missing committer falls back to the author.

fn

decode_ref

also on silt #
pub fn decode_ref(
  body: String,
) -> Result(#(String, String), Nil)

Decode a ref-update body into its #(ref, sha) — the ref name and the commit it should point at.