From 331f1d2baa0bafa32d8bfc3d947ae3af7fc12796 Mon Sep 17 00:00:00 2001 From: Marius Peter Date: Sun, 29 Jun 2025 01:09:09 +0200 Subject: Differentiate (sub-)tree and blob views. --- lib/handlers.ml | 6 ++++-- lib/resolvers.ml | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/handlers.ml b/lib/handlers.ml index 76cdf42..5f67199 100644 --- a/lib/handlers.ml +++ b/lib/handlers.ml @@ -29,8 +29,10 @@ module Repo = struct let file_id req = let repo = Dream.param req "repo" in let id = Dream.param req "id" in - let* blob = Resolvers.Blob.of_id repo id in - Views.Repo.file repo blob + let* res = Resolvers.blob_or_tree repo id in + match res with + | `Tree tree -> Views.Repo.files repo tree + | `Blob blob -> Views.Repo.file repo blob let refs req = let repo = Dream.param req "repo" in diff --git a/lib/resolvers.ml b/lib/resolvers.ml index 741c797..0db0e10 100644 --- a/lib/resolvers.ml +++ b/lib/resolvers.ml @@ -139,3 +139,12 @@ module Blob = struct | Git.Value.Blob blob -> Lwt_result.return (to_t blob) | _ -> Lwt_result.fail @@ `Msg ("no blob matches id " ^ id) end + +let blob_or_tree repo id = + let* store = store repo in + let hash = Store.Hash.of_hex id in + let* obj = Store.read store hash in + match obj with + | Git.Value.Tree tree -> Lwt_result.return @@ `Tree (Tree.to_t tree) + | Git.Value.Blob blob -> Lwt_result.return @@ `Blob (Blob.to_t blob) + | _ -> Lwt_result.fail @@ `Msg ("No tree or blob matches id " ^ id) -- cgit v1.2.3