package mgit
Build not yet checkedInstall
dune-project
Dependency
Authors
Maintainers
Sources
sha256=6fad812ce53e69e045c4d53d958fc0f12c13900841348dd37f0ba6dd0db2ba8d
sha512=3c2427bc9ee42748aa99540582125aea989dca574493ef46cae70d67ab005c517f079c6c537507b3cb53544811864d52d30df22993b7c297f6a6521f6484ff82
doc/README.html
Git in OCaml (also for unikernels)
mgit is a small implementation of Git in OCaml that can manipulate a repository stored either in memory or as a single file (which, in the case of unikernels, can be viewed as a block device). The aim of mgit is to provide a fairly simple way to manage a Git repository by allowing:
- synchronisation with an existing repository (via TCP/IP, SSH or HTTP)
- the creation of commits that can aggregate multiple changes (file creation, deletion, modification), just as one would do manually.
- the ability to push these changes to an existing repository (via TCP/IP, SSH or HTTP). Commits can therefore be automatically generated and pushed.
- the ability to use this implemention within a unikernel (see https://uniker.nl) (with all the associated type and memory constraints)
Give a try!
The short example below creates an in-memory Git repository and adds a file called foo.txt with the value Hello World. It then displays the commit (which is reproducible as the default date is always 0; see the now parameter).
module Git = Mgit_unix
let run () =
let ( let* ) = Result.bind in
let* t = Git.make Git.Mem in
let fn t = Git.set t "foo.txt" "Hello World!" in
let* () = Git.change_and_push t fn |> Result.join in
begin match Git.commit t with
| Some (`Clean uid) -> Fmt.pr "%s\n%!" (Mgit.uid_to_hex uid)
| Some (`Dirty uid) -> Fmt.pr "~%s\n%!" (Mgit.uid_to_hex uid)
| None -> Fmt.pr "no commit\n%!" end;
Ok ()
let () = Miou_unix.run @@ fun () ->
match run () with
| Ok () -> ()
| Error err -> Fmt.epr "%a\n%!" Mgit.pp_error errYou can simply compile the project as follows:
$ ocamlfind opt -linkpkg -package checkseum.c,digestif.c,mgit.unix main.ml
$ ./a.out
35624210f9ece4576d225edc16466dc01d58af64mgit also offers a very small tool that allows you to save a Git repository to a file containing absolutely everything; here is the same example as the one shown in OCaml:
$ mgit create --size=4MiB disk.img
$ echo 'Hello World!' | mget set disk.img /foo.txt -m "First commit" -
eefb2efe7bc3415aa01ab18cd0b359b0af294d86
$ mgit get disk.img /foo.txt
Hello World!mgit and domains
The model currently used for reading from and writing to a Git repository (whether in memory or on a block device) is one of multiple readers and sequential writers: in other words, there can only be one active write operation at any one time.
If you are interested in the possibility of having multiple writers at the same time, we recommend bancos, which has a more granular structure allowing multiple writers to access the block device.
ocaml-git and git-kv
mgit is a new iteration of ocaml-git and git-kv, for which I am currently the maintainer and/or original author. These projects have been useful for experimenting with the API and the implementations required to ensure interoperability with Git. Furthermore:
ocaml-gitwas an interesting experiment that enabled me, very quickly, to understand and implement the PACKv2 format used by Git to store Git objects. The back-and-forth between the implementation, what was required and how to integrate it into an existing framework led to the creation ofcarton, a scheduler-free implementation of the PACKv2 format (there was, of course, a need to implement decompress, duff and digestif).git-kvis a project that focuses on the high-level API. Initially, we had to use Irmin to manipulate a repository, but its level of abstraction was far too high for our purposes (particularly with regard to dns-primary or opam-mirror). More specifically,git-kvprovides an API that is more like a file system (open, read, write) with a few Git-related functions (fetch, push) and the protocol.
However, these projects have their limitations:
ocaml-gitis far too convoluted by abstractions which, in hindsight, are unnecessary but which we still have to adhere to, creating significant inertia when it comes to improving it.git-kvhas an interesting API but still, in a sense, inherits the abstractions fromocaml-gitand uses lwt. This makes it difficult to carry out an update that would retain support for this scheduler whilst introducing Miou as the new scheduler
More generally, both implementations have memory usage that only increases over time (and with the number of commits), which requires a rethink of the fundamental building blocks needed to store Git objects, with the ability to clean up those that are no longer needed. mgit now offers the gc function, which allows you to retain only the necessary Git objects according to a specified depth (of the history).