123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899(*
* 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.
*)openImportlet(>>?)=Lwt_result.bindmoduleMake(G:Git.S)(S:Git.Sync.Swithtypehash:=G.hashandtypestore:=G.t)(B:Irmin.Branch.S)=structletsrc=Logs.Src.create"irmin.git-remote"~doc:"Git remote"moduleGitlog=(valLogs.src_logsrc:Logs.LOG)moduleH=Irmin.Hash.Make(G.Hash)typet=G.ttypecommit=H.ttypebranch=B.ttypeendpoint=Mimic.ctx*Smart_git.Endpoint.tletgit_of_branch_strstr=Git.Reference.v("refs/heads/"^str)letgit_of_branchr=git_of_branch_str(Irmin.Type.to_stringB.tr)(* let o_head_of_git = function None -> Ok None | Some k -> Ok (Some k) *)letmsgffmt=Fmt.kstr(funerr->`Msgerr)fmtletreword_errorf=functionOk_asv->v|Errorerr->Error(ferr)letfetcht?depth(ctx,e)br=[%log.debug"fetch %a"Smart_git.Endpoint.ppe];letpush_stdoutmsg=Gitlog.info(funf->f"%s"msg)andpush_stderrmsg=Gitlog.warn(funf->f"%s"msg)anddeepen=matchdepthwithSomedepth->Some(`Depthdepth)|None->Noneandreference=git_of_branchbrandcapabilities=[`Side_band_64k;`Multi_ack_detailed;`Ofs_delta;`Thin_pack;`Report_status;]inS.fetch~push_stdout~push_stderr~capabilities~ctxet?deepen(`Some[(reference,reference)])>>=function|Error`Not_found->Lwt.return(Error(`Msg"not found"))|Error(`Msgerr)->Lwt.return(Error(`Msgerr))|Error(`Exnerr)->Lwt.return(Error(`Msg(Printexc.to_stringerr)))|Errorerr->Fmt.kstr(fune->Lwt.return(Error(`Msge)))"%a"S.pp_errorerr|OkNone->Lwt.return(OkNone)|Ok(Some(_,[(reference,hash)]))->letvalue=Git.Reference.uidhashinletbr=Git.Reference.v("refs/remotes/origin/"^Irmin.Type.to_stringB.tbr)inG.Ref.writetbrvalue>|=reword_error(msgf"%a"G.pp_error)>>?fun()->G.Ref.writetreferencevalue>|=reword_error(msgf"%a"G.pp_error)>>?fun()->Lwt.return(Ok(Somehash))|_->assertfalseletpusht?depth:_(ctx,e)br=[%log.debug"push %a"Smart_git.Endpoint.ppe];letreference=git_of_branchbrinletcapabilities=[`Side_band_64k;`Multi_ack_detailed;`Ofs_delta;`Thin_pack;`Report_status;]inS.push~capabilities~ctxet[`Update(reference,reference)]>|=function|Error(`Msgerr)->Error(`Msgerr)|Error(`Exnexn)->Error(`Msg(Printexc.to_stringexn))|Error`Not_found->Error(`Msg"not found")|Errorerr->Error(`Msg(Fmt.str"%a"S.pp_errorerr))|Ok()->Ok()end