Read staged files
This commit is contained in:
parent
65f850cf44
commit
4f93219f1d
3 changed files with 24 additions and 20 deletions
|
@ -395,25 +395,26 @@ module Make (Pclock : Mirage_clock.PCLOCK) = struct
|
||||||
| `Reference_not_found _ | `Msg _ as err -> Store.pp_error ppf err
|
| `Reference_not_found _ | `Msg _ as err -> Store.pp_error ppf err
|
||||||
| `Hash_not_found hash -> Store.pp_error ppf (`Not_found hash)
|
| `Hash_not_found hash -> Store.pp_error ppf (`Not_found hash)
|
||||||
|
|
||||||
|
let noppp t key =
|
||||||
|
match t.committed, t.head with
|
||||||
|
| None, None -> Lwt.return None
|
||||||
|
| Some (tree_root_hash, _), _ ->
|
||||||
|
Search.find t.store tree_root_hash (`Path (Mirage_kv.Key.segments key))
|
||||||
|
| None, Some commit ->
|
||||||
|
Search.find t.store commit (`Commit (`Path (Mirage_kv.Key.segments key)))
|
||||||
|
|
||||||
let exists t key =
|
let exists t key =
|
||||||
let open Lwt.Infix in
|
let open Lwt.Infix in
|
||||||
match t.head with
|
noppp t key >>= function
|
||||||
| None -> Lwt.return (Ok None)
|
| None -> Lwt.return (Ok None)
|
||||||
| Some head ->
|
| Some tree_hash ->
|
||||||
Search.mem t.store head (`Commit (`Path (Mirage_kv.Key.segments key))) >>= function
|
Store.read_exn t.store tree_hash >>= function
|
||||||
| false -> Lwt.return (Ok None)
|
|
||||||
| true ->
|
|
||||||
Search.find t.store head (`Commit (`Path (Mirage_kv.Key.segments key)))
|
|
||||||
>|= Option.get >>= Store.read_exn t.store >>= function
|
|
||||||
| Blob _ -> Lwt.return (Ok (Some `Value))
|
| Blob _ -> Lwt.return (Ok (Some `Value))
|
||||||
| Tree _ | Commit _ | Tag _ -> Lwt.return (Ok (Some `Dictionary))
|
| Tree _ | Commit _ | Tag _ -> Lwt.return (Ok (Some `Dictionary))
|
||||||
|
|
||||||
let get t key =
|
let get t key =
|
||||||
let open Lwt.Infix in
|
let open Lwt.Infix in
|
||||||
match t.head with
|
noppp t key >>= function
|
||||||
| None -> Lwt.return (Error (`Not_found key))
|
|
||||||
| Some head ->
|
|
||||||
Search.find t.store head (`Commit (`Path (Mirage_kv.Key.segments key))) >>= function
|
|
||||||
| None -> Lwt.return (Error (`Not_found key))
|
| None -> Lwt.return (Error (`Not_found key))
|
||||||
| Some blob ->
|
| Some blob ->
|
||||||
Store.read_exn t.store blob >|= function
|
Store.read_exn t.store blob >|= function
|
||||||
|
@ -434,10 +435,7 @@ module Make (Pclock : Mirage_clock.PCLOCK) = struct
|
||||||
|
|
||||||
let list t key =
|
let list t key =
|
||||||
let open Lwt.Infix in
|
let open Lwt.Infix in
|
||||||
match t.head with
|
noppp t key >>= function
|
||||||
| None -> Lwt.return (Error (`Not_found key))
|
|
||||||
| Some head ->
|
|
||||||
Search.find t.store head (`Commit (`Path (Mirage_kv.Key.segments key))) >>= function
|
|
||||||
| None -> Lwt.return (Error (`Not_found key))
|
| None -> Lwt.return (Error (`Not_found key))
|
||||||
| Some tree ->
|
| Some tree ->
|
||||||
Store.read_exn t.store tree >>= function
|
Store.read_exn t.store tree >>= function
|
||||||
|
@ -455,6 +453,8 @@ module Make (Pclock : Mirage_clock.PCLOCK) = struct
|
||||||
|
|
||||||
let last_modified t key =
|
let last_modified t key =
|
||||||
let open Lwt.Infix in
|
let open Lwt.Infix in
|
||||||
|
noppp t key >>=
|
||||||
|
(* FIXME *)
|
||||||
Option.fold
|
Option.fold
|
||||||
~none:(Lwt.return (Error (`Not_found key)))
|
~none:(Lwt.return (Error (`Not_found key)))
|
||||||
~some:(fun head ->
|
~some:(fun head ->
|
||||||
|
@ -478,13 +478,14 @@ module Make (Pclock : Mirage_clock.PCLOCK) = struct
|
||||||
in
|
in
|
||||||
Ok ts
|
Ok ts
|
||||||
| _ -> assert false)
|
| _ -> assert false)
|
||||||
t.head
|
|
||||||
|
|
||||||
let digest t key =
|
let digest t key =
|
||||||
|
let open Lwt.Infix in
|
||||||
|
noppp t key >>=
|
||||||
|
(* FIXME *)
|
||||||
Option.fold
|
Option.fold
|
||||||
~none:(Error (`Not_found key))
|
~none:(Lwt.return (Error (`Not_found key)))
|
||||||
~some:(fun x -> Ok (Store.Hash.to_raw_string x))
|
~some:(fun x -> Lwt.return (Ok (Store.Hash.to_raw_string x)))
|
||||||
t.head |> Lwt.return
|
|
||||||
|
|
||||||
let size t key =
|
let size t key =
|
||||||
let open Lwt_result.Infix in
|
let open Lwt_result.Infix in
|
||||||
|
@ -593,6 +594,7 @@ module Make (Pclock : Mirage_clock.PCLOCK) = struct
|
||||||
|
|
||||||
let remove ?and_commit t key =
|
let remove ?and_commit t key =
|
||||||
let segs = Mirage_kv.Key.segments key in
|
let segs = Mirage_kv.Key.segments key in
|
||||||
|
(* FIXME: t.head *)
|
||||||
match List.rev segs, t.head with
|
match List.rev segs, t.head with
|
||||||
| [], _ -> assert false
|
| [], _ -> assert false
|
||||||
| _, None -> Lwt.return_ok () (* XXX(dinosaure): or [`Not_found]? *)
|
| _, None -> Lwt.return_ok () (* XXX(dinosaure): or [`Not_found]? *)
|
||||||
|
|
|
@ -11,7 +11,7 @@ Batch operation
|
||||||
> exists /bar
|
> exists /bar
|
||||||
> quit
|
> quit
|
||||||
> quit
|
> quit
|
||||||
/bar does not exists
|
/bar exists as a value
|
||||||
$ mgit git://localhost/simple#main <<EOF
|
$ mgit git://localhost/simple#main <<EOF
|
||||||
> list /
|
> list /
|
||||||
> get /bar
|
> get /bar
|
||||||
|
|
|
@ -5,9 +5,11 @@ Reading during batch operation
|
||||||
$ mgit git://localhost/simple#main << EOF
|
$ mgit git://localhost/simple#main << EOF
|
||||||
> fold
|
> fold
|
||||||
> set /bar "Git rocks!"
|
> set /bar "Git rocks!"
|
||||||
|
> list /
|
||||||
> get /bar
|
> get /bar
|
||||||
> quit
|
> quit
|
||||||
> quit
|
> quit
|
||||||
|
- /bar
|
||||||
00000000: 4769 7420 726f 636b 7321 Git rocks!
|
00000000: 4769 7420 726f 636b 7321 Git rocks!
|
||||||
$ cd simple
|
$ cd simple
|
||||||
$ git log main --pretty=oneline | wc -l
|
$ git log main --pretty=oneline | wc -l
|
||||||
|
|
Loading…
Reference in a new issue