···55 | Removed of string
66[@@deriving repr]
7788+let path = function
99+ | Modified p -> p
1010+ | Created p -> p
1111+ | Renamed (p, _) -> p
1212+ | Removed p -> p
1313+814type t = diff list [@@deriving repr]
9151016let truncate_path s =
···3743 |> List.filter (function [] -> false | _ -> true)
3844 in
3945 List.filter_map parse_row tsv
4646+4747+type tree = Leaf of diff | Dir of string * tree list
4848+4949+let rec insert modified path_components tree =
5050+ match (path_components, tree) with
5151+ | [], _ -> tree
5252+ | [ file ], nodes ->
5353+ if List.exists (function Leaf f -> path f = file | _ -> false) nodes
5454+ then nodes
5555+ else
5656+ let diff =
5757+ match modified with
5858+ | Modified _ -> Modified file
5959+ | Created _ -> Created file
6060+ | Renamed (_, to_) -> Renamed (file, to_)
6161+ | Removed _ -> Removed file
6262+ in
6363+ Leaf diff :: nodes
6464+ | dir :: rest, nodes ->
6565+ let rec insert_into_dir acc = function
6666+ | [] -> Dir (dir, insert modified rest []) :: List.rev acc
6767+ | Dir (name, children) :: tl when name = dir ->
6868+ List.rev_append acc (Dir (name, insert modified rest children) :: tl)
6969+ | x :: tl -> insert_into_dir (x :: acc) tl
7070+ in
7171+ insert_into_dir [] nodes
7272+7373+let to_tree (diffs : diff list) =
7474+ let paths =
7575+ List.map (fun v -> (v, String.split_on_char '/' (path v))) diffs
7676+ in
7777+ List.fold_left (fun acc (m, p) -> insert m p acc) [] paths
7878+7979+let leaves =
8080+ let rec loop acc acc2 = function
8181+ | Leaf (Modified v) -> Modified (Filename.concat acc v) :: acc2
8282+ | Leaf (Created v) -> Created (Filename.concat acc v) :: acc2
8383+ | Leaf (Removed v) -> Removed (Filename.concat acc v) :: acc2
8484+ | Leaf (Renamed (r1, r2)) -> Renamed (Filename.concat acc r1, r2) :: acc2
8585+ | Dir (p, cs) ->
8686+ List.fold_left (fun lvs v -> loop (Filename.concat acc p) lvs v) acc2 cs
8787+ in
8888+ loop "" []
8989+9090+let pp_diff fmt = function
9191+ | Modified v -> Fmt.(styled (`Fg `Yellow) string) fmt ("~ /" ^ v)
9292+ | Created v -> Fmt.(styled (`Fg `Green) string) fmt ("+ /" ^ v)
9393+ | Removed v -> Fmt.(styled (`Fg `Red) string) fmt ("- /" ^ v)
9494+ | Renamed (v, _) -> Fmt.(styled (`Fg `Magenta) string) fmt ("| /" ^ v)
9595+9696+let pp fmt diffs =
9797+ let tree = to_tree diffs in
9898+ let lvs =
9999+ List.fold_left (fun acc v -> leaves v @ acc) [] tree
100100+ |> List.filter (fun v ->
101101+ not
102102+ (String.starts_with ~prefix:"shelter" (path v)
103103+ || String.starts_with ~prefix:"tmp" (path v)))
104104+ in
105105+ Fmt.pf fmt "%a" Fmt.(list ~sep:Format.pp_force_newline pp_diff) lvs
+1-3
src/lib/shelter/shelter_main.ml
···166166167167(* Fork a new session from an existing one *)
168168let display_history (s : entry H.t) =
169169- let pp_diff fmt d =
170170- if d = [] then () else Fmt.pf fmt "\n %a" (Repr.pp Diff.t) d
171171- in
169169+ let pp_diff fmt d = if d = [] then () else Fmt.pf fmt "\n%a%!" Diff.pp d in
172170 let pp_entry fmt (e : entry) =
173171 Fmt.pf fmt "%-10s %s%a"
174172 Fmt.(str "%a" (styled (`Fg `Yellow) uint64_ns_span) e.post.time)