diff options
| author | Marius Peter <marius.peter@tutanota.com> | 2025-06-29 01:09:09 +0200 | 
|---|---|---|
| committer | Marius Peter <marius.peter@tutanota.com> | 2025-06-29 01:09:09 +0200 | 
| commit | 331f1d2baa0bafa32d8bfc3d947ae3af7fc12796 (patch) | |
| tree | ae94c09f870fab78c64f9e3e657feae3567bd5b2 /lib | |
| parent | b56bdde770615fb5c59f34d3f5c58d70ca9ad73b (diff) | |
Differentiate (sub-)tree and blob views.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/handlers.ml | 6 | ||||
| -rw-r--r-- | 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) | 
