Reintroduce branches.

Commit
08a42b99a2ba69e953dc5ffd7e2b429f2f808874
Author
Marius Peter <marius.peter@tutanota.com>
Author date
Committer
Marius Peter <marius.peter@tutanota.com>
Committer date
Changed files
lib/handlers.ml
index e63e911a..7a37b207 100644..100644
@@ -4,8 +4,7 @@
4 4
5 5 module Repo = struct
6 6 let ( let* ) m f =
7 Removed: let open Lwt.Infix in
8 Removed: m >>= function
7 Added: Lwt.bind m @@ function
9 8 | Ok x -> f x
10 9 | Error e ->
11 10 let msg = Format.asprintf "%a" Resolvers.Store.pp_error e in
@@ -13,11 +12,10 @@
13 12
14 13 let summary req =
15 14 let repo = Dream.param req "repo" in
16 Removed: (* let* branches = Resolvers.Branch.all repo in *)
17 Removed: (* let* commits = Resolvers.Commit.recent repo 10 in *)
18 Removed: let* commits = Resolvers.Commit.head repo in
15 Added: let* branches = Resolvers.Branch.all repo in
16 Added: let* commits = Resolvers.Commit.recent repo 10 in
19 17 let authors = [ "John Pork"; "Sebastian Jellybean" ] in
20 Removed: Views.Repo.summary repo () [commits] authors
18 Added: Views.Repo.summary repo branches commits authors
21 19
22 20 let log req =
23 21 let repo = Dream.param req "repo" in
@@ -37,8 +35,8 @@
37 35
38 36 let refs req =
39 37 let repo = Dream.param req "repo" in
40 Removed: (* let* branches = Resolvers.Branch.all repo in *)
41 Removed: Views.Repo.refs repo ()
38 Added: let* branches = Resolvers.Branch.all repo in
39 Added: Views.Repo.refs repo branches
42 40
43 41 let commit req =
44 42 let repo = Dream.param req "repo" in
lib/resolvers.ml
index 9baa116d..f7bf31ab 100644..100644
@@ -31,7 +31,7 @@
31 31 let to_t c =
32 32 let open Store.Value in
33 33 {
34 Removed: hash = Store.Value.Commit.digest c |> Store.Hash.to_hex;
34 Added: hash = Commit.digest c |> Store.Hash.to_hex;
35 35 parents = Commit.parents c |> List.map Store.Hash.to_hex;
36 36 author = Commit.author c;
37 37 message = Commit.message c;
@@ -64,36 +64,35 @@
64 64 walk [] head_commit.hash n
65 65 end
66 66
67 Removed: (* module Branch = struct *)
68 Removed: (* type t = { hash : string; name : string } *)
67 Added: module Branch = struct
68 Added: type t = { name : string; hash : string }
69 69
70 Removed: (* let to_t (branch : Store.Reference.t) = *)
71 Removed: (* { *)
72 Removed: (* hash = Store.Reference.hash branch ; *)
73 Removed: (* name = Store.Reference.contents branch; *)
74 Removed: (* } *)
70 Added: let to_t (reference, hash) = { name = reference; hash }
75 71
76 Removed: (* let of_id repo id = *)
77 Removed: (* let* store = store repo in *)
78 Removed: (* let hash = Store.Hash.of_hex id in *)
79 Removed: (* Store.Ref.resolve store hash *)
80 Removed: (* |> Lwt_result.map @@ function *)
81 Removed: (* | Git.Reference.Ref branch -> to_t branch *)
82 Removed: (* | _ -> failwith "no head tree id" *)
72 Added: let all repo =
73 Added: let* store = store repo in
74 Added: let open Lwt.Syntax in
75 Added: let* refs = Store.Ref.list store in
76 Added: let branches =
77 Added: List.map
78 Added: (fun (reference, hash) ->
79 Added: let name = Git.Reference.to_string reference in
80 Added: let hash = Store.Hash.to_hex hash in
81 Added: { name; hash })
82 Added: refs
83 Added: in
84 Added: Lwt_result.return branches
83 85
84 Removed: (* let all repo = *)
85 Removed: (* let* store = store repo in *)
86 Removed: (* let* refs = Store.Ref.list store in *)
87 Removed: (* let branches = *)
88 Removed: (* List.map *)
89 Removed: (* (fun (reference, hash) -> *)
90 Removed: (* let name = Git.Reference.to_string reference in *)
91 Removed: (* let hash = Store.Hash.to_hex hash in *)
92 Removed: (* { name; hash }) *)
93 Removed: (* refs *)
94 Removed: (* in *)
95 Removed: (* Lwt_result.return branches *)
96 Removed: (* end *)
86 Added: let of_id repo id =
87 Added: let* branches = all repo in
88 Added: let branch =
89 Added: branches
90 Added: |> List.find_opt (fun branch -> Filename.basename branch.name = id)
91 Added: in
92 Added: match branch with
93 Added: | Some branch -> Lwt_result.return branch
94 Added: | None -> Lwt_result.fail @@ `Msg ("Found no branch matching " ^ id)
95 Added: end
97 96
98 97 module Entry = struct
99 98 type t = { hash : string; name : string; perm : int }
lib/views.ml
index ca012fcb..3a5de9d1 100644..100644
@@ -95,25 +95,27 @@
95 95
96 96 let li_of_author author = HTML.(li [] [ txt "%s" author ])
97 97
98 Removed: (* let li_of_branch repo (branch : Resolvers.Branch.t) = *)
99 Removed: (* HTML.(li [] [ Routes.link_to (Refs repo) (txt "%s" branch.name) ]) *)
98 Added: let li_of_branch repo (branch : Resolvers.Branch.t) =
99 Added: HTML.(li [] [ Routes.link_to (Refs repo) (txt "%s" branch.name) ])
100 100
101 101 let li_of_commit repo (commit : Resolvers.Commit.t) =
102 Removed: let open HTML in
103 102 let short_hash = Resolvers.short_hash commit.hash in
104 Removed: match commit.message with
105 Removed: | None -> li [] [ txt "%s" short_hash ]
106 Removed: | Some msg ->
107 Removed: li []
108 Removed: [
109 Removed: Routes.link_to
110 Removed: (Commit (repo, commit.hash))
111 Removed: (null
112 Removed: [
113 Removed: span [ class_ "commit-hash" ] [ txt "%s" short_hash ];
114 Removed: txt " — %s" msg;
115 Removed: ]);
116 Removed: ]
103 Added: let content =
104 Added: match commit.message with
105 Added: | None -> txt "%s" short_hash
106 Added: | Some msg ->
107 Added: let route = Routes.Commit (repo, commit.hash) in
108 Added: let node =
109 Added: HTML.(
110 Added: null
111 Added: [
112 Added: span [ class_ "commit-hash" ] [ txt "%s" short_hash ];
113 Added: txt " — %s" msg;
114 Added: ])
115 Added: in
116 Added: Routes.link_to route node
117 Added: in
118 Added: HTML.li [] [ content ]
117 119
118 120 let li_of_entry repo (entry : Resolvers.Entry.t) =
119 121 let display_name =
@@ -125,12 +127,12 @@
125 127 in
126 128 HTML.(li [] [ Routes.link_to route @@ txt "%s" display_name ])
127 129
128 Removed: let summary repo _branches commits authors =
130 Added: let summary repo branches commits authors =
129 131 let content =
130 132 HTML.
131 133 [
132 134 h3 [] [ txt "Branches" ];
133 Removed: (* ul [] (List.map (li_of_branch repo) branches); *)
135 Added: ul [] (List.map (li_of_branch repo) branches);
134 136 h3 [] [ txt "Latest commits" ];
135 137 ul [] (List.map (li_of_commit repo) commits);
136 138 h3 [] [ txt "Authors" ];
@@ -146,12 +148,12 @@
146 148 content;
147 149 }
148 150
149 Removed: let refs repo _branches =
151 Added: let refs repo branches =
150 152 let content =
151 153 HTML.
152 154 [
153 155 h3 [] [ txt "Branches" ];
154 Removed: (* ul [] (List.map (li_of_branch repo) branches); *)
156 Added: ul [] (List.map (li_of_branch repo) branches);
155 157 ]
156 158 in
157 159 respond