Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file loose.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232let()=Printexc.record_backtracetrueletsrc=Logs.Src.create"git.loose"~doc:"logs git's loose event"moduleLog=(valLogs.src_logsrc:Logs.LOG)type('a,'s)io=('a,'s)Carton.iolet(<.>)fgx=f(gx)moduletypeUID=sigincludeCarton.UIDvalto_hex:t->stringendtypekind=[`A|`B|`C|`D]type('t,'brk,'error,'s)store={map:'t->'brk->pos:int64->int->(Bigstringaf.t,'s)io;mem:'t->'brk->(bool,'s)io;list:'t->('brklist,'s)io;append:'t->'brk->Bigstringaf.t->((unit,'error)result,'s)io;appendv:'t->'brk->Bigstringaf.tlist->((unit,'error)result,'s)io;}typebuffers={window:De.window;queue:De.Queue.t;i:De.bigstring;o:De.bigstring;hdr:Cstruct.t;}letreword_errorfx=matchxwithOkx->Okx|Errorerr->Error(ferr)moduleMake(Uid:UID)=structletlisttstore=store.listtletexistststoreuid=store.memtuidletatomic_add{Carton.return;bind}tbuffersstore~hdrv=let(>>=)=bindinlet(>>|)xf=x>>=funx->return(fx)inlet(>>?)xf=x>>=functionOkx->fx|Error_aserr->returnerrinlethdr=hdr~buffer:buffers.hdrvinDe.Queue.resetbuffers.queue;letencoder=Zl.Def.encoder`Manual`Manual~q:buffers.queue~w:buffers.window~level:2in(* TODO(dinosaure): delete [rec], we should have only one [`Flush] and [`End]. *)letrecgoencodersrcsdst=matchsrcs,Zl.Def.encodeencoderwith|src::srcs,`Awaitencoder->letencoder=Zl.Def.srcencoder(Cstruct.to_bigarraysrc)0(Cstruct.lensrc)ingoencodersrcsdst|[],`Awaitencoder->letencoder=Zl.Def.srcencoderBigstringaf.empty00ingoencoder[]dst|_,`Flushencoder->letlen=Cstruct.lendst-Zl.Def.dst_remencoderiniflen=Cstruct.lendstthenError`Non_atomicelseletdst=Cstruct.shiftdstleningo(Zl.Def.dstencoder(Cstruct.to_bigarraydst)0(Cstruct.lendst))srcsdst|_,`Endencoder->letlen=Cstruct.lendst-Zl.Def.dst_remencoderinRresult.R.ok(Cstruct.len(Cstruct.shiftdstlen))inletencoder=Zl.Def.dstencoderbuffers.o0(Bigstringaf.lengthbuffers.o)inletcontents=Cstruct.of_bigarray(Carton.Dec.rawv)~off:0~len:(Carton.Dec.lenv)inletuid=letfoldctxpayload=Uid.feedctx(Cstruct.to_bigarraypayload)inletctx=List.fold_leftfoldUid.empty[hdr;contents]inUid.getctxinmatchgoencoder[hdr;contents](Cstruct.of_bigarraybuffers.o)with|Okrest->letlen=Bigstringaf.lengthbuffers.o-restinLog.debug(funm->m"Atomic write of %a."Uid.ppuid);store.appendtuid(Bigstringaf.subbuffers.o~off:0~len)>>|reword_error(funerr->`Storeerr)>>?fun()->return(Ok(uid,len))|Error_aserr->returnerrletadd{Carton.return;bind}tbuffersstore~hdrstream=let(>>=)=bindinlet(>>|)xf=x>>=funx->return(fx)inlet(>>?)xf=x>>=functionOkx->fx|Error_aserr->returnerrinDe.Queue.resetbuffers.queue;letencoder=Zl.Def.encoder`Manual`Manual~q:buffers.queue~w:buffers.window~level:2inletrecgoctx((src,off,len)aspayload)dstsencoder=matchZl.Def.encodeencoderwith|`Awaitencoder->(iflen>0then(letmax=minlen(Bigstringaf.lengthbuffers.i)inBigstringaf.blit_from_stringsrc~src_off:offbuffers.i~dst_off:0~len:max;letctx=Uid.feedctxbuffers.i~off:0~len:maxinletencoder=Zl.Def.srcencoderbuffers.i0maxingoctx(src,off+max,len-max)dstsencoder)elsestream()>>=function|Somesrc->goctx(src,0,String.lengthsrc)dstsencoder|None->letencoder=Zl.Def.srcencoderBigstringaf.empty00ingoctxpayloaddstsencoder)|`Flushencoder->letlen=Bigstringaf.lengthbuffers.o-Zl.Def.dst_remencoderinletraw=Bigstringaf.copybuffers.o~off:0~leninletencoder=Zl.Def.dstencoderbuffers.o0(Bigstringaf.lengthbuffers.o)ingoctxpayload(raw::dsts)encoder|`Endencoder->letlen=Bigstringaf.lengthbuffers.o-Zl.Def.dst_remencoderinletraw=Bigstringaf.copybuffers.o~off:0~leninreturn(Uid.getctx,List.rev(raw::dsts))inletencoder=Zl.Def.dstencoderbuffers.o0(Bigstringaf.lengthbuffers.o)ingoUid.empty(Cstruct.to_stringhdr,0,Cstruct.lenhdr)[]encoder>>=fun(uid,vs)->letlen=List.fold_right((+)<.>Bigstringaf.length)vs0in(* XXX(dinosaure): shame! *)Log.debug(funm->m"Append(v) %a into the minor heap."Uid.ppuid);store.appendvtuidvs>>|reword_error(funerr->`Storeerr)>>?fun()->return(Ok(uid,len))letatomic_get{Carton.return;bind}tbuffersstore~hdruid=let(>>=)=bindinstore.maptuid~pos:0L(Bigstringaf.lengthbuffers.i)>>=funi->letdecoder=Zl.Inf.decoder`Manual~allocate:(fun_->buffers.window)~o:buffers.oinletdecoder=Zl.Inf.srcdecoderi0(Bigstringaf.lengthi)inletres=matchZl.Inf.decodedecoderwith|`Await_->Error`Non_atomic|`Malformed_->Error`Non_atomic|`Flushdecoder->letlen=Bigstringaf.lengthbuffers.o-Zl.Inf.dst_remdecoderinOk(Zl.Inf.flushdecoder,len)|`End_->Ok(Zl.Inf.flushdecoder,0)inletopenRresultinmatchreswith|Ok(_,len)->letraw=Cstruct.of_bigarraybuffers.o~off:0~leninletcontents,kind,length=hdrrawinifInt64.of_int(Cstruct.lencontents)<>lengththenreturn(Error`Non_atomic)elsereturn(Ok(Carton.Dec.v~kind(Cstruct.to_bigarraycontents)))|Error_aserr->returnerrletsize_and_kind{Carton.return;bind}tbuffersstore~hdruid=let(>>=)=bindinstore.maptuid~pos:0L(2+286+1+20+1)>>=funi->letdecoder=Zl.Inf.decoder`Manual~allocate:(fun_->buffers.window)~o:buffers.oinletdecoder=Zl.Inf.srcdecoderi0(Bigstringaf.lengthi)inletres=matchZl.Inf.decodedecoderwith|`Await_->letlen=Bigstringaf.lengthbuffers.o-Zl.Inf.dst_remdecoderinOklen|`Malformed_->Error`Malformed|`Flushdecoder->letlen=Bigstringaf.lengthbuffers.o-Zl.Inf.dst_remdecoderinOklen|`End_->Error`MalformedinletopenRresultinmatchreswith|Oklen->letraw=Cstruct.of_bigarraybuffers.o~off:0~leninlet_contents,kind,length=hdrrawinreturn(Ok(length,kind))|Error_aserr->returnerrletget{Carton.return;bind}tbuffersstore~hdruid=let(>>=)=bindinlet(>>?)xf=x>>=functionOkx->fx|Error_aserr->returnerrinletdecoder=Zl.Inf.decoder`Manual~allocate:(fun_->buffers.window)~o:buffers.oinletrecgoposdstsdecoder=matchZl.Inf.decodedecoderwith|`Awaitdecoder->store.maptuid~pos(Bigstringaf.lengthbuffers.i)>>=funi->letlen=Bigstringaf.lengthiinletdecoder=Zl.Inf.srcdecoderi0leningoInt64.(addpos(of_intlen))dstsdecoder|`Flushdecoder->letlen=Bigstringaf.lengthbuffers.o-Zl.Inf.dst_remdecoderingopos(Bigstringaf.copybuffers.o~off:0~len::dsts)(Zl.Inf.flushdecoder)|`Malformederr->return(Rresult.R.error_msgerr)|`Enddecoder->letlen=Bigstringaf.lengthbuffers.o-Zl.Inf.dst_remdecoderinreturn(Ok(List.rev(Bigstringaf.copybuffers.o~off:0~len::dsts)))ingo0L[]decoder>>?funvs->letraw=Cstruct.concat(List.mapCstruct.of_bigarrayvs)in(* XXX(dinosaure): ropes? *)letcontents,kind,_length=hdrrawin(* assert (_length = len); *)return(Ok(Carton.Dec.v~kind(Cstruct.to_bigarraycontents)))end