[OCaml] Mobile-friendly clone of cgit.
Rename repo_name to repo.
Changed files
lib/git_helpers.ml
@@ -1,22 +1,20 @@
1
Removed:
open Lwt.Infix
2
1
module Store = Git_unix.Store
3
Removed:
module Value = Git.Value
4
2
5
Removed:
type user_record = { name : string; email : string }
6
Removed:
7
3
let full_path path = Filename.concat Config.git_directory path
8
4
9
Removed:
let store repo_path =
10
Removed:
let path = Fpath.v @@ full_path repo_path in
5
Added:
let store repo =
6
Added:
let path = Fpath.v @@ full_path repo in
11
7
Store.v ~dotgit:path path
12
8
13
9
let short_hash hash = String.sub hash 0 8
14
10
15
Removed:
let repo_description repo_path =
16
Removed:
let description_path = Filename.concat (full_path repo_path) "description" in
11
Added:
let repo_description repo =
12
Added:
let description_path = Filename.concat (full_path repo) "description" in
17
13
In_channel.with_open_text description_path In_channel.input_all
18
14
19
15
module Commit = struct
16
Added:
open Lwt_result.Syntax
17
Added:
20
18
type t = {
21
19
hash : string;
22
20
parents : string list;
@@ -25,8 +23,9 @@
25
23
}
26
24
27
25
let of_hash store h =
28
Removed:
Store.read store h >>= function
29
Removed:
| Ok (Value.Commit c) ->
26
Added:
let* v = Store.read store h in
27
Added:
match v with
28
Added:
| Git.Value.Commit c ->
30
29
Lwt_result.return
31
30
{
32
31
hash = Store.Hash.to_hex h;
@@ -34,29 +33,25 @@
34
33
author = Store.Value.Commit.author c;
35
34
message = Store.Value.Commit.message c;
36
35
}
37
Removed:
| Ok _ -> Lwt_result.fail (`Msg "object is not a commit")
38
Removed:
| Error e -> Lwt_result.fail e
36
Added:
| _ -> Lwt_result.fail @@ `Msg "value is not a commit"
39
37
40
Removed:
let recent_commits repo_path n =
41
Removed:
let open Lwt_result.Syntax in
42
Removed:
let* store = store repo_path in
38
Added:
let recent_commits repo n =
39
Added:
let* store = store repo in
43
40
let* head = Store.Ref.resolve store Git.Reference.head in
44
41
let rec walk acc hash count =
45
42
if count = 0 then Lwt_result.return (List.rev acc)
46
43
else
47
Removed:
of_hash store hash >>= function
48
Removed:
| Error e -> Lwt_result.fail e
49
Removed:
| Ok commit -> (
50
Removed:
match commit.parents with
51
Removed:
| parent :: _ ->
52
Removed:
walk (commit :: acc) (Store.Hash.of_hex parent) (count - 1)
53
Removed:
| [] -> Lwt_result.return (List.rev (commit :: acc)))
44
Added:
let* commit = of_hash store hash in
45
Added:
match commit.parents with
46
Added:
| parent :: _ ->
47
Added:
walk (commit :: acc) (Store.Hash.of_hex parent) (count - 1)
48
Added:
| [] -> Lwt_result.return (List.rev (commit :: acc))
54
49
in
55
50
walk [] head n
56
51
57
Removed:
let of_id repo_path id =
52
Added:
let of_id repo id =
58
53
let open Lwt_result.Syntax in
59
Removed:
let* store = store repo_path in
54
Added:
let* store = store repo in
60
55
let id = Store.Hash.of_hex id in
61
56
of_hash store id
62
57
end
@@ -64,9 +59,9 @@
64
59
module Branch = struct
65
60
type t = { name : string }
66
61
67
Removed:
let all_branches repo_path =
62
Added:
let all_branches repo =
68
63
let open Lwt_result.Syntax in
69
Removed:
let* store = Git_unix.Store.v (Fpath.v repo_path) in
64
Added:
let* store = Git_unix.Store.v (Fpath.v repo) in
70
65
let open Lwt.Syntax in
71
66
let* refs = Store.Ref.list store in
72
67
let branches =
@@ -74,4 +69,8 @@
74
69
List.map (function _, x -> x |> Store.Hash.to_hex) refs
75
70
in
76
71
Lwt_result.return branches
72
Added:
end
73
Added:
74
Added:
module User = struct
75
Added:
type t = Git.User.t
77
76
end
lib/handlers.ml
@@ -9,23 +9,22 @@
9
9
let root _req = Views.root () |> Dream_html.respond
10
10
11
11
module Repo = struct
12
Removed:
let repo_path req = Dream.param req "repo_name"
12
Added:
let repo req = Dream.param req "repo_name"
13
13
14
14
let summary req =
15
Removed:
let* branches = Git_helpers.Branch.all_branches (repo_path req) in
16
Removed:
let* commits = Git_helpers.Commit.recent_commits (repo_path req) 10 in
15
Added:
let* branches = Git_helpers.Branch.all_branches (repo req) in
16
Added:
let* commits = Git_helpers.Commit.recent_commits (repo req) 10 in
17
17
let authors = [ "John Pork"; "Sebastian Jellybean" ] in
18
Removed:
Views.Repo.summary (repo_path req) branches commits authors
19
Removed:
|> Dream_html.respond
18
Added:
Views.Repo.summary (repo req) branches commits authors |> Dream_html.respond
20
19
21
Removed:
let refs req = Views.Repo.refs (repo_path req) |> Dream_html.respond
22
Removed:
let log req = Views.Repo.log (repo_path req) |> Dream_html.respond
23
Removed:
let tree req = Views.Repo.tree (repo_path req) |> Dream_html.respond
20
Added:
let refs req = Views.Repo.refs (repo req) |> Dream_html.respond
21
Added:
let log req = Views.Repo.log (repo req) |> Dream_html.respond
22
Added:
let tree req = Views.Repo.tree (repo req) |> Dream_html.respond
24
23
25
24
let commit req =
26
25
let id = match Dream.query req "id" with Some id -> id | None -> "" in
27
Removed:
let* commit = Git_helpers.Commit.of_id (repo_path req) id in
28
Removed:
Views.Repo.commit (repo_path req) commit |> Dream_html.respond
26
Added:
let* commit = Git_helpers.Commit.of_id (repo req) id in
27
Added:
Views.Repo.commit (repo req) commit |> Dream_html.respond
29
28
end
30
29
31
30
let all_handlers =
lib/views.ml
@@ -10,14 +10,14 @@
10
10
module Components = struct
11
11
open Dream_html
12
12
13
Removed:
let topnav repo_path =
13
Added:
let topnav repo =
14
14
let open HTML in
15
Removed:
let () = Dream.log "%s" ("current path is: " ^ repo_path) in
15
Added:
let () = Dream.log "%s" ("current path is: " ^ repo) in
16
16
let li_of_a (path, text) =
17
17
let () = Dream.log "%s" ("and path is: " ^ path) in
18
Removed:
let is_active = String.ends_with ~suffix:path repo_path in
18
Added:
let is_active = String.ends_with ~suffix:path repo in
19
19
let attrs = if is_active then [ id "active" ] else [] in
20
Removed:
let url = Printf.sprintf "/%s/%s" repo_path path in
20
Added:
let url = Printf.sprintf "/%s/%s" repo path in
21
21
li attrs [ a [ href "%s" url ] [ txt text ] ]
22
22
in
23
23
nav
@@ -96,7 +96,7 @@
96
96
Page.render body_data
97
97
98
98
module Repo = struct
99
Removed:
let summary repo_path branches commits authors =
99
Added:
let summary repo branches commits authors =
100
100
let open Dream_html in
101
101
let li_of_branch branch =
102
102
HTML.(li [] [ a [ href "%s" branch ] [ txt "%s" branch ] ])
@@ -129,53 +129,53 @@
129
129
in
130
130
Page.render
131
131
{
132
Removed:
title = repo_path;
133
Removed:
subtitle = Git_helpers.repo_description repo_path;
134
Removed:
topnav = Components.topnav repo_path;
132
Added:
title = repo;
133
Added:
subtitle = Git_helpers.repo_description repo;
134
Added:
topnav = Components.topnav repo;
135
135
content;
136
136
}
137
137
138
Removed:
let refs repo_path =
138
Added:
let refs repo =
139
139
let open Dream_html in
140
140
Page.render
141
141
HTML.
142
142
{
143
Removed:
title = repo_path;
144
Removed:
subtitle = Git_helpers.repo_description repo_path;
145
Removed:
topnav = Components.topnav repo_path;
143
Added:
title = repo;
144
Added:
subtitle = Git_helpers.repo_description repo;
145
Added:
topnav = Components.topnav repo;
146
146
content = [ null [] ];
147
147
}
148
148
149
Removed:
let log repo_path =
149
Added:
let log repo =
150
150
let open Dream_html in
151
151
Page.render
152
152
HTML.
153
153
{
154
Removed:
title = repo_path;
155
Removed:
subtitle = Git_helpers.repo_description repo_path;
156
Removed:
topnav = Components.topnav repo_path;
154
Added:
title = repo;
155
Added:
subtitle = Git_helpers.repo_description repo;
156
Added:
topnav = Components.topnav repo;
157
157
content = [ null [] ];
158
158
}
159
159
160
Removed:
let tree repo_path =
160
Added:
let tree repo =
161
161
let open Dream_html in
162
162
Page.render
163
163
HTML.
164
164
{
165
Removed:
title = repo_path;
166
Removed:
subtitle = Git_helpers.repo_description repo_path;
167
Removed:
topnav = Components.topnav repo_path;
165
Added:
title = repo;
166
Added:
subtitle = Git_helpers.repo_description repo;
167
Added:
topnav = Components.topnav repo;
168
168
content = [ null [] ];
169
169
}
170
170
171
Removed:
let commit repo_path (commit : Git_helpers.Commit.t) =
171
Added:
let commit repo (commit : Git_helpers.Commit.t) =
172
172
let open Dream_html in
173
173
let open Git_helpers in
174
174
let message = match commit.message with Some msg -> msg | None -> "" in
175
175
let content = HTML.[ h3 [] [ txt "%s" message ] ] in
176
Removed:
let title = Printf.sprintf "%s : %s" repo_path (short_hash commit.hash) in
176
Added:
let title = Printf.sprintf "%s : %s" repo (short_hash commit.hash) in
177
177
Page.render
178
Removed:
{ title; subtitle = ""; topnav = Components.topnav repo_path; content }
178
Added:
{ title; subtitle = ""; topnav = Components.topnav repo; content }
179
179
end
180
180
181
181
let error_page message =