Refactor + proper implementation for refs and log handlers.

Commit
0a46c9b495557f4634a543c43cdc8fb920c76303
Author
Marius Peter <marius.peter@tutanota.com>
Author date
Committer
Marius Peter <marius.peter@tutanota.com>
Committer date
lib/handlers.ml
index 6b3df29e..8771f5f1 100644..100644
@@ -1,31 +1,39 @@
1 1 (* -*- mode: tuareg; -*- *)
2 2
3 Removed: let ( let* ) m f =
4 Removed: let open Lwt.Infix in
5 Removed: m >>= function
6 Removed: | Ok x -> f x
7 Removed: | Error e ->
8 Removed: let msg = Format.asprintf "%a" Git_unix.Store.pp_error e in
9 Removed: Views.error_page msg |> Dream_html.respond
10 Removed:
11 3 let root _req = Views.root () |> Dream_html.respond
12 4
13 5 module Repo = struct
6 Added: open Git_presenters
7 Added:
8 Added: let ( let* ) m f =
9 Added: let open Lwt.Infix in
10 Added: m >>= function
11 Added: | Ok x -> f x
12 Added: | Error e ->
13 Added: let msg = Format.asprintf "%a" Git_unix.Store.pp_error e in
14 Added: Views.error_page msg |> Dream_html.respond
15 Added:
14 16 let repo req = Dream.param req "repo_name"
15 17
16 18 let summary req =
17 Removed: let* branches = Git_presenters.Branch.all_branches (repo req) in
18 Removed: let* commits = Git_presenters.Commit.recent_commits (repo req) 10 in
19 Added: let* branches = all_branches (repo req) in
20 Added: let* commits = recent_commits (repo req) 10 in
19 21 let authors = [ "John Pork"; "Sebastian Jellybean" ] in
20 22 Views.Repo.summary (repo req) branches commits authors |> Dream_html.respond
21 23
22 Removed: let refs req = Views.Repo.refs (repo req) |> Dream_html.respond
23 Removed: let log req = Views.Repo.log (repo req) |> Dream_html.respond
24 Added: let refs req =
25 Added: let* branches = all_branches (repo req) in
26 Added: Views.Repo.refs (repo req) branches |> Dream_html.respond
27 Added:
28 Added: let log req =
29 Added: let* commits = recent_commits (repo req) 100 in
30 Added: Views.Repo.log (repo req) commits |> Dream_html.respond
31 Added:
24 32 let tree req = Views.Repo.tree (repo req) |> Dream_html.respond
25 33
26 34 let commit req =
27 35 let id = match Dream.query req "id" with Some id -> id | None -> "" in
28 Removed: let* commit = Git_presenters.Commit.of_id (repo req) id in
36 Added: let* commit = of_id (repo req) id in
29 37 Views.Repo.commit (repo req) commit |> Dream_html.respond
30 38 end
31 39