12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364(*
* Copyright (c) 2013-2022 Thomas Gazagnaire <thomas@gazagnaire.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)openImportmoduleMake(G:Git.S)(C:Irmin.Contents.S)=structmoduleRaw=Git.Value.Make(G.Hash)moduleHash=Irmin.Hash.Make(G.Hash)moduleV=structtypet=C.tlettype_eq=function`Blob->true|_->falseletof_git=function|Git.Value.Blobb->(letstr=G.Value.Blob.to_stringbinmatchIrmin.Type.of_stringC.tstrwith|Okx->Somex|Error(`Msge)->Fmt.invalid_arg"error %s"e)|_->Noneletto_gitb=letstr=Irmin.Type.to_stringC.tbinG.Value.blob(G.Value.Blob.of_stringstr)endincludeContent_addressable.Check_closed(Content_addressable.Make(G)(V))moduleVal=structincludeCletto_bint=Raw.to_raw(V.to_gitt)letencode_bin(t:t)k=k(to_bint)letdecode_binbufpos_ref=[%log.debug"Content.decode_bin"];letoff=!pos_refinmatchRaw.of_raw_with_header~offbufwith|Okg->(matchV.of_gitgwith|Someg->pos_ref:=String.lengthbuf;g|None->failwith"wrong object kind")|Error(`Msg_)->failwith"wrong object"letsize_of=Irmin.Type.Size.custom_dynamic()lett=Irmin.Type.like~bin:(encode_bin,decode_bin,size_of)tendend