Link branches on summary page to their commit history

- Add Commits_branch route (/:repo/commits/:branch) - Add Commit.recent_from to walk commits from a given hash - Add commits_branch handler resolving branch ref then listing commits - Branch links on summary page now go to commits for that branch

Commit
bad677d1fa0e96fa03b5825ca3dc1658ba7b43a5
Author
Marius Peter <dev@marius-peter.com>
Author date
Committer
Marius Peter <dev@marius-peter.com>
Committer date
Changed files
lib/handlers.ml
index c9b3653a..39558628 100644..100644
@@ -28,6 +28,11 @@
28 28 let* commits = Resolvers.Commit.recent repo 100 in
29 29 Views.Repo.commits repo commits
30 30
31 Added: let commits_branch repo branch =
32 Added: let* ref = Resolvers.Reference.of_id repo branch in
33 Added: let* commits = Resolvers.Commit.recent_from repo ref.hash 100 in
34 Added: Views.Repo.commits repo commits
35 Added:
31 36 let commit_id repo id =
32 37 let* commit = Resolvers.Commit.of_id repo id in
33 38 let* diff = Resolvers.Diff.of_commit repo commit in
@@ -70,6 +75,7 @@
70 75 get "/" (handle summary);
71 76 get "/summary/" (handle summary);
72 77 get "/commits/" (handle commits);
78 Added: get "/commits/:id" (handle_id commits_branch);
73 79 get "/commit/:id" (handle_id commit_id);
74 80 get "/files/" (handle files_at_head);
75 81 get "/file/:id" (handle_id file_id);
lib/resolvers.ml
index db51bed5..f80137ed 100644..100644
@@ -168,6 +168,17 @@
168 168 | [] -> Lwt_result.return (List.rev (commit :: acc))
169 169 in
170 170 walk [] head_commit.hash n
171 Added:
172 Added: let recent_from repo hash n =
173 Added: let rec walk acc hash count =
174 Added: if count = 0 then Lwt_result.return (List.rev acc)
175 Added: else
176 Added: let* commit = of_id repo hash in
177 Added: match commit.parents with
178 Added: | parent_hash :: _ -> walk (commit :: acc) parent_hash (count - 1)
179 Added: | [] -> Lwt_result.return (List.rev (commit :: acc))
180 Added: in
181 Added: walk [] hash n
171 182 end
172 183
173 184 module Reference = struct
lib/routes.ml
index 5c93ce42..e1f9f13e 100644..100644
@@ -4,6 +4,7 @@
4 4 | Root
5 5 | Repo of string
6 6 | Commits of string
7 Added: | Commits_branch of string * string
7 8 | Commit of string * string
8 9 | Files of string
9 10 | File of string * string
@@ -14,6 +15,7 @@
14 15 let%path root_path = "/"
15 16 let%path repo_path = "/%s/summary/"
16 17 let%path commits_path = "/%s/commits/"
18 Added: let%path commits_branch_path = "/%s/commits/%s"
17 19 let%path commit_path = "/%s/commit/%s"
18 20 let%path files_path = "/%s/files/"
19 21 let%path file_path = "/%s/file/%s"
@@ -28,6 +30,7 @@
28 30 | Root -> path_attr href root_path
29 31 | Repo repo -> path_attr href repo_path repo
30 32 | Commits repo -> path_attr href commits_path repo
33 Added: | Commits_branch (repo, branch) -> path_attr href commits_branch_path repo branch
31 34 | Commit (repo, commit) -> path_attr href commit_path repo commit
32 35 | Files repo -> path_attr href files_path repo
33 36 | File (repo, hash) -> path_attr href file_path repo hash
lib/views.ml
index e55cffa8..63273f69 100644..100644
@@ -135,7 +135,7 @@
135 135 HTML.(li [] [ txt "%s" author.name ])
136 136
137 137 let li_of_branch repo (branch : Resolvers.Reference.t) =
138 Removed: HTML.(li [] [ Routes.link_to (Branches repo) (txt "%s" branch.name) ])
138 Added: HTML.(li [] [ Routes.link_to (Commits_branch (repo, branch.name)) (txt "%s" branch.name) ])
139 139
140 140 let li_of_tag repo (tag : Resolvers.Reference.t) =
141 141 HTML.(li [] [ Routes.link_to (Tags repo) (txt "%s" tag.name) ])