[OCaml] Mobile-friendly clone of cgit.
Update config.
Changed files
lib/config.ml
@@ -1,26 +1,76 @@
1
Removed:
let config_file = "default_config.toml"
1
Added:
(* -*- mode: tuareg; -*- *)
2
2
3
Added:
open Toml
4
Added:
3
5
type t = {
4
Removed:
repositories_root : string;
5
6
user : string;
6
7
default_branch : string;
7
Removed:
max_commits_displayed : int;
8
Added:
repositories_root_path : string;
9
Added:
commits_max_displayed : int;
8
10
}
9
11
12
Added:
let default =
13
Added:
{
14
Added:
user = Unix.getlogin ();
15
Added:
default_branch = "master";
16
Added:
repositories_root_path = Filename.concat (Sys.getenv "HOME") "git.test";
17
Added:
commits_max_displayed = 10;
18
Added:
}
19
Added:
20
Added:
let config_file = Filename.(concat current_dir_name "config.toml")
21
Added:
22
Added:
let to_table t =
23
Added:
let open Types in
24
Added:
List.map
25
Added:
(fun (k, v) -> (Min.key k, v))
26
Added:
[
27
Added:
("user", TString t.user);
28
Added:
("default_branch", TString t.default_branch);
29
Added:
("repositories.root_path", TString t.repositories_root_path);
30
Added:
("commits.max_displayed", TInt t.commits_max_displayed);
31
Added:
]
32
Added:
|> Min.of_key_values
33
Added:
34
Added:
let write_file ?(file = config_file) table =
35
Added:
let oc = open_out file in
36
Added:
Printer.string_of_table table |> Printf.fprintf oc "%s\n";
37
Added:
close_out oc
38
Added:
39
Added:
let read_file ?(file = config_file) () =
40
Added:
try
41
Added:
match Toml.Parser.from_filename file with
42
Added:
| `Error (e, l) ->
43
Added:
Error (Printf.sprintf "%s: %s at line %d" l.source e l.line)
44
Added:
| `Ok table ->
45
Added:
let ( let* ) = Result.bind in
46
Added:
let find_string key =
47
Added:
match Toml.Types.Table.find_opt (Toml.Min.key key) table with
48
Added:
| Some (TString s) -> Ok s
49
Added:
| Some _ -> Error ("Expected string for key: " ^ key)
50
Added:
| None -> Error ("Missing key: " ^ key)
51
Added:
in
52
Added:
let find_int key =
53
Added:
match Toml.Types.Table.find_opt (Toml.Min.key key) table with
54
Added:
| Some (TInt i) -> Ok i
55
Added:
| Some _ -> Error ("Expected int for key: " ^ key)
56
Added:
| None -> Error ("Missing key: " ^ key)
57
Added:
in
58
Added:
let* repositories_root_path = find_string "repositories_root" in
59
Added:
let* user = find_string "user" in
60
Added:
let* default_branch = find_string "default_branch" in
61
Added:
let* commits_max_displayed = find_int "max_commits_displayed" in
62
Added:
Ok
63
Added:
{
64
Added:
repositories_root_path;
65
Added:
user;
66
Added:
default_branch;
67
Added:
commits_max_displayed;
68
Added:
}
69
Added:
with _ ->
70
Added:
prerr_endline "[config.ml] Falling back to default config.";
71
Added:
Ok default
72
Added:
10
73
let config =
11
Removed:
match Toml.Parser.from_filename config_file with
12
Removed:
| `Error (e, _) -> failwith ("Config parse error: " ^ e)
13
Removed:
| `Ok table ->
14
Removed:
let find key = Toml.Types.Table.find (Toml.Min.key key) table in
15
Removed:
let find_string key =
16
Removed:
match find key with TString s -> s | _ -> raise Not_found
17
Removed:
in
18
Removed:
let find_int key =
19
Removed:
match find key with TInt i -> i | _ -> raise Not_found
20
Removed:
in
21
Removed:
{
22
Removed:
repositories_root = find_string "repositories_root";
23
Removed:
user = find_string "user";
24
Removed:
default_branch = find_string "default_branch";
25
Removed:
max_commits_displayed = find_int "max_commits_displayed";
26
Removed:
}
74
Added:
match read_file ~file:config_file () with
75
Added:
| Ok cfg -> cfg
76
Added:
| Error err -> failwith err
lib/config_writer.ml
@@ -0,0 +1,3 @@
1
Added:
(* -*- mode: tuareg; -*- *)
2
Added:
3
Added:
let () = Config.(default |> to_table |> write_file)
lib/default_config.toml
@@ -1,4 +0,0 @@
1
Removed:
repositories_root = "~/git.test/"
2
Removed:
user = "Marius Peter"
3
Removed:
default_branch = "master"
4
Removed:
max_commits_displayed = 100
lib/dune
@@ -1,3 +1,5 @@
1
Added:
;; -*- mode: lisp; -*-
2
Added:
1
3
(library
2
4
(name ogit)
3
5
(libraries dream dream-html git-unix toml))
lib/git_presenters.ml
@@ -1,7 +1,9 @@
1
Added:
(* -*- mode: tuareg; -*- *)
2
Added:
1
3
module Store = Git_unix.Store
2
4
open Config
3
5
4
Removed:
let full_path path = Filename.concat config.repositories_root path
6
Added:
let full_path path = Filename.concat config.repositories_root_path path
5
7
6
8
let store repo =
7
9
let path = Fpath.v @@ full_path repo in
lib/handlers.ml
@@ -1,3 +1,5 @@
1
Added:
(* -*- mode: tuareg; -*- *)
2
Added:
1
3
let ( let* ) m f =
2
4
let open Lwt.Infix in
3
5
m >>= function
lib/views.ml
@@ -1,3 +1,5 @@
1
Added:
(* -*- mode: tuareg; -*- *)
2
Added:
1
3
open Config
2
4
3
5
type head_data = { page_title : string }
@@ -92,7 +94,7 @@
92
94
title = "Ogit";
93
95
subtitle = "Repositories for " ^ config.user;
94
96
topnav = HTML.null [];
95
Removed:
content = [ repositories_in config.repositories_root ];
97
Added:
content = [ repositories_in config.repositories_root_path ];
96
98
}
97
99
in
98
100
Page.render body_data