plebeia
Library
Module
Module type
Parameter
Class
Class type
Commit DB provides a map from commit hashes (Commit_hash.t) to entries (Commit.t).
The commits are stored in 2 places:
* Context : commit information is written next to the top Plebeia node of each commit. It provides linear access since each commit entry is linked to the previously written entry. The traversal is slow since the entries are scattered in the file.
* Commit_tree : tree structured persistent storage for mappings from commit hashes to the indices of the commit entry saved in the context. If commit tree file is lost or broken, it can be reconstructed from the entries in the context.
val create :
hash_func:[ `Blake2B | `Blake3 ] ->
storage_context:Storage.t ->
commit_tree:Commit_tree.t ->
( t, Error.t ) Result_lwt.t
val commit_tree : t -> Commit_tree.t
Returns the underlying commit tree
type entry = Commit.t = {
parent : Commit_hash.t option; | |
index : Index.t; | (* Index of the Plebeia tree root node in storage_context. If the commit is a dummy, field |
hash : Commit_hash.t; | (* Context hash *) |
info : Index.t; | (* Index of the Info.t in storage_conetxt. *) |
}
val compute_hash :
t ->
parent:Commit_hash.t option ->
Hash.Prefix.t ->
Commit_hash.t
compute_hash t ~parent hash_prefix
computes the commit hash of the commit (parent, hash_prefix)
.
val make_commit :
t ->
parent:Commit_hash.t option ->
index:Index.t ->
info:Index.t ->
?hash_override:Commit_hash.t ->
Hash.Prefix.t ->
entry
Build Commit.t
using t
's hash function
For the writer, reload additional commits from the updated context. For readers, do nothing and returns Ok 0
.
flush
writes the node of the commit_tree to the context. Once flush
succeeds, the modificaiton to t
is persisted on the disk.
For reader, update_reader
updates the commit DB which may be updated by the writer. For writer, update_reader
does nothing.
val may_forget : t -> bool
Forget the on-memory cache of t
then returns true
. If t
has unsaved update, it returns false
.
Add a commit entry. To persist the added commit on disk, commit
must be called.
val mem : t -> Commit_hash.t -> bool
Existence check
val find : t -> Commit_hash.t -> Commit.t option
Find a root of the given hash
Returns the Commit.t of the parent. Ok None
: The Commit.t has no parent Error `Not_found
: the parent does not exist in the DB.
val children : t -> ( Commit_hash.t -> Commit.t list ) Lwt.t
children t
returns a function to query children of the given hash.
children t
traverses the whole commit tree, therefore inefficient.
Get the genesis commit hashes, which have no parent.
This function traverses the whole commit tree, therefore inefficient.
val fold :
( Commit.t ->
parent:( Commit.t option, [ `Not_found ] ) Stdlib.result ->
'a ->
'a Lwt.t ) ->
t ->
'a ->
'a Lwt.t
Folding over all the commits
Warning: this takes VERY long time if the context file is huge.
Read all the entries from the context file.
Warning: this takes VERY long time if the context file is huge.