[OCaml] Mobile-friendly clone of cgit.
Add TOML config management.
lib/config.ml
@@ -1,2 +1,26 @@
1
Removed:
let git_directory = Filename.concat (Unix.getenv "HOME") "git.test"
2
Removed:
let author = "Marius Peter"
1
Added:
let config_file = "default_config.toml"
2
Added:
3
Added:
type t = {
4
Added:
repositories_root : string;
5
Added:
user : string;
6
Added:
default_branch : string;
7
Added:
max_commits_displayed : int;
8
Added:
}
9
Added:
10
Added:
let config =
11
Added:
match Toml.Parser.from_filename config_file with
12
Added:
| `Error (e, _) -> failwith ("Config parse error: " ^ e)
13
Added:
| `Ok table ->
14
Added:
let find key = Toml.Types.Table.find (Toml.Min.key key) table in
15
Added:
let find_string key =
16
Added:
match find key with TString s -> s | _ -> raise Not_found
17
Added:
in
18
Added:
let find_int key =
19
Added:
match find key with TInt i -> i | _ -> raise Not_found
20
Added:
in
21
Added:
{
22
Added:
repositories_root = find_string "repositories_root";
23
Added:
user = find_string "user";
24
Added:
default_branch = find_string "default_branch";
25
Added:
max_commits_displayed = find_int "max_commits_displayed";
26
Added:
}
lib/default_config.toml
@@ -0,0 +1,4 @@
1
Added:
repositories_root = "~/git.test/"
2
Added:
user = "Marius Peter"
3
Added:
default_branch = "master"
4
Added:
max_commits_displayed = 100
lib/dune
@@ -1,5 +1,3 @@
1
1
(library
2
2
(name ogit)
3
Removed:
(libraries dream dream-html git git-unix)
4
Removed:
(preprocess
5
Removed:
(pps lwt_ppx)))
3
Added:
(libraries dream dream-html git-unix toml))
lib/git_presenters.ml
@@ -1,13 +1,12 @@
1
1
module Store = Git_unix.Store
2
Added:
open Config
2
3
3
Removed:
let full_path path = Filename.concat Config.git_directory path
4
Added:
let full_path path = Filename.concat config.repositories_root path
4
5
5
6
let store repo =
6
7
let path = Fpath.v @@ full_path repo in
7
8
Store.v ~dotgit:path path
8
9
9
Removed:
let short_hash hash = String.sub hash 0 8
10
Removed:
11
10
let repo_description repo =
12
11
let description_path = Filename.concat (full_path repo) "description" in
13
12
In_channel.with_open_text description_path In_channel.input_all
@@ -21,18 +20,21 @@
21
20
22
21
type t = {
23
22
hash : string;
23
Added:
short_hash : string;
24
24
parents : string list;
25
25
author : User.t;
26
26
message : string option;
27
27
}
28
28
29
Removed:
let of_hash store h =
29
Added:
let to_commit store h =
30
30
let* v = Store.read store h in
31
31
match v with
32
32
| Git.Value.Commit c ->
33
Added:
let hash = Store.Hash.to_hex h in
33
34
Lwt_result.return
34
35
{
35
Removed:
hash = Store.Hash.to_hex h;
36
Added:
hash;
37
Added:
short_hash = String.sub hash 0 8;
36
38
parents = Store.Value.Commit.parents c |> List.map Store.Hash.to_hex;
37
39
author = Store.Value.Commit.author c;
38
40
message = Store.Value.Commit.message c;
@@ -45,7 +47,7 @@
45
47
let rec walk acc hash count =
46
48
if count = 0 then Lwt_result.return (List.rev acc)
47
49
else
48
Removed:
let* commit = of_hash store hash in
50
Added:
let* commit = to_commit store hash in
49
51
match commit.parents with
50
52
| parent :: _ ->
51
53
walk (commit :: acc) (Store.Hash.of_hex parent) (count - 1)
@@ -57,7 +59,7 @@
57
59
let open Lwt_result.Syntax in
58
60
let* store = store repo in
59
61
let id = Store.Hash.of_hex id in
60
Removed:
of_hash store id
62
Added:
to_commit store id
61
63
end
62
64
63
65
module Branch = struct
lib/views.ml
@@ -1,3 +1,5 @@
1
Added:
open Config
2
Added:
1
3
type head_data = { page_title : string }
2
4
3
5
type body_data = {
@@ -49,7 +51,7 @@
49
51
let footer () =
50
52
let today = Unix.localtime (Unix.time ()) in
51
53
let year = string_of_int (today.Unix.tm_year + 1900) in
52
Removed:
let footer_text = Printf.sprintf "Copyright %s %s" year Config.author in
54
Added:
let footer_text = Printf.sprintf "Copyright %s %s" year config.user in
53
55
footer [] [ txt "%s" footer_text ]
54
56
55
57
let default_head_data = { page_title = "Ogit" }
@@ -88,9 +90,9 @@
88
90
let body_data =
89
91
{
90
92
title = "Ogit";
91
Removed:
subtitle = "Repositories for " ^ Config.author;
93
Added:
subtitle = "Repositories for " ^ config.user;
92
94
topnav = HTML.null [];
93
Removed:
content = [ repositories_in Config.git_directory ];
95
Added:
content = [ repositories_in config.repositories_root ];
94
96
}
95
97
in
96
98
Page.render body_data
@@ -101,7 +103,7 @@
101
103
let li_of_branch branch =
102
104
HTML.(li [] [ a [ href "%s" branch ] [ txt "%s" branch ] ])
103
105
in
104
Removed:
let li_of_commit (commit : Git_helpers.Commit.t) =
106
Added:
let li_of_commit (commit : Git_presenters.Commit.t) =
105
107
match commit.message with
106
108
| Some msg ->
107
109
HTML.(
@@ -109,7 +111,7 @@
109
111
[
110
112
a
111
113
[ href "commit/?id=%s" commit.hash ]
112
Removed:
[ txt "%s %s" (Git_helpers.short_hash commit.hash) msg ];
114
Added:
[ txt "%s %s" commit.short_hash msg ];
113
115
])
114
116
| None -> HTML.(li [] [ a [ href "" ] [ txt "caca!!" ] ])
115
117
in
@@ -130,7 +132,7 @@
130
132
Page.render
131
133
{
132
134
title = repo;
133
Removed:
subtitle = Git_helpers.repo_description repo;
135
Added:
subtitle = Git_presenters.repo_description repo;
134
136
topnav = Components.topnav repo;
135
137
content;
136
138
}
@@ -141,7 +143,7 @@
141
143
HTML.
142
144
{
143
145
title = repo;
144
Removed:
subtitle = Git_helpers.repo_description repo;
146
Added:
subtitle = Git_presenters.repo_description repo;
145
147
topnav = Components.topnav repo;
146
148
content = [ null [] ];
147
149
}
@@ -152,7 +154,7 @@
152
154
HTML.
153
155
{
154
156
title = repo;
155
Removed:
subtitle = Git_helpers.repo_description repo;
157
Added:
subtitle = Git_presenters.repo_description repo;
156
158
topnav = Components.topnav repo;
157
159
content = [ null [] ];
158
160
}
@@ -163,17 +165,16 @@
163
165
HTML.
164
166
{
165
167
title = repo;
166
Removed:
subtitle = Git_helpers.repo_description repo;
168
Added:
subtitle = Git_presenters.repo_description repo;
167
169
topnav = Components.topnav repo;
168
170
content = [ null [] ];
169
171
}
170
172
171
Removed:
let commit repo (commit : Git_helpers.Commit.t) =
173
Added:
let commit repo (commit : Git_presenters.Commit.t) =
172
174
let open Dream_html in
173
Removed:
let open Git_helpers in
174
175
let message = match commit.message with Some msg -> msg | None -> "" in
175
176
let content = HTML.[ h3 [] [ txt "%s" message ] ] in
176
Removed:
let title = Printf.sprintf "%s : %s" repo (short_hash commit.hash) in
177
Added:
let title = Printf.sprintf "%s : %s" repo commit.short_hash in
177
178
Page.render
178
179
{ title; subtitle = ""; topnav = Components.topnav repo; content }
179
180
end