diff --git a/src/git_kv.ml b/src/git_kv.ml index 97375be..8f4c7b5 100644 --- a/src/git_kv.ml +++ b/src/git_kv.ml @@ -143,9 +143,22 @@ let get_partial t key ~offset ~length = let l = min length (String.length data - offset) in String.sub data offset l -let list _t _key = - (* ((string * [`Value | `Dictionary]) list, error) result Lwt.t *) - assert false +let list t key = + let open Lwt.Infix in + match t.head with + | None -> Lwt.return (Error (`Not_found key)) + | Some head -> + Search.find t.store head (`Path (Mirage_kv.Key.segments key)) >>= function + | None -> Lwt.return (Error (`Not_found key)) + | Some tree -> + Store.read_exn t.store tree >>= function + | Tree t -> + Lwt_list.map_p (fun { Git.Tree.perm; name; _ } -> match perm with + | `Commit | `Dir -> Lwt.return (name, `Dictionary) + | `Everybody | `Exec | `Normal -> Lwt.return (name, `Value) + | `Link -> failwith "Unimplemented link follow") + (Store.Value.Tree.to_list t) >|= Result.ok + | _ -> Lwt.return (Error (`Dictionary_expected key)) let last_modified t key = let open Lwt.Infix in