[OCaml] Mobile-friendly clone of cgit.
Start work on Trees.
Making slow but steady progress... Bulldozer mindset.
Changed files
lib/config.ml
@@ -69,5 +69,4 @@
69
69
prerr_endline "[config.ml] Falling back to default config.";
70
70
Ok default
71
71
72
Removed:
let config =
73
Removed:
match read_file ~file:config_file () with Ok cfg -> cfg | Error _ -> default
72
Added:
let config = match read_file () with Ok cfg -> cfg | Error _ -> default
lib/dune
@@ -3,5 +3,5 @@
3
3
(library
4
4
(name ogit)
5
5
(libraries dream dream-html git-unix toml)
6
Removed:
(preprocess (pps dream-html.ppx)))
7
Removed:
6
Added:
(preprocess
7
Added:
(pps dream-html.ppx)))
lib/git_presenters.ml
@@ -27,11 +27,11 @@
27
27
message : string option;
28
28
}
29
29
30
Removed:
let to_commit store h =
31
Removed:
let* v = Store.read store h in
30
Added:
let to_commit store hash =
31
Added:
let* v = Store.read store hash in
32
32
match v with
33
33
| Git.Value.Commit c ->
34
Removed:
let hash = Store.Hash.to_hex h in
34
Added:
let hash = Store.Hash.to_hex hash in
35
35
Lwt_result.return
36
36
{
37
37
hash;
@@ -40,8 +40,13 @@
40
40
author = Store.Value.Commit.author c;
41
41
message = Store.Value.Commit.message c;
42
42
}
43
Removed:
| _ -> Lwt_result.fail @@ `Msg "value is not a commit"
43
Added:
| _ -> Lwt_result.fail (`Msg "value is not a commit")
44
44
45
Added:
let commit_of_id repo id =
46
Added:
let* store = store repo in
47
Added:
let hash = Store.Hash.of_hex id in
48
Added:
to_commit store hash
49
Added:
45
50
let recent_commits repo n =
46
51
let* store = store repo in
47
52
let* head = Store.Ref.resolve store Git.Reference.head in
@@ -56,18 +61,66 @@
56
61
in
57
62
walk [] head n
58
63
59
Removed:
let of_id repo id =
60
Removed:
let* store = store repo in
61
Removed:
let id = Store.Hash.of_hex id in
62
Removed:
to_commit store id
64
Added:
type branch = { hash : string; name : string }
63
65
64
Removed:
type branch = { name : string }
65
Removed:
66
66
let all_branches repo =
67
67
let* store = store repo in
68
68
let open Lwt.Syntax in
69
69
let* refs = Store.Ref.list store in
70
70
let branches =
71
Removed:
List.map (fun (ref, _) -> { name = Git.Reference.to_string ref }) refs
71
Added:
List.map
72
Added:
(fun (ref, hash) ->
73
Added:
{ name = Git.Reference.to_string ref; hash = Store.Hash.to_hex hash })
74
Added:
refs
72
75
in
73
76
Lwt_result.return branches
77
Added:
78
Added:
type tree_entry = {
79
Added:
hash : string;
80
Added:
short_hash : string;
81
Added:
name : string;
82
Added:
perm : int;
83
Added:
}
84
Added:
85
Added:
type tree = { hash : string; short_hash : string; entries : tree_entry list }
86
Added:
87
Added:
let to_entry _ =
88
Added:
{
89
Added:
hash = "foo";
90
Added:
short_hash = String.sub "foobar" 0 8;
91
Added:
name = "foobarbino";
92
Added:
perm = 122;
93
Added:
}
94
Added:
95
Added:
let present_tree tree = Store.Value.Tree.to_list tree |> List.map to_entry
96
Added:
97
Added:
let to_tree store hash =
98
Added:
let* v = Store.read store hash in
99
Added:
match v with
100
Added:
| Git.Value.Tree tree ->
101
Added:
let hash = Store.Hash.to_hex hash in
102
Added:
Lwt_result.return
103
Added:
{ hash; short_hash = String.sub hash 0 8; entries = present_tree tree }
104
Added:
| _ ->
105
Added:
Dream.log "Value is not a tree";
106
Added:
Lwt_result.fail (`Msg "value is not a tree")
107
Added:
108
Added:
let head_tree_id store =
109
Added:
let* commit_hash = Store.Ref.resolve store Git.Reference.head in
110
Added:
let* v = Store.read store commit_hash in
111
Added:
match v with
112
Added:
| Git.Value.Commit commit ->
113
Added:
Store.Value.Commit.tree commit |> Lwt_result.return
114
Added:
| _ ->
115
Added:
Dream.log "no head tree id";
116
Added:
Lwt_result.fail (`Msg "")
117
Added:
118
Added:
let head_tree repo =
119
Added:
let* store = store repo in
120
Added:
let* hash = head_tree_id store in
121
Added:
to_tree store hash
122
Added:
123
Added:
let tree_of_id repo id =
124
Added:
let* store = store repo in
125
Added:
let* hash = Lwt_result.return (Store.Hash.of_hex id) in
126
Added:
to_tree store hash
lib/handlers.ml
@@ -10,10 +10,11 @@
10
10
m >>= function
11
11
| Ok x -> f x
12
12
| Error e ->
13
Removed:
let msg = Format.asprintf "%a" Git_unix.Store.pp_error e in
13
Added:
let msg = Format.asprintf "%a" Store.pp_error e in
14
14
Views.error_page msg |> Dream_html.respond
15
15
16
Removed:
let repo req = Dream.param req "repo_name"
16
Added:
let repo req = Dream.param req "repo"
17
Added:
let id_of_req req = Dream.param req "id"
17
18
18
19
let summary req =
19
20
let* branches = all_branches (repo req) in
@@ -29,25 +30,36 @@
29
30
let* commits = recent_commits (repo req) 100 in
30
31
Views.Repo.log (repo req) commits |> Dream_html.respond
31
32
32
Removed:
let tree req = Views.Repo.tree (repo req) |> Dream_html.respond
33
Added:
let tree_head req =
34
Added:
Dream.log "Tree head";
35
Added:
let* tree = head_tree (repo req) in
36
Added:
Views.Repo.tree (repo req) tree |> Dream_html.respond
33
37
38
Added:
let tree_id req =
39
Added:
Dream.log "Tree id";
40
Added:
let id = id_of_req req in
41
Added:
let* tree = tree_of_id (repo req) id in
42
Added:
Views.Repo.tree (repo req) tree |> Dream_html.respond
43
Added:
34
44
let commit req =
35
Removed:
let id = match Dream.query req "id" with Some id -> id | None -> "" in
36
Removed:
let* commit = of_id (repo req) id in
45
Added:
let id = id_of_req req in
46
Added:
let* commit = commit_of_id (repo req) id in
37
47
Views.Repo.commit (repo req) commit |> Dream_html.respond
38
48
end
39
49
40
50
let all_handlers =
41
Removed:
[
42
Removed:
Dream.get "/" root;
43
Removed:
Dream.scope "/:repo_name" []
44
Removed:
Repo.
45
Removed:
[
46
Removed:
Dream.get "/" summary;
47
Removed:
Dream.get "/refs/" refs;
48
Removed:
Dream.get "/log/" log;
49
Removed:
Dream.get "/tree/" tree;
50
Removed:
Dream.get "/commit/" commit;
51
Removed:
];
52
Removed:
Dream.get "/static/**" (Dream.static "./lib/static");
53
Removed:
]
51
Added:
Dream.
52
Added:
[
53
Added:
get "/" root;
54
Added:
scope "/:repo" []
55
Added:
Repo.
56
Added:
[
57
Added:
get "/" summary;
58
Added:
get "/refs/" refs;
59
Added:
get "/log/" log;
60
Added:
get "/tree/" tree_head;
61
Added:
get "/tree/:id" tree_id;
62
Added:
get "/commit/:id" commit;
63
Added:
];
64
Added:
get "/static/**" (static "./lib/static");
65
Added:
]
lib/views.ml
@@ -98,7 +98,7 @@
98
98
module Repo = struct
99
99
let page_title repo = Printf.sprintf "%s — %s" repo (repo_description repo)
100
100
101
Removed:
let li_of_branch repo branch =
101
Added:
let li_of_branch repo (branch : branch) =
102
102
HTML.(li [] [ Routes.link_to branch.name (Tag (repo, branch.name)) ])
103
103
104
104
let li_of_commit repo commit =
@@ -163,11 +163,19 @@
163
163
content;
164
164
}
165
165
166
Removed:
let tree repo =
167
Removed:
let content = HTML.[ null [] ] in
166
Added:
let tree repo tree =
167
Added:
let title = Printf.sprintf "%s : %s" repo tree.short_hash in
168
Added:
let li_of_entry entry = HTML.(li [] [ txt "%s" entry.name ]) in
169
Added:
let content =
170
Added:
HTML.
171
Added:
[
172
Added:
h3 [] [ txt "Tree %s" tree.short_hash ];
173
Added:
ul [] (List.map li_of_entry tree.entries);
174
Added:
]
175
Added:
in
168
176
Page.render ~page_title:(page_title repo)
169
177
{
170
Removed:
title = repo;
178
Added:
title;
171
179
subtitle = repo_description repo;
172
180
topnav = Components.topnav repo;
173
181
content;