package git-kv

  1. Overview
  2. Docs
A Mirage_kv implementation using git

Install

dune-project
 Dependency

Authors

Maintainers

Sources

git-kv-0.2.2.tbz
sha256=6d1e7fe304db9672a86497b57f71af31d97a725ccca77c6f40a461ca3d1929fe
sha512=a9c4d4a4605ad9c97e317be5ee6e07ab610ec4c2a2a56fab7ef000ab61f44b135d538c771fabe7434d19302bb2f433df80279fa87c97bfb1961a2d6e1759240e

doc/src/git-kv.mem/git_digest.ml.html

Source file git_digest.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
let hdr = function
  | `Blob -> Fmt.str "blob %Ld\000"
  | `Tree -> Fmt.str "tree %Ld\000"
  | `Tag -> Fmt.str "tag %Ld\000"
  | `Commit -> Fmt.str "commit %Ld\000"

let ( % ) f g = fun x -> f (g x)

let sha1 =
  let open Digestif in
  let feed_bigstring bstr ctx = SHA1.feed_bigstring ctx bstr in
  let feed_bytes buf ~off ~len ctx = SHA1.feed_bytes ctx ~off ~len buf in
  {
    Carton.First_pass.feed_bytes;
    feed_bigstring;
    serialize= SHA1.to_raw_string % SHA1.get;
    length= SHA1.digest_size;
  }

let digest digest ctx fkind length serializer v =
  let open Carton.First_pass in
  let hdr = hdr fkind (length v) in
  let state = Encore.Lavoisier.emit v serializer in
  let rec go ctx = function
    | Encore.Lavoisier.Partial {buffer= str; off; len; continue} ->
      let ctx = digest.feed_bytes ~off ~len (Bytes.unsafe_of_string str) ctx in
      go ctx (continue ~committed:len)
    | Fail -> Fmt.failwith "Invalid Git object"
    | Done -> digest.serialize ctx |> Digestif.SHA1.of_raw_string
  in
  let ctx =
    digest.feed_bytes ~off:0 ~len:(String.length hdr)
      (Bytes.unsafe_of_string hdr)
      ctx
  in
  go ctx state