package git-kv

  1. Overview
  2. Docs
A Mirage_kv implementation using git

Install

Dune Dependency

Authors

Maintainers

Sources

git-kv-0.0.3.tbz
sha256=f94fdbacefab6cd0f53fae7ce3bcfe792b85954324a3da22a5e1c996a25bee36
sha512=454ab1f126aa6da864e41b94aae9cf0ef25d146286d1870a014d1ea7dda7b18ed4574df48ffc9f8df442b70d3361a2bafbcfeebb1e90284cbb8d9af8cba08203

Description

Published: 17 Dec 2022

README

Git-kv, a simple Key-Value store synchronized with a Git repository

This library is a simple implementation of a Git repository that can be read and/or modified. It offers two ways to create such a local repository:

  1. The local repository can be created in a serialized state

  2. The local repository can be created from a remote repository

The first method has the advantage of not requiring an internet connection. The serialized state can be created with the mgit tool:

$ mgit https://github.com/mirage/mirage <<EOF
> save db.pack
> quit
$ ls db.pack
db.pack

The disadvantage is that the serialized state may be out of sync with the state of the remote repository. In this case, the user has access to the pull function, which allows the internet state of the local repository to be re-synchronised with the remote repository.

let contents_of_file filename =
  let ic = open_in filename in
  let ln = in_channel_length ic in
  let rs = Bytes.create ln in
  really_input ic rs 0 ln ;
  Bytes.unsafe_to_string rs

let _ =
  Git_kv.of_octets ctx 
    ~remote:"git@github.com:mirage/mirage.git"
    (contents_of_file "db.pack") >>= fun t ->
  Git_kv.pull t >>= fun diff ->
  ...

The second method initiates a connection to the remote repository in order to download its state and reproduce a synchronised internal state. The type of connections supported are described in the given ctx. We recommend the tutorial about Mimic to understand its use.

let _ =
  Git_kv.connect ctx "git@github.com:mirage/mirage.git" >>= fun t ->
  ...

The user can manipulate the repository as an RW repository. Any change to the repository requires a new commit. These changes will be sent to the remote repository. The user can fold any changes into one commit if he/she wants.

module Store = Git_kv.Make (Pclock)

let new_file t =
  Store.set t Mirage_kv.Key.(empty / "foo") "foo" >>= fun () ->
  (* XXX(dinosaure): a commit was created and sended to the
     remote repository. *)
  ...

let new_files t =
  Store.change_and_push t @@ fun t ->
  Store.set t Mirage_kv.Key.(empty / "foo" "foo") >>= fun () ->
  Store.set t Mirage_kv.Key.(empty / "bar" "bar")
(* XXX(dinosaure): multiple files are added into the local repository
   but they are committed only at the end of the given function
   to [change_and_push]. That's say, only one commit was made and sended to the
   remote Git repository. *)

Dependencies (8)

  1. ptime
  2. mirage-clock >= "2.0.0"
  3. fmt >= "0.8.7"
  4. carton >= "0.6.0"
  5. mirage-kv >= "6.0.0"
  6. git >= "3.10.0"
  7. dune >= "2.9.0"
  8. ocaml >= "4.08.0"

Dev Dependencies (4)

  1. git-unix >= "3.10.0" & with-test
  2. mirage-clock-unix with-test
  3. conf-git with-test
  4. hxd with-test

Used by (1)

  1. yocaml_git < "2.0.0"

Conflicts

None

OCaml

Innovation. Community. Security.