Persistent store with Git semantics: lazy reads, delayed writes, content-addressing
at benchs 40 lines 1.4 kB view raw
1(** Tree command. *) 2 3let run ~repo ~branch ~output path = 4 let config = Config.load ~repo () in 5 let (module B : Common.BACKEND) = Common.backend_of_config config in 6 Eio_main.run @@ fun env -> 7 let fs = Eio.Stdenv.cwd env in 8 Eio.Switch.run @@ fun sw -> 9 let store = B.open_store ~sw ~fs ~config in 10 match B.checkout store ~branch with 11 | None -> 12 Common.error "Branch %a not found" Common.styled_cyan branch; 13 1 14 | Some tree -> 15 let start_path = 16 match path with None -> [] | Some p -> Common.path_of_string p 17 in 18 let rec walk indent path = 19 let entries = B.tree_list tree path in 20 List.iter 21 (fun (name, kind) -> 22 let full_path = path @ [ name ] in 23 match kind with 24 | `Contents -> ( 25 match output with 26 | `Human -> Fmt.pr "%s%s@." indent name 27 | `Json -> 28 Fmt.pr {|{"path":%S,"type":"file"}@.|} 29 (String.concat "/" full_path)) 30 | `Node -> 31 (match output with 32 | `Human -> Fmt.pr "%s%a/@." indent Common.styled_blue name 33 | `Json -> 34 Fmt.pr {|{"path":%S,"type":"dir"}@.|} 35 (String.concat "/" full_path)); 36 walk (indent ^ " ") full_path) 37 entries 38 in 39 walk "" start_path; 40 0