123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245(*
* 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.
*)open!ImportmoduleType=ReprmoduleMetrics=MetricsmoduleDiff=DiffmoduleRead_only=Read_onlymoduleAppend_only=Append_onlymoduleIndexable=IndexablemoduleContent_addressable=Content_addressablemoduleAtomic_write=Atomic_writemoduleContents=ContentsmoduleMerge=MergemoduleBranch=BranchmoduleNode=NodemoduleCommit=CommitmoduleInfo=InfomoduleSchema=SchemamoduleDot=Dot.MakemoduleHash=HashmodulePath=PathmodulePerms=PermsmoduleKey=KeymoduleIrmin_node=NodeexceptionClosed=Store_properties.ClosedmoduletypeMaker_generic_key_args=sigmoduleContents_store:Indexable.Maker_concrete_key2moduleNode_store:Indexable.Maker_concrete_key1moduleCommit_store:Indexable.Maker_concrete_key1moduleBranch_store:Atomic_write.MakerendmoduleMaker_generic_key(Backend:Maker_generic_key_args)=structtypeendpoint=unittype('h,'v)contents_key=('h,'v)Backend.Contents_store.keytype'hnode_key='hBackend.Node_store.keytype'hcommit_key='hBackend.Commit_store.keymoduleMake(S:Schema.S)=structmoduleX=structmoduleSchema=SmoduleHash=S.HashmoduleContents_key=Backend.Contents_store.Key(S.Hash)(S.Contents)moduleNode_key=Backend.Node_store.Key(S.Hash)moduleCommit_key=Backend.Commit_store.Key(S.Hash)moduleContents=structmoduleBackend=Backend.Contents_store.Make(S.Hash)(S.Contents)includeContents.Store_indexable(Backend)(S.Hash)(S.Contents)endmoduleNode=structmoduleValue=Node.Generic_key.Make(S.Hash)(S.Path)(S.Metadata)(Contents_key)(Node_key)moduleBackend=Backend.Node_store.Make(S.Hash)(Value)includeNode.Generic_key.Store(Contents)(Backend)(S.Hash)(Value)(S.Metadata)(S.Path)endmoduleNode_portable=Node.Value.PortablemoduleCommit=structmoduleCommit_maker=Commit.Generic_key.Maker(Schema.Info)moduleValue=Commit_maker.Make(S.Hash)(Node_key)(Commit_key)moduleBackend=Backend.Commit_store.Make(S.Hash)(Value)includeCommit.Generic_key.Store(S.Info)(Node)(Backend)(S.Hash)(Value)endmoduleCommit_portable=Commit.Value.PortablemoduleBranch=structmoduleVal=Commit.KeyincludeBackend.Branch_store(S.Branch)(Val)moduleKey=S.BranchendmoduleSlice=Slice.Make(Contents)(Node)(Commit)moduleRemote=Remote.None(Commit_key)(S.Branch)moduleRepo=structtypet={config:Conf.t;contents:readContents.t;nodes:readNode.t;commits:readCommit.t;branch:Branch.t;}letcontents_tt=t.contentsletnode_tt=t.nodesletcommit_tt=t.commitsletbranch_tt=t.branchletconfigt=t.configletbatchtf=Contents.Backend.batcht.contents@@func->Node.Backend.batch(sndt.nodes)@@funn->Commit.Backend.batch(sndt.commits)@@funct->letcontents_t=cinletnode_t=(contents_t,n)inletcommit_t=(node_t,ct)infcontents_tnode_tcommit_tletvconfig=let*contents=Contents.Backend.vconfiginlet*nodes=Node.Backend.vconfiginlet*commits=Commit.Backend.vconfiginletnodes=(contents,nodes)inletcommits=(nodes,commits)inlet+branch=Branch.vconfigin{contents;nodes;commits;branch;config}letcloset=Contents.Backend.closet.contents>>=fun()->Node.Backend.close(sndt.nodes)>>=fun()->Commit.Backend.close(sndt.commits)>>=fun()->Branch.closet.branchendendincludeStore.Make(X)endendmoduleMaker(CA:Content_addressable.Maker)(AW:Atomic_write.Maker)=structmoduleIndexable_store=structtype'hkey='hmoduleKey=Key.Of_hashmoduleMake(Hash:Hash.S)(Value:Type.S)=structmoduleCA=Content_addressable.Check_closed(CA)(Hash)(Value)includeIndexable.Of_content_addressable(Hash)(CA)letv=CA.vendendmoduleMaker_args=structmoduleContents_store=Indexable.Maker_concrete_key2_of_1(Indexable_store)moduleNode_store=Indexable_storemoduleCommit_store=Indexable_storemoduleBranch_store=Atomic_write.Check_closed(AW)endincludeMaker_generic_key(Maker_args)endmoduleKV_maker(CA:Content_addressable.Maker)(AW:Atomic_write.Maker)=structtypemetadata=unittypehash=Schema.default_hashtypeinfo=Info.defaultmoduleMaker=Maker(CA)(AW)includeMakermoduleMake(C:Contents.S)=Maker.Make(Schema.KV(C))endmoduleOf_backend=Store.MakemoduletypeTree=Tree.SmoduletypeS=Store.Stypeconfig=Conf.ttype'adiff='aDiff.tmoduletypeMaker=Store.MakermoduletypeKV=Store.KVmoduletypeKV_maker=Store.KV_makermoduleGeneric_key=structincludeStore.Generic_keymoduletypeMaker_args=Maker_generic_key_argsmoduleMaker=Maker_generic_keyendmoduleBackend=structmoduleConf=ConfmoduleSlice=SlicemoduleRemote=RemotemoduletypeS=Backend.SmoduleWatch=WatchmoduleLock=LockmoduleLru=Lruendletversion=Version.currentmoduleSync=Synctyperemote=Remote.t=..letremote_store(typet)(moduleM:Generic_key.Swithtypet=t)(t:t)=letmoduleX:Store.Generic_key.Swithtypet=t=MinSync.remote_store(moduleX)tmoduleMetadata=MetadatamoduleJson_tree=Store.Json_treemoduleExport_for_backends=Export_for_backendsmoduleStorage=StoragemoduleOf_storage(M:Storage.Make)(H:Hash.S)(V:Contents.S)=structmoduleCA=Storage.Content_addressable(M)moduleAW=Storage.Atomic_write(M)moduleMaker=Maker(CA)(AW)includeMaker.Make(structmoduleHash=HmoduleContents=VmoduleInfo=Info.DefaultmoduleMetadata=Metadata.NonemodulePath=Path.String_listmoduleBranch=Branch.StringmoduleNode=Node.Make(Hash)(Path)(Metadata)moduleCommit=Commit.Make(Hash)end)end