package git

  1. Overview
  2. Docs
Git format and protocol in pure OCaml

Install

Dune Dependency

Authors

Maintainers

Sources

git-3.8.0.tbz
sha256=f6c628e3628d25686cec4cdff8132f9433e95938bdcb43975778d28d33a0b077
sha512=779bdd7a1657e859ed47b46ef9da007b5f43f4446f8cea831f29fae662efdd33a39aa2ee90b9f8d8b6360f2abb78038a7592633efa26e8adc5d2ae20d86d8015

Description

Support for on-disk and in-memory Git stores. Can read and write all the Git objects: the usual blobs, trees, commits and tags but also the pack files, pack indexes and the index file (where the staging area lives).

All the objects share a consistent API, and convenience functions are provided to manipulate the different objects.

Published: 03 Feb 2022

README

ocaml-git -- Git format and protocol in pure OCaml

Support for on-disk and in-memory Git stores. Can read and write all the Git objects: blobs, trees, commits and tags. It can also handle pack files, pack indexes and index files (where the staging area lives - only for git-unix package).

All the objects share a consistent API, and convenience functions are provided to manipulate the different objects. For instance, it is possible to make a pack file position independent (as the Zlib compression might change the relative offsets between the packed objects), to generate pack indexes from pack files, or to expand the filesystem of a given commit.

The library comes with some command-line tools called ogit-* as a Proof-of-concept of the core library which shares a similar interface with git, but where all operations are mapped to the API exposed by ocaml-git (and hence using only OCaml code). However, these tools are not meant to be used. They are just examples of how to use ocaml-git.

ocaml-git wants to be a low-level library for irmin. By this fact, high-level commands such as a (patience) diff, git status, etc. are not implemented.

As a MirageOS project, ocaml-git is system agnostic. However, it provides a git-unix package which uses UNIX syscall and is able to introspect a usual Git repository in a filesystem. However, ocaml-git handles only Git objects and does not populate your filesystem as git does. For example, Git_unix.Sync.fetch does not give you files fetched from the repository but only synchronizes .git with that repository.

The API documentation is available online.

Build, Install Instructions and Packages

To build and install the project, simply run:

$ opam install git
$ opam install git-unix
$ opam install git-mirage

Linking-trick

ocaml-git uses 2 libraries with the linking-trick:

These libraries provide a C implementation and an OCaml implementation (mostly to be compatible with js_of_ocaml). However, utop or any a build-system such as ocamlbuild are not able to choose between these implementations. So, you must explicitely choose one.

These libraries use virtual-library available with dune. If your build-system is dune, you should not have any problem about that where dune is able to take the default implementation of these libraries.

What is supported

  • The loose object files can be read and written;

  • The PACK files (collections of compressed loose objects using a binary-diff representation) and PACK indexes (indexes of pack files) can be read and written). The binary diff hunks are exposed using a high-level position-independent representation so that they can be manipulated more easily. Pack file can be created and is compressed.

  • The INDEX file (used as for managing the staging area) are fully supported, which means that git diff and git status will work as expected on a repository created by the library. This feature is only available for git-unix when it needs to introspect a file-system.

  • Cloning and fetching (using various options) are fully supported for the Git protocol, the smart-HTTP protocol and git+ssh. A subset of the protocol capabilities are implemented (mainly thin-pack, ofs-delta, side-band-64k and allow-reachable-sha1-in-want).

  • Pushing is still experimental and needs more testing.

  • An abstraction for Git Store Is available. Various store implementations are available:

What is not supported

  • No server-side operations are currently supported.

  • No GC.

  • Updates, merge and rebase are not supported. Use irmin instead.

Performance

Performance is comparable to the Git tool.

Example

This utop example must run into the ocaml-git repository when the given path is ..

# ;; load necessary modules
# #require "checkseum.c" ;;
# #require "digestif.c" ;;
# #require "git-unix" ;;

# ;; we are going to use this project's local repository
# module Store = Git_unix.Store ;; 
module Store = Git_unix.Store

# ;; this module is useful for finding git objects in a git store
# module Search = Git.Search.Make (Digestif.SHA1) (Store) ;;
module Search :
  sig
    type hash = Store.hash
    type store = Store.t
    type pred =
        [ `Commit of hash
        | `Tag of string * hash
        | `Tree of string * hash
        | `Tree_root of hash ]
    val pred : store -> ?full:bool -> hash -> pred list Lwt.t
    type path =
        [ `Commit of path | `Path of string list | `Tag of string * path ]
    val mem : store -> hash -> path -> bool Lwt.t
    val find : store -> hash -> path -> hash option Lwt.t
  end

# ;; we want to read the contents of a blob under name [filename]
# let read filename =
  let open Lwt_result.Syntax in
  (* get store located in current root's .git folder *)
  let* store = Store.v (Fpath.v (Sys.getcwd ())) in
  (* find obj-id pointed at by master branch (reference) *)
  let* commit_id = Store.Ref.resolve store Git.Reference.master in
  let open Lwt.Syntax in
  (* find obj-id of of [filename] as a git blob *)
  let* blob_id = Search.find store commit_id (`Commit (`Path [ filename ])) in
  match blob_id with
  | None -> Lwt.return (Error (`Not_found commit_id))
  | Some hash ->
      (* read contents of the blob *)
      Store.read store hash
  ;;
val read : string -> (Store.Value.t, Store.error) Lwt_result.t = <fun>

# let pp =
  let ok ppf = function
    | Git.Value.Blob b -> Fmt.string ppf (Git.Blob.to_string b)
    | _ -> Fmt.string ppf "#git-object"
  in
  Fmt.result ~ok ~error:Store.pp_error;;
val pp : ('_weak1 Git.Value.t, Store.error) result Fmt.t = <fun>

# Lwt_main.run Lwt.Infix.(read "README.md" >|= pp Fmt.stdout) ;;

ocaml-git -- Git format and protocol in pure OCaml

Support for on-disk and in-memory Git stores. Can read and write all
the Git objects: the usual blobs, trees, commits and tags but also
the pack files, pack indexes and the index file (where the staging area
lives).

[...]

()

License

MIT, see LICENSE.md file for its text.

Dependencies (33)

  1. uri >= "4.1.0"
  2. psq >= "0.2.0"
  3. ipaddr >= "5.0.1"
  4. emile >= "1.1"
  5. domain-name >= "0.3.0"
  6. mirage-flow >= "2.0.1"
  7. hxd >= "0.3.1"
  8. fpath
  9. encore >= "0.8"
  10. fpath
  11. astring
  12. ocamlgraph >= "1.8.8"
  13. checkseum >= "0.2.1"
  14. fmt >= "0.8.7"
  15. ke >= "0.4"
  16. carton-git >= "0.4.3"
  17. carton-lwt >= "0.4.3"
  18. carton >= "0.4.3"
  19. angstrom >= "0.14.0"
  20. cstruct >= "6.0.0" & < "6.1.0"
  21. mimic >= "0.0.4"
  22. lwt
  23. logs
  24. decompress >= "1.4.0" & < "1.4.3"
  25. optint
  26. bigarray-compat
  27. bigstringaf < "0.9.0"
  28. result
  29. base64 >= "3.0.0"
  30. rresult
  31. digestif >= "0.8.1"
  32. dune >= "2.8.0"
  33. ocaml >= "4.08.0"

Dev Dependencies (6)

  1. crowbar >= "0.2" & with-test
  2. base-unix with-test
  3. cmdliner with-test
  4. mirage-crypto-rng with-test & >= "0.8.0" & < "1.0.0"
  5. alcotest-lwt with-test & >= "1.1.0"
  6. alcotest with-test & >= "1.1.0"

Used by (17)

  1. datakit != "0.12.0"
  2. docteur
  3. docteur-solo5
  4. docteur-unix
  5. dog
  6. git-mirage < "1.11.4" | = "3.8.0"
  7. git-paf = "3.8.0"
  8. git-unix = "3.8.0"
  9. imaplet-lwt >= "0.1.3"
  10. irmin >= "0.9.0" & != "0.10.1" & < "0.11.1"
  11. irmin-cli
  12. irmin-git >= "2.6.0" & < "3.9.0"
  13. irmin-mirage-git >= "2.5.1" & < "2.8.0" | >= "2.10.0"
  14. irmin-mirage-graphql >= "2.5.1"
  15. irmin-unix < "0.9.9" | >= "2.5.4"
  16. merge-queues >= "0.2.0"
  17. plotkicadsch >= "0.5.0" & < "0.6.1" | >= "0.9.0"

Conflicts

None

OCaml

Innovation. Community. Security.