[OCaml] Mobile-friendly clone of cgit.
Unify tags and branches under references, add repo module.
lib/resolvers.ml
@@ -27,13 +27,13 @@
27
27
}
28
28
29
29
let to_t c =
30
Removed:
let open Store.Value in
31
Removed:
{
32
Removed:
hash = Commit.digest c |> Store.Hash.to_hex;
33
Removed:
parents = Commit.parents c |> List.map Store.Hash.to_hex;
34
Removed:
author = Commit.author c;
35
Removed:
message = Commit.message c;
36
Removed:
}
30
Added:
Store.
31
Added:
{
32
Added:
hash = Value.Commit.digest c |> Hash.to_hex;
33
Added:
parents = Value.Commit.parents c |> List.map Hash.to_hex;
34
Added:
author = Value.Commit.author c;
35
Added:
message = Value.Commit.message c;
36
Added:
}
37
37
38
38
let of_id repo id =
39
39
let* store = store repo in
@@ -61,7 +61,7 @@
61
61
walk [] head_commit.hash n
62
62
end
63
63
64
Removed:
module Branch = struct
64
Added:
module Reference = struct
65
65
type t = { name : string; hash : string }
66
66
67
67
let to_t (reference, hash) =
@@ -70,19 +70,31 @@
70
70
let all repo =
71
71
let* store = store repo in
72
72
let open Lwt.Syntax in
73
Removed:
let* refs = Store.Ref.list store in
74
Removed:
let branches = List.map to_t refs in
75
Removed:
Lwt_result.return branches
73
Added:
let* references = Store.Ref.list store in
74
Added:
let references = List.map to_t references in
75
Added:
Lwt_result.return references
76
76
77
Added:
let branches repo =
78
Added:
let* references = all repo in
79
Added:
let is_branch reference =
80
Added:
not (String.starts_with ~prefix:"v" reference.name)
81
Added:
in
82
Added:
Lwt_result.return @@ List.filter is_branch references
83
Added:
84
Added:
let tags repo =
85
Added:
let* references = all repo in
86
Added:
let is_branch reference = String.starts_with ~prefix:"v" reference.name in
87
Added:
Lwt_result.return @@ List.filter is_branch references
88
Added:
77
89
let of_id repo id =
78
Removed:
let* branches = all repo in
90
Added:
let* branches = branches repo in
79
91
let branch =
80
92
branches
81
93
|> List.find_opt (fun branch -> Filename.basename branch.name = id)
82
94
in
83
95
match branch with
84
96
| Some branch -> Lwt_result.return branch
85
Removed:
| None -> Lwt_result.fail @@ `Msg ("no branch matches id " ^ id)
97
Added:
| None -> Lwt_result.fail @@ `Msg ("no reference matches id " ^ id)
86
98
end
87
99
88
100
module Entry = struct
@@ -101,6 +113,9 @@
101
113
| `Normal -> 0o100644
102
114
in
103
115
{ hash; name; perm }
116
Added:
117
Added:
let is_readme { name; _ } =
118
Added:
String.lowercase_ascii name |> String.starts_with ~prefix:"readme"
104
119
end
105
120
106
121
module Tree = struct
@@ -145,8 +160,24 @@
145
160
let blob_or_tree repo id =
146
161
let* store = store repo in
147
162
let hash = Store.Hash.of_hex id in
148
Removed:
let* obj = Store.read store hash in
149
Removed:
match obj with
163
Added:
Lwt_result.bind (Store.read store hash) @@ function
150
164
| Git.Value.Tree tree -> Lwt_result.return @@ `Tree (Tree.to_t tree)
151
165
| Git.Value.Blob blob -> Lwt_result.return @@ `Blob (Blob.to_t blob)
152
166
| _ -> Lwt_result.fail @@ `Msg ("No tree or blob matches id " ^ id)
167
Added:
168
Added:
module Repo = struct
169
Added:
let has_readme repo =
170
Added:
let* tree = Tree.head repo in
171
Added:
Lwt_result.return @@ List.exists Entry.is_readme tree.entries
172
Added:
173
Added:
let readme repo =
174
Added:
let* tree = Tree.head repo in
175
Added:
match List.find_opt Entry.is_readme tree.entries with
176
Added:
| None -> Lwt_result.return None
177
Added:
| Some readme -> (
178
Added:
let* store = store repo in
179
Added:
let hash = Store.Hash.of_hex readme.hash in
180
Added:
Lwt_result.bind (Store.read store hash) @@ function
181
Added:
| Git.Value.Blob blob -> Lwt_result.return @@ Some (Blob.to_t blob)
182
Added:
| _ -> Lwt_result.fail @@ `Msg ("couldn't read file " ^ readme.name))
183
Added:
end