This module implements the ability to manipulate a Git repository as a Key-Value store. It allows you to create a local (in-memory) Git repository that can come from either:
The first case is interesting if you want to be synchronised with the remote repository. The second case can be interesting if we don't want to create a connection at the beginning and desynchronisation between our local and remote repositories is not a problem.
In the second case, the synchronisation can be done later with pull.
Pushing and synchronisation.
The user can modify the repository (add files, remove files, etc.). Each change produces a commit and after each change we try to transfer them to the remote Git repository. If you want to make multiple changes but contain them in a single commit and only transfer those changes once, you should use the Make.change_and_push function.
Serialization of the Git repository.
Finally, the KV-store tries to keep the minimal set of commits required between you and the remote repository. Only unpushed changes are kept by the KV-store. However, if these changes are not pushed, they will be stored into the final state produced by to_octets. In other words, the more changes you make out of sync with the remote repository (without pushing them), the bigger the state serialization will be.
exists t k is Some `Value if k is bound to a value in t, Some `Dictionary if k is a prefix of a valid key in t and None if no key with that prefix exists in t.
exists answers two questions: does the key exist and is it referring to a value or a dictionary.
An error occurs when the underlying storage layer fails.
get_partial t k ~offset ~length is the length bytes wide value bound at offset of k in t.
If the size of k is less than offset, get_partial returns an empty string. If the size of k is less than offset+length, get_partial returns a short string. The result is Error (`Value_expected k) if k refers to a dictionary in t.
last_modified t k is the last time the value bound to k in t has been modified.
When the value bound to k is a dictionary, the implementation is free to decide how to compute a last modified timestamp, or return Error (`Value_expected _).
digest t k is the unique digest of the value bound to k in t.
When the value bound to k is a dictionary, the implementation is allowed to return Error (`Value_expected _). Otherwise, the digest is a unique and deterministic digest of its entries.
allocate t key ~last_modified size allocates space for key in t with the provided size and last_modified. This is useful for e.g. append-only backends that could still use set_partial. The data will be filled with 0. If key already exists, Error (`Already_present key) is returned. If there's not enough space, Error `No_space is returned.
set_partial t k offset v attempts to write v at offset in the value bound to k in t. If k contains directories that do not exist, set_partial will attempt to create them. If the size of k is less than offset, set_partial appends v at the end of k. If the size of k is greater than offset+length of v, set_partial leaves the last bytes of k unchanged.
The result is Error (`Value_expected k) if k refers to a dictionary in t.
rename t source dest rename source to dest in t. If source and dest are both bound to values in t, dest is removed and the binding of source is moved to dest. If dest is bound to a dictionary in t, source is moved inside dest. If source is bound to a dictionary, the full dictionary is moved.
The result is Error (`Not_found source) if source does not exists in t. The result is Error (`Value_expected source) if source is bound to a dictionary in t and dest is bound to a value in t. The result id Error (`Rename_source_prefix (source, dest)) if source is a prefix of dest, and source is a directory.
to_octets ?level store returns a serialized version of the given store. level is the zlib level compression used for Git object (between 0 and 9 including), defaults to 4.
of_octets ctx ~remote contents tries to re-create a t from its serialized version contents. This function does not do I/O and the returned t can be out of sync with the given remote. We advise to call pull to be in-sync with remote.
pull store tries to synchronise the remote Git repository with your local store Git repository. It returns a list of changes between the old state of your store and what you have remotely.
change_and_push store ~author ~author_email ~message f applies the changes of f to store, and creates a commit using author, author_email, and message (committer will be the same as author), and pushes that commit to the remote.