• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mbarbin / vcs / 16

04 Apr 2024 01:48PM UTC coverage: 99.944% (-0.06%) from 100.0%
16

push

github

mbarbin
Update .gitignore

1771 of 1772 relevant lines covered (99.94%)

24.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.33
/lib/git_cli/src/num_status.ml
1
(*******************************************************************************)
2
(*  Vcs - a versatile OCaml library for Git interaction                        *)
3
(*  Copyright (C) 2024 Mathieu Barbin <mathieu.barbin@gmail.com>               *)
4
(*                                                                             *)
5
(*  This file is part of Vcs.                                                  *)
6
(*                                                                             *)
7
(*  Vcs is free software; you can redistribute it and/or modify it under       *)
8
(*  the terms of the GNU Lesser General Public License as published by the     *)
9
(*  Free Software Foundation either version 3 of the License, or any later     *)
10
(*  version, with the LGPL-3.0 Linking Exception.                              *)
11
(*                                                                             *)
12
(*  Vcs is distributed in the hope that it will be useful, but WITHOUT ANY     *)
13
(*  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS  *)
14
(*  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and    *)
15
(*  the file `NOTICE.md` at the root of this repository for more details.      *)
16
(*                                                                             *)
17
(*  You should have received a copy of the GNU Lesser General Public License   *)
18
(*  and the LGPL-3.0 Linking Exception along with this library. If not, see    *)
19
(*  <http://www.gnu.org/licenses/> and <https://spdx.org>, respectively.       *)
20
(*******************************************************************************)
21

22
let parse_line_exn ~line : Vcs.Num_status.Change.t =
23
  match String.split line ~on:'\t' with
155✔
24
  | [] -> assert false
25
  | [ _ ] | [ _; _ ] | _ :: _ :: _ :: _ :: _ ->
1✔
26
    raise_s [%sexp "Unexpected output from git diff", (line : string)]
27
  | [ insertions; deletions; munged_path ] ->
151✔
28
    { Vcs.Num_status.Change.key = Munged_path.parse_exn munged_path
150✔
29
    ; num_stat =
30
        (match insertions, deletions with
31
         | "-", _ | _, "-" -> Binary_file
×
32
         | insertions, deletions ->
147✔
33
           Num_lines_in_diff
34
             { insertions = Int.of_string insertions
146✔
35
             ; deletions = Int.of_string deletions
146✔
36
             })
37
    }
38
;;
39

40
let parse_lines_exn ~lines = List.map lines ~f:(fun line -> parse_line_exn ~line)
8✔
41

42
module Make (Runtime : Runtime.S) = struct
43
  type t = Runtime.t
44

45
  let diff t ~repo_root ~(changed : Vcs.Name_status.Changed.t) =
46
    let changed_param =
5✔
47
      match changed with
48
      | Between { src; dst } ->
5✔
49
        Printf.sprintf "%s..%s" (src |> Vcs.Rev.to_string) (dst |> Vcs.Rev.to_string)
5✔
50
    in
51
    Runtime.git
52
      t
53
      ~cwd:(repo_root |> Vcs.Repo_root.to_absolute_path)
5✔
54
      ~args:[ "diff"; "--numstat"; changed_param ]
55
      ~f:(fun output ->
56
        let%bind stdout = Vcs.Git.exit0_and_stdout output in
5✔
57
        Or_error.try_with (fun () -> parse_lines_exn ~lines:(String.split_lines stdout)))
5✔
58
  ;;
59
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc