[OCaml] Mobile-friendly clone of cgit.
Refactor miscellaneous functions.
Changed files
lib/git_presenters.ml
@@ -2,8 +2,8 @@
2
2
3
3
module Store = Git_unix.Store
4
4
open Lwt_result.Syntax
5
Removed:
open Config
6
5
open Lwt_result.Infix
6
Added:
open Config
7
7
8
8
let full_path path = Filename.concat config.git_project_root path
9
9
@@ -29,8 +29,7 @@
29
29
}
30
30
31
31
let to_commit store hash =
32
Removed:
let* v = Store.read store hash in
33
Removed:
match v with
32
Added:
Store.read store hash >>= function
34
33
| Git.Value.Commit c ->
35
34
let hash = Store.Hash.to_hex hash in
36
35
Lwt_result.return
@@ -102,14 +101,12 @@
102
101
let short_hash = String.sub hash 0 8 in
103
102
{ hash; short_hash; name = entry.name; perm }
104
103
105
Removed:
let present_tree tree = Store.Value.Tree.to_list tree |> List.map to_entry
106
Removed:
107
104
let to_tree store hash =
108
105
Store.read store hash >>= function
109
106
| Git.Value.Tree tree ->
110
107
let hash = Store.Hash.to_hex hash in
111
108
let short_hash = String.sub hash 0 8 in
112
Removed:
let entries = present_tree tree in
109
Added:
let entries = Store.Value.Tree.to_list tree |> List.map to_entry in
113
110
Lwt_result.return { hash; short_hash; entries }
114
111
| _ -> Lwt_result.fail (`Msg "value is not a tree")
115
112
@@ -118,7 +115,7 @@
118
115
| Git.Value.Blob blob ->
119
116
let content = Store.Value.Blob.to_string blob in
120
117
Lwt_result.return { content }
121
Removed:
| _ -> Lwt_result.fail (`Msg "value is not a tree")
118
Added:
| _ -> Lwt_result.fail (`Msg "value is not a blob")
122
119
123
120
let head_tree_id store =
124
121
Store.Ref.resolve store Git.Reference.head >>= Store.read store >>= function
@@ -133,10 +130,10 @@
133
130
134
131
let tree_of_id repo id =
135
132
let* store = store repo in
136
Removed:
let* hash = Lwt_result.return (Store.Hash.of_hex id) in
133
Added:
let hash = Store.Hash.of_hex id in
137
134
to_tree store hash
138
135
139
136
let blob_of_id repo id =
140
137
let* store = store repo in
141
Removed:
let* hash = Lwt_result.return (Store.Hash.of_hex id) in
138
Added:
let hash = Store.Hash.of_hex id in
142
139
to_blob store hash
lib/handlers.ml
@@ -22,28 +22,28 @@
22
22
let authors = [ "John Pork"; "Sebastian Jellybean" ] in
23
23
Views.Repo.summary (repo req) branches commits authors |> Dream_html.respond
24
24
25
Removed:
let refs req =
26
Removed:
let* branches = all_branches (repo req) in
27
Removed:
Views.Repo.refs (repo req) branches |> Dream_html.respond
28
Removed:
29
25
let log req =
30
26
let* commits = recent_commits (repo req) 100 in
31
27
Views.Repo.log (repo req) commits |> Dream_html.respond
32
28
33
Removed:
let tree_head req =
29
Added:
let files_at_head req =
34
30
let* tree = head_tree (repo req) in
35
Removed:
Views.Repo.tree (repo req) tree |> Dream_html.respond
31
Added:
Views.Repo.files (repo req) tree |> Dream_html.respond
36
32
37
Removed:
let tree_id req =
33
Added:
let files_id req =
38
34
let id = id_of_req req in
39
35
let* tree = tree_of_id (repo req) id in
40
Removed:
Views.Repo.tree (repo req) tree |> Dream_html.respond
36
Added:
Views.Repo.files (repo req) tree |> Dream_html.respond
41
37
42
Removed:
let blob_id req =
38
Added:
let file_id req =
43
39
let id = id_of_req req in
44
40
let* blob = blob_of_id (repo req) id in
45
Removed:
Views.Repo.blob (repo req) blob |> Dream_html.respond
41
Added:
Views.Repo.file (repo req) blob |> Dream_html.respond
46
42
43
Added:
let refs req =
44
Added:
let* branches = all_branches (repo req) in
45
Added:
Views.Repo.refs (repo req) branches |> Dream_html.respond
46
Added:
47
47
let commit req =
48
48
let id = id_of_req req in
49
49
let* commit = commit_of_id (repo req) id in
@@ -58,11 +58,12 @@
58
58
Repo.
59
59
[
60
60
get "/" summary;
61
Removed:
get "/refs/" refs;
61
Added:
get "/summary/" summary;
62
62
get "/log/" log;
63
Removed:
get "/tree/" tree_head;
64
Removed:
get "/tree/:id" tree_id;
65
Removed:
get "/blob/:id" blob_id;
63
Added:
get "/files/" files_at_head;
64
Added:
get "/files/:id" files_id;
65
Added:
get "/file/:id" file_id;
66
Added:
get "/refs/" refs;
66
67
get "/commit/:id" commit;
67
68
];
68
69
get "/static/**" (static "./lib/static");
lib/views.ml
@@ -76,7 +76,7 @@
76
76
let all_repositories =
77
77
let repos =
78
78
Sys.readdir config.git_project_root
79
Removed:
|> Array.to_list |> List.sort String.compare
79
Added:
|> Array.to_list (* |> List.sort String.compare *)
80
80
in
81
81
let li_of_repo repo =
82
82
HTML.li [] [ Routes.link_to (Routes.Repo repo) (txt "%s" repo) ]
@@ -100,8 +100,7 @@
100
100
let li_of_author author = HTML.(li [] [ txt "%s" author ])
101
101
102
102
let li_of_branch repo (branch : branch) =
103
Removed:
HTML.(
104
Removed:
li [] [ Routes.link_to (Tag (repo, branch.name)) (txt "%s" branch.name) ])
103
Added:
HTML.(li [] [ Routes.link_to (Refs repo) (txt "%s" branch.name) ])
105
104
106
105
let li_of_commit repo commit =
107
106
let open HTML in
@@ -124,8 +123,8 @@
124
123
if entry.perm = 0o040000 then entry.name ^ "/" else entry.name
125
124
in
126
125
let route =
127
Removed:
if entry.perm = 0o040000 then Routes.Tree (repo, entry.hash)
128
Removed:
else Routes.Blob (repo, entry.hash)
126
Added:
if entry.perm = 0o040000 then Routes.Files repo
127
Added:
else Routes.File (repo, entry.hash)
129
128
in
130
129
HTML.(li [] [ Routes.link_to route @@ txt "%s" display_name ])
131
130
@@ -135,7 +134,7 @@
135
134
[
136
135
h3 [] [ txt "Branches" ];
137
136
ul [] (List.map (li_of_branch repo) branches);
138
Removed:
h3 [] [ txt "Recent commits" ];
137
Added:
h3 [] [ txt "Latest commits" ];
139
138
ul [] (List.map (li_of_commit repo) commits);
140
139
h3 [] [ txt "Authors" ];
141
140
ul [] (List.map li_of_author authors);
@@ -181,12 +180,12 @@
181
180
content;
182
181
}
183
182
184
Removed:
let tree repo tree =
183
Added:
let files repo tree =
185
184
let title = Printf.sprintf "%s" repo in
186
185
let content =
187
186
HTML.
188
187
[
189
Removed:
h3 [] [ txt "Tree %s" tree.short_hash ];
188
Added:
h3 [] [ txt "Files %s" tree.short_hash ];
190
189
ul [] (List.map (li_of_entry repo) tree.entries);
191
190
]
192
191
in
@@ -219,7 +218,7 @@
219
218
{
220
219
title;
221
220
subtitle = repo_description repo;
222
Removed:
topnav = Components.topnav repo;
221
Added:
topnav = Components.Topnav.(v ~active_path:Files repo);
223
222
content;
224
223
}
225
224