123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159(*
* Copyright (c) 2018-2021 Tarides <contact@tarides.com>
*
* 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.
*)open!ImportmoduleAtomic_write(K:Irmin.Type.S)(V:Irmin.Hash.S)=structmoduleAW=Irmin_mem.Atomic_write(K)(V)includeAWletv()=AW.v(Irmin_mem.config())letflush_t=()letclear_keep_generation_=Lwt.return_unitendmoduleMake(Node:Irmin.Private.Node.Maker)(Commit:Irmin.Private.Commit.Maker)(Config:Irmin_pack.Conf.S)(M:Irmin.Metadata.S)(C:Irmin.Contents.S)(P:Irmin.Path.S)(B:Irmin.Branch.S)(H:Irmin.Hash.S)=structmodulePack=Content_addressable.Maker(H)moduleX=structmoduleHash=Htype'avalue={hash:H.t;magic:char;v:'a}[@@derivingirmin]moduleContents=structmodulePack_value=Irmin_pack.Pack_value.Of_contents(H)(C)moduleCA=structmoduleKey=HmoduleVal=CmoduleCA=Pack.Make(Pack_value)includeIrmin_pack.Content_addressable.Closeable(CA)letvx=CA.vx>|=make_closeableendincludeIrmin.Contents.Store(CA)endmoduleNode=structmoduleNode=Node(H)(P)(M)moduleCA=structmoduleInter=Irmin_pack.Inode.Make_internal(Config)(H)(Node)moduleCA=Pack.Make(Inter.Raw)includeIrmin_pack.Inode.Make(H)(Node)(Inter)(CA)letv=CA.vendincludeIrmin.Private.Node.Store(Contents)(P)(M)(CA)endmoduleCommit=structmoduleCommit=Commit(H)modulePack_value=Irmin_pack.Pack_value.Of_commit(H)(Commit)moduleCA=structmoduleKey=HmoduleVal=CommitmoduleCA=Pack.Make(Pack_value)includeIrmin_pack.Content_addressable.Closeable(CA)letvx=CA.vx>|=make_closeableendincludeIrmin.Private.Commit.Store(Node)(CA)endmoduleBranch=structmoduleKey=BmoduleVal=HmoduleAW=Atomic_write(Key)(Val)includeIrmin_pack.Atomic_write.Closeable(AW)letv()=AW.v()>|=make_closeableendmoduleSlice=Irmin.Private.Slice.Make(Contents)(Node)(Commit)moduleSync=Irmin.Private.Sync.None(H)(B)moduleRepo=structtypet={config:Irmin.Private.Conf.t;contents:readContents.CA.t;node:readNode.CA.t;commit:readCommit.CA.t;branch:Branch.t;}letcontents_tt:'aContents.t=t.contentsletnode_tt:'aNode.t=(contents_tt,t.node)letcommit_tt:'aCommit.t=(node_tt,t.commit)letbranch_tt=t.branchletbatchtf=Commit.CA.batcht.commit(funcommit->Node.CA.batcht.node(funnode->Contents.CA.batcht.contents(funcontents->letcontents:'aContents.t=contentsinletnode:'aNode.t=(contents,node)inletcommit:'aCommit.t=(node,commit)infcontentsnodecommit)))letvconfig=letroot=Irmin_pack.Conf.rootconfiginlet*contents=Contents.CA.vrootinlet*node=Node.CA.vrootinlet*commit=Commit.CA.vrootinlet+branch=Branch.v()in{contents;node;commit;branch;config}letcloset=Contents.CA.close(contents_tt)>>=fun()->Node.CA.close(snd(node_tt))>>=fun()->Commit.CA.close(snd(commit_tt))>>=fun()->Branch.closet.branch(* An in-memory store is always in sync. *)letsync_=()letflush_=()(* Stores share instances so one clear is enough. *)letcleart=Contents.CA.clear(contents_tt)endendincludeIrmin.Of_private(X)letintegrity_check_inodes?heads:__=Lwt.return(Error(`Msg"Not supported: integrity checking of in-memory inodes"))letsync=X.Repo.syncletclear=X.Repo.clearletmigrate=Irmin_pack.migrateletflush=X.Repo.flushletintegrity_check?ppf:_~auto_repair:__t=Ok`No_errorlettraverse_pack_file__=()end