···
11
+
| Renamed (p, _) -> p
type t = diff list [@@deriving repr]
···
|> List.filter (function [] -> false | _ -> true)
List.filter_map parse_row tsv
47
+
type tree = Leaf of diff | Dir of string * tree list
49
+
let rec insert modified path_components tree =
50
+
match (path_components, tree) with
52
+
| [ file ], nodes ->
53
+
if List.exists (function Leaf f -> path f = file | _ -> false) nodes
58
+
| Modified _ -> Modified file
59
+
| Created _ -> Created file
60
+
| Renamed (_, to_) -> Renamed (file, to_)
61
+
| Removed _ -> Removed file
64
+
| dir :: rest, nodes ->
65
+
let rec insert_into_dir acc = function
66
+
| [] -> Dir (dir, insert modified rest []) :: List.rev acc
67
+
| Dir (name, children) :: tl when name = dir ->
68
+
List.rev_append acc (Dir (name, insert modified rest children) :: tl)
69
+
| x :: tl -> insert_into_dir (x :: acc) tl
71
+
insert_into_dir [] nodes
73
+
let to_tree (diffs : diff list) =
75
+
List.map (fun v -> (v, String.split_on_char '/' (path v))) diffs
77
+
List.fold_left (fun acc (m, p) -> insert m p acc) [] paths
80
+
let rec loop acc acc2 = function
81
+
| Leaf (Modified v) -> Modified (Filename.concat acc v) :: acc2
82
+
| Leaf (Created v) -> Created (Filename.concat acc v) :: acc2
83
+
| Leaf (Removed v) -> Removed (Filename.concat acc v) :: acc2
84
+
| Leaf (Renamed (r1, r2)) -> Renamed (Filename.concat acc r1, r2) :: acc2
86
+
List.fold_left (fun lvs v -> loop (Filename.concat acc p) lvs v) acc2 cs
90
+
let pp_diff fmt = function
91
+
| Modified v -> Fmt.(styled (`Fg `Yellow) string) fmt ("~ /" ^ v)
92
+
| Created v -> Fmt.(styled (`Fg `Green) string) fmt ("+ /" ^ v)
93
+
| Removed v -> Fmt.(styled (`Fg `Red) string) fmt ("- /" ^ v)
94
+
| Renamed (v, _) -> Fmt.(styled (`Fg `Magenta) string) fmt ("| /" ^ v)
97
+
let tree = to_tree diffs in
99
+
List.fold_left (fun acc v -> leaves v @ acc) [] tree
100
+
|> List.filter (fun v ->
102
+
(String.starts_with ~prefix:"shelter" (path v)
103
+
|| String.starts_with ~prefix:"tmp" (path v)))
105
+
Fmt.pf fmt "%a" Fmt.(list ~sep:Format.pp_force_newline pp_diff) lvs