Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file tag.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207(*
* Copyright (c) 2013-2017 Thomas Gazagnaire <thomas@gazagnaire.org>
* and Romain Calascibetta <romain.calascibetta@gmail.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.
*)typekind=Blob|Commit|Tag|Treetype'hasht={obj:'hash;kind:kind;tag:string;tagger:User.toption;message:string;}moduletypeS=sigtypehashtypenonrect=hashtvalmake:hash->kind->?tagger:User.t->tag:string->string->tvalformat:tEncore.tincludeS.DIGESTwithtypet:=tandtypehash:=hashincludeS.BASEwithtypet:=tvallength:t->int64valobj:t->hashvaltag:t->stringvalmessage:t->stringvalkind:t->kindvaltagger:t->User.toptionendmoduleMake(Hash:S.HASH)=structtypehash=Hash.ttypenonrect=hashtletmaketargetkind?tagger~tagmessage={obj=target;kind;tag;tagger;message}letpp_kindppf=function|Blob->Fmt.stringppf"Blob"|Commit->Fmt.stringppf"Commit"|Tag->Fmt.stringppf"Tag"|Tree->Fmt.stringppf"Tree"letppppf{obj;kind;tag;tagger;message}=Fmt.pfppf"{ @[<hov>obj = %a;@ kind = %a;@ tag = %s;@ tagger = %a;@ message = %a@] \
}"Hash.ppobjpp_kindkindtag(Fmt.hvbox(Fmt.optionUser.pp))tagger(Fmt.hvboxFmt.text)messageletstring_of_kind=function|Commit->"commit"|Tag->"tag"|Tree->"tree"|Blob->"blob"moduleSyntax=structletsafe_exnfx=tryfxwith_->raiseEncore.Bij.Bijectionlethex=Encore.Bij.v~fwd:(safe_exnHash.of_hex)~bwd:(safe_exnHash.to_hex)letuser=Encore.Bij.v~fwd:(funstr->matchAngstrom.parse_string~consume:Angstrom.Consume.All(Encore.to_angstromUser.format)strwith|Okv->v|Error_->raiseEncore.Bij.Bijection)~bwd:(funv->Encore.Lavoisier.emit_stringv(Encore.to_lavoisierUser.format))letkind=Encore.Bij.v~fwd:(function|"tree"->Tree|"blob"->Blob|"commit"->Commit|"tag"->Tag|_->raiseEncore.Bij.Bijection)~bwd:(function|Blob->"blob"|Tree->"tree"|Commit->"commit"|Tag->"tag")lettag=Encore.Bij.v~fwd:(fun((_,obj),(_,kind),(_,tag),tagger,message)->{obj;kind;tag;tagger=Stdlib.Option.mapsndtagger;message})~bwd:(fun{obj;kind;tag;tagger;message}->lettagger=Stdlib.Option.map(funx->"tagger",x)taggerin("object",obj),("type",kind),("tag",tag),tagger,message)letis_not_spchr=chr<>' 'letis_not_lfchr=chr<>'\x0a'letalwaysx_=xletrest=letopenEncore.SyntaxinletopenEncore.Eitherinfix@@funm->letcons=Encore.Bij.cons<$>(while0(alwaystrue)<*commit<*>m)inletnil=pure~compare:(fun()()->true)()inEncore.Bij.v~fwd:(functionLcons->cons|R()->[])~bwd:(function_::_aslst->Llst|[]->R())<$>peekconsnilletrest:stringEncore.t=letopenEncore.SyntaxinEncore.Bij.v~fwd:(String.concat"")~bwd:(funx->[x])<$>restletbinding?keyvalue=letopenEncore.Syntaxinletvalue=value<$>(while1is_not_lf<*(Encore.Bij.char'\x0a'<$>any))inmatchkeywith|Somekey->constkey<*(Encore.Bij.char' '<$>any)<*>value|None->while1is_not_sp<*(Encore.Bij.char' '<$>any)<*>valuelett=letopenEncore.Syntaxinbinding~key:"object"hex<*>binding~key:"type"kind<*>binding~key:"tag"Encore.Bij.identity<*>option(binding~key:"tagger"user)<*>restletformat=Encore.Syntax.mapEncore.Bij.(composeobj5tag)tendletformat=Syntax.formatletlengtht=letstringx=Int64.of_int(String.lengthx)inlet(+)=Int64.addinletuser_length=matcht.taggerwith|Someuser->string"tagger"+1L+User.lengthuser+1L|None->0Linstring"object"+1L+Int64.of_int(Hash.digest_size*2)+1L+string"type"+1L+string(string_of_kindt.kind)+1L+string"tag"+1L+stringt.tag+1L+user_length+stringt.messageletdigestvalue=Stream.digest{Stream.empty=Hash.empty;Stream.feed_string=(funstrctx->Hash.feed_stringctxstr);Stream.feed_bigstring=(funbstrctx->Hash.feed_bigstringctxbstr);Stream.get=Hash.get;}`Taglength(Encore.to_lavoisierformat)valueletobj{obj;_}=objlettag{tag;_}=tagletmessage{message;_}=messageletkind{kind;_}=kindlettagger{tagger;_}=taggerletequal=(=)letcompare=Stdlib.comparelethash=Hashtbl.hashmoduleSet=Set.Make(structtypenonrect=tletcompare=compareend)moduleMap=Map.Make(structtypenonrect=tletcompare=compareend)end