Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file loose_git.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160letsrc=Logs.Src.create"git.loose"~doc:"logs git's loose event"moduleLog=(valLogs.src_logsrc:Logs.LOG)moduletypeSTORE=sigtypettypeuidtypeerrortype+'afibervalpp_error:errorFmt.tvalexists:t->uid->boolfibervallength:t->uid->(int64,error)resultfibervalmap:t->uid->pos:int64->int->Bigstringaf.tfibervalappend:t->uid->Bigstringaf.t->(unit,error)resultfibervalappendv:t->uid->Bigstringaf.tlist->(unit,error)resultfibervallist:t->uidlistfibervalreset:t->(unit,error)resultfiberendmoduletypeIO=sigtype+'atvalbind:'at->('a->'bt)->'btvalreturn:'a->'atendmoduleMake(Scheduler:Carton.SCHEDULER)(IO:IOwithtype+'at='aScheduler.s)(Store:STOREwithtype+'afiber='aScheduler.s)(Uid:Loose.UIDwithtypet=Store.uid)=structlet(>>=)=IO.bindletreturn=IO.returnletio=letopenSchedulerin{Carton.bind=(funxf->inj(prjx>>=funx->prj(fx)));Carton.return=(funx->inj(returnx));}(* XXX(dinosaure): at this layer, [loose] can ask something bigger than
the length of [uid]. So we fix it with this process and return as
much as we can. *)letstore_maprootuid~poslen=ifpos<0L||len<0theninvalid_arg"store_map: invalid bounds";Store.lengthrootuid>>=function|Error_->returnBigstringaf.empty|Okmax->letlen=min(Int64.addpos(Int64.of_intlen))(Int64.submaxpos)inletlen=Int64.to_intleninStore.maprootuid~poslenletstore_memrootuid=Store.existsrootuidletstore_appendrootuidpayload=Store.appendrootuidpayloadletstore_appendvrootuidpayloads=Store.appendvrootuidpayloadsletstore_listroot=Store.listrootletstore={Loose.map=(funtuid~poslen->Scheduler.inj(store_maptuid~poslen));Loose.mem=(funtuid->Scheduler.inj(store_memtuid));Loose.append=(funtuidv->Scheduler.inj(store_appendtuidv));Loose.appendv=(funtuidvs->Scheduler.inj(store_appendvtuidvs));Loose.list=(funt->Scheduler.inj(store_listt));}letspace=Cstruct.of_string" "letzero=Cstruct.of_string"\000"(* TODO(dinosaure): integrate it into [cstruct]. *)letcut~sep:({Cstruct.len=sep_len;_}assep)({Cstruct.len;_}ast)=ifsep_len=0theninvalid_arg"cut: empty separator";letmax_sep_zidx=sep_len-1inletmax_t_zidx=len-sep_leninletreccheck_sepik=ifk>max_sep_zidxthenSome(Cstruct.subt0i,Cstruct.subt(i+sep_len)(len-sep_len-i))elseifCstruct.get_chart(i+k)=Cstruct.get_charsepkthencheck_sepi(succk)elsescan(succi)andscani=ifi>max_t_zidxthenNoneelseifCstruct.get_charti=Cstruct.get_charsep0thencheck_sepi1elsescan(succi)inscan0lethdr_getraw=matchcut~sep:spacerawwith|None->failwith"Invalid Git header"|Some(kind,rest)->(matchcut~sep:zerorestwith|Some(length,contents)->letlength=Int64.of_string(Cstruct.to_stringlength)inletkind=matchCstruct.to_stringkindwith|"commit"->`A|"blob"->`C|"tag"->`D|"tree"->`B|v->Fmt.failwith"Invalid type of Git object: %s"vincontents,kind,length|None->failwith"Invalid Git header")lethdr_set~buffer(kind,length)=letkind=matchkindwith|`Commit->"commit"|`Tree->"tree"|`Blob->"blob"|`Tag->"tag"inCstruct.blit_from_stringkind0buffer0(String.lengthkind);Cstruct.set_charbuffer(String.lengthkind)' ';letlength=Int64.to_stringlengthinCstruct.blit_from_stringlength0buffer(String.lengthkind+1)(String.lengthlength);Cstruct.set_charbuffer(String.lengthkind+1+String.lengthlength)'\000';Cstruct.subbuffer0(String.lengthkind+1+String.lengthlength+1)includeLoose.Make(Uid)letlistt=Scheduler.prj(store.listt)letexiststuid=Scheduler.prj(existststoreuid)letatomic_addtbuffersv=lethdr_set~bufferv=letkind=matchCarton.Dec.kindvwith|`A->`Commit|`B->`Tree|`C->`Blob|`D->`Taginletlength=Int64.of_int(Carton.Dec.lenv)inhdr_set~buffer(kind,length)inScheduler.prj(atomic_addiotbuffersstore~hdr:hdr_setv)letaddtbuffers(kind,length)stream=lethdr=hdr_set~buffer:(Cstruct.create30)(kind,length)inletstream()=Scheduler.inj(stream())inScheduler.prj(addiotbuffersstore~hdrstream)letatomic_gettbufferuid=Scheduler.prj(atomic_getiotbufferstore~hdr:hdr_getuid)letsize_and_kindtbuffersuid=Scheduler.prj(size_and_kindiotbuffersstore~hdr:hdr_getuid)letgettbufferuid=Scheduler.prj(getiotbufferstore~hdr:hdr_getuid)end