less exceptions
This commit is contained in:
parent
65c8202565
commit
d124201bf3
1 changed files with 17 additions and 14 deletions
|
@ -64,12 +64,14 @@ let disconnect _t = Lwt.return_unit
|
||||||
|
|
||||||
let to_octets t =
|
let to_octets t =
|
||||||
let open Lwt.Infix in
|
let open Lwt.Infix in
|
||||||
let head = Option.get t.head in
|
match t.head with
|
||||||
Store.read_exn t.store head >|= function
|
| None -> Lwt.return ""
|
||||||
| Commit c ->
|
| Some head ->
|
||||||
let l = Encore.to_lavoisier Git_commit.format in
|
Store.read_exn t.store head >|= function
|
||||||
Encore.Lavoisier.emit_string c l
|
| Commit c ->
|
||||||
| _ -> assert false
|
let l = Encore.to_lavoisier Git_commit.format in
|
||||||
|
Encore.Lavoisier.emit_string c l
|
||||||
|
| _ -> assert false
|
||||||
|
|
||||||
let of_octets data =
|
let of_octets data =
|
||||||
let open Lwt_result.Infix in
|
let open Lwt_result.Infix in
|
||||||
|
@ -90,13 +92,15 @@ let exists _t _key =
|
||||||
|
|
||||||
let get t key =
|
let get t key =
|
||||||
let open Lwt.Infix in
|
let open Lwt.Infix in
|
||||||
let head = Option.get t.head in
|
match t.head with
|
||||||
Search.find t.store head (`Path (Mirage_kv.Key.segments key)) >>= function
|
|
||||||
| None -> Lwt.return (Error (`Not_found key))
|
| None -> Lwt.return (Error (`Not_found key))
|
||||||
| Some blob ->
|
| Some head ->
|
||||||
Store.read_exn t.store blob >|= function
|
Search.find t.store head (`Path (Mirage_kv.Key.segments key)) >>= function
|
||||||
| Blob b -> Ok (Git.Blob.to_string b)
|
| None -> Lwt.return (Error (`Not_found key))
|
||||||
| _ -> assert false
|
| Some blob ->
|
||||||
|
Store.read_exn t.store blob >|= function
|
||||||
|
| Blob b -> Ok (Git.Blob.to_string b)
|
||||||
|
| _ -> assert false
|
||||||
|
|
||||||
let get_partial t key ~offset ~length =
|
let get_partial t key ~offset ~length =
|
||||||
let open Lwt_result.Infix in
|
let open Lwt_result.Infix in
|
||||||
|
@ -116,8 +120,7 @@ let last_modified _t _key =
|
||||||
assert false
|
assert false
|
||||||
|
|
||||||
let digest t _key =
|
let digest t _key =
|
||||||
let head = Option.get t.head in
|
Lwt.return (Ok (Option.fold ~none:"0" ~some:Store.Hash.to_hex t.head))
|
||||||
Digestif.SHA1.to_hex head
|
|
||||||
|
|
||||||
let size t key =
|
let size t key =
|
||||||
let open Lwt_result.Infix in
|
let open Lwt_result.Infix in
|
||||||
|
|
Loading…
Reference in a new issue