[OCaml] Mobile-friendly clone of cgit.
Differentiate (sub-)tree and blob views.
Changed files
lib/handlers.ml
@@ -29,8 +29,10 @@
29
29
let file_id req =
30
30
let repo = Dream.param req "repo" in
31
31
let id = Dream.param req "id" in
32
Removed:
let* blob = Resolvers.Blob.of_id repo id in
33
Removed:
Views.Repo.file repo blob
32
Added:
let* res = Resolvers.blob_or_tree repo id in
33
Added:
match res with
34
Added:
| `Tree tree -> Views.Repo.files repo tree
35
Added:
| `Blob blob -> Views.Repo.file repo blob
34
36
35
37
let refs req =
36
38
let repo = Dream.param req "repo" in
lib/resolvers.ml
@@ -139,3 +139,12 @@
139
139
| Git.Value.Blob blob -> Lwt_result.return (to_t blob)
140
140
| _ -> Lwt_result.fail @@ `Msg ("no blob matches id " ^ id)
141
141
end
142
Added:
143
Added:
let blob_or_tree repo id =
144
Added:
let* store = store repo in
145
Added:
let hash = Store.Hash.of_hex id in
146
Added:
let* obj = Store.read store hash in
147
Added:
match obj with
148
Added:
| Git.Value.Tree tree -> Lwt_result.return @@ `Tree (Tree.to_t tree)
149
Added:
| Git.Value.Blob blob -> Lwt_result.return @@ `Blob (Blob.to_t blob)
150
Added:
| _ -> Lwt_result.fail @@ `Msg ("No tree or blob matches id " ^ id)