123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113(*******************************************************************************)(* Volgo - a Versatile OCaml Library for Git Operations *)(* Copyright (C) 2024-2025 Mathieu Barbin <mathieu.barbin@gmail.com> *)(* *)(* This file is part of Volgo. *)(* *)(* Volgo is free software; you can redistribute it and/or modify it under *)(* the terms of the GNU Lesser General Public License as published by the *)(* Free Software Foundation either version 3 of the License, or any later *)(* version, with the LGPL-3.0 Linking Exception. *)(* *)(* Volgo is distributed in the hope that it will be useful, but WITHOUT ANY *)(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *)(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *)(* the file `NOTICE.md` at the root of this repository for more details. *)(* *)(* You should have received a copy of the GNU Lesser General Public License *)(* and the LGPL-3.0 Linking Exception along with this library. If not, see *)(* <http://www.gnu.org/licenses/> and <https://spdx.org>, respectively. *)(*******************************************************************************)moduleStatus_code=structmoduleT=struct[@@@coverageoff]typet=|Dash|Numofint|Otherofstringletto_dyn=function|Dash->Dyn.Variant("Dash",[])|Numn->Dyn.Variant("Num",[Dyn.intn])|Others->Dyn.Variant("Other",[Dyn.strings]);;letsexp_of_tt=Dyn.to_sexp(to_dynt)endincludeTletparse=function|"-"->Dash|status->(matchInt.of_string_optstatuswith|Somenwhenn>=0->Numn|Some_|None->Otherstatus);;endletparse_line_exn~line:Vcs.Num_status.Change.t=matchVcs.Private.try_with(fun()->matchString.splitline~on:'\t'with|[]->assertfalse|[_]|[_;_]|_::_::_::_::_->raise(Err.E(Err.create[Pp.text"Unexpected output from git diff."]))|[insertions;deletions;munged_path]->{Vcs.Num_status.Change.key=Munged_path.parse_exnmunged_path;num_stat=(matchStatus_code.parseinsertions,Status_code.parsedeletionswith|Dash,Dash->Binary_file|Numinsertions,Numdeletions->Num_lines_in_diff{insertions;deletions}|insertions,deletions->raise(Err.E(Err.create[Pp.text"Unexpected output from git diff.";Err.sexp(Sexp.List[sexp_field(moduleStatus_code)"insertions"insertions;sexp_field(moduleStatus_code)"deletions"deletions])])))})with|Okt->t|Errorerr->raise(Err.E(Err.add_contexterr[Err.sexp(Sexp.List[Sexp.Atom"Volgo_git_backend.Num_status.parse_line_exn";sexp_field(moduleString)"line"line])]));;letparse_lines_exn~lines=List.maplines~f:(funline->parse_line_exn~line)moduleMake(Runtime:Runtime.S)=structtypet=Runtime.tletnum_statust~repo_root~(changed:Vcs.Name_status.Changed.t)=letchanged_param=matchchangedwith|Between{src;dst}->Printf.sprintf"%s..%s"(src|>Vcs.Rev.to_string)(dst|>Vcs.Rev.to_string)inRuntime.gitt~cwd:(repo_root|>Vcs.Repo_root.to_absolute_path)~args:["diff";"--numstat";changed_param]~f:(funoutput->letopenResult.Syntaxinlet*stdout=Vcs.Git.Result.exit0_and_stdoutoutputinVcs.Private.try_with(fun()->parse_lines_exn~lines:(String.split_linesstdout)));;end