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/resolvers.ml | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'lib/resolvers.ml') 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