Legend:
Library
Module
Module type
Parameter
Class
Class type
Branch-consistent stores.
Branch-consistent stores
Branch-consistent stores are hierarchical read-write stores with extended capabilities. They allow an application (or a collection of applications) to work with multiple local states, which can be forked and merged programmatically, without having to rely on a global state. In a way very similar to version control systems, Irmin local states are called branches.
There are two kinds of BC store in Irmin: persistent named branches and temporary detached heads. These exist relative to a local, larger (and shared) store, and have some (shared) contents. This is exactly the same as usual version control systems, that the informed user can see as an implicit purely functional data-structure.
Persistent Branches
A persistent branch always has a unique ID, which is typically a string (the branch name). Thus, in order to use a persistent branch, you need to provide its name: see the of_branch_id function.
type commit_id
Type for commit identifiers. Similar to Git's commit SHA1s.
type branch_id
Type for persistent branch names. Branches usually share a common global namespace and it's the user's responsibility to avoid name clashes.
update t k v replaces the contents of k by v in t. If k is not already defined in t, create a fresh binding. Raise Invalid_argument if k is the empty path.
val compare_and_set :
t->key->test:value option->set:value option->bool Lwt.t
compare_and_set t key ~test ~set sets key to set only if the current value of key is test and in that case returns true. If the current value of key is different, it returns false. None means that the value does not have to exist or is removed.
master repo task is a function returning fresh store handles within the repository repo, with fresh tasks computed using task. The result is a persistent branch using the
ef.S.master
reference. This operation is cheap, can be repeated multiple times.
update_branch t src updates t's contents with the contents of the branch named src. Can cause data losses as it discard the current contents. Similar to git reset --hard <src>.
Temporary stores do not have stable names: instead they can be addressed using the hash of the current commit. These hashes are called heads in Irmin. Temporary stores are similar to Git's detached heads. In a temporary store, all the operations are performed relative to the current head and update operations can modify the current head: the current stores's head will automatically become the new head obtained while performing the update.
Temporary stores are created using the BC.of_head function.
head t is the current head of the store t. This works for both persistent and temporary stores. In the case of a persistent branch, this involves getting the the head associated with the branch's ID, so this may block. In the case of a temporary store, it simply returns the current head. Returns None if the store has no contents. Similar to git
rev-parse HEAD.
head_ref t is the branch ID that this store tracks (for persistent stores), the current head commit (for temporary stores), or `Empty for empty temporary stores.
update_head t h updates t's contents with the contents of the commit_id h. Can cause data loss as it discards the current contents. Similar to git reset --hard <hash>.
val fast_forward_head :
t->?max_depth:int ->?n:int ->commit_id->bool Lwt.t
fast_forward_head t h is similar to update_head but the t's head is updated to h only if h is stricly in the future of t's current head. Return false if it is not the case. If present, max_depth or n are used to limit the search space of the lowest common ancestors (see lcas).
merge_head t ?max_head ?n commit_id merges the contents of the commit associated to commit_id into t. max_depth is the maximal depth used for getting the lowest common ancestor. n is the maximum number of lowest common ancestors. If present, max_depth or n are used to limit the search space of the lowest common ancestors (see lcas).
val merge_head_exn : t->?max_depth:int ->?n:int ->commit_id->unit Lwt.t
watch_branch t f calls f every time the contents of t's reference is updated. Do nothing if t is not persistent. Return a clean-up function to remove the watch handler.
Note: even f might skip some head updates, it will never be called concurrently: all consecutive calls to f are done in sequence, so we ensure that the previous one ended before calling the next one.
watch_key t key f calls f every time the key's value is added, removed or updated. If the current branch is deleted, no signal is sent to the watcher.
Clones and Merges
val clone :
'aTask.f->t->branch_id->[ `Ok of 'a->t| `Duplicated_branch| `Empty_head ]Lwt.t
Clone the store t, using the given branch name. Return Duplicated_branch if a branch with the same name already exists and Empty_head if t has no head.
Same as clone but delete and update the existing branch if a branch with the same name already exists.
val merge :
'a->?max_depth:int ->?n:int ->('a->t)->into:('a->t)->unit Merge.resultLwt.t
merge x t i merges t x's current branch into i x's current branch. After that operation, the two stores are still independent. Similar to git merge <branch>.
val merge_exn :
'a->?max_depth:int ->?n:int ->('a->t)->into:('a->t)->unit Lwt.t
history ?depth ?min ?max t is a view of the history of the store t, of depth at most depth, starting from the max (or from the t's head if the list of heads is empty) and stopping at min if specified.