-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Tree.is_val
and Tree.Contents.is_val
functions
#1864
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1417,6 +1417,37 @@ module Make (S : Generic_key) = struct | |||||||||||||||
in | ||||||||||||||||
run x test | ||||||||||||||||
|
||||||||||||||||
let test_lazy_tree x () = | ||||||||||||||||
let is_val_aux v t k = | ||||||||||||||||
let str = Fmt.str "empty is_val %a" Irmin.Type.(pp S.path_t) k in | ||||||||||||||||
let b = S.Tree.is_val t k in | ||||||||||||||||
Alcotest.(check bool) str v b | ||||||||||||||||
in | ||||||||||||||||
let is_val = is_val_aux true in | ||||||||||||||||
let is_not_val = is_val_aux false in | ||||||||||||||||
let test repo = | ||||||||||||||||
let v0 = S.Tree.empty () in | ||||||||||||||||
is_val v0 []; | ||||||||||||||||
is_val v0 [ "foo" ]; | ||||||||||||||||
is_val v0 [ "foo"; "bar" ]; | ||||||||||||||||
|
||||||||||||||||
let* r1 = r1 ~repo in | ||||||||||||||||
let v1 = S.Commit.tree r1 in | ||||||||||||||||
is_not_val v1 []; | ||||||||||||||||
is_not_val v1 [ "a" ]; | ||||||||||||||||
|
||||||||||||||||
let* _ = S.Tree.find_tree v1 [ "a" ] in | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
the returned value here is None, there is no node at "a" in |
||||||||||||||||
is_val v1 []; | ||||||||||||||||
is_val v1 [ "a" ]; | ||||||||||||||||
|
||||||||||||||||
S.Tree.clear v1; | ||||||||||||||||
is_not_val v1 []; | ||||||||||||||||
is_not_val v1 [ "a" ]; | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
|
||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I propose to also add a test for an update in lazy tree, for instance:
|
||||||||||||||||
Lwt.return () | ||||||||||||||||
in | ||||||||||||||||
run x test | ||||||||||||||||
|
||||||||||||||||
let pp_proof = Irmin.Type.pp (S.Tree.Proof.t S.Tree.Proof.tree_t) | ||||||||||||||||
let pp_stream = Irmin.Type.pp (S.Tree.Proof.t S.Tree.Proof.stream_t) | ||||||||||||||||
|
||||||||||||||||
|
@@ -2441,6 +2472,7 @@ let suite (speed, x) = | |||||||||||||||
suite' | ||||||||||||||||
([ | ||||||||||||||||
("High-level operations on trees", speed, T.test_trees x); | ||||||||||||||||
("Test lazy trees", speed, T.test_lazy_tree x); | ||||||||||||||||
("Basic operations on contents", speed, T.test_contents x); | ||||||||||||||||
("Basic operations on nodes", speed, T.test_nodes x); | ||||||||||||||||
("Basic operations on commits", speed, T.test_commits x); | ||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -82,6 +82,12 @@ module type S = sig | |||||
(** [is_empty t] is true iff [t] is {!empty} (i.e. a tree node with no | ||||||
children). Trees with {!kind} = [`Contents] are never considered empty. *) | ||||||
|
||||||
val is_val : t -> path -> bool | ||||||
(** [is_val t k] is [true] iff the path [k] has already been forced in [t]. In | ||||||
that case, that means that all the nodes traversed by [k] are loaded in | ||||||
memory. If the leaf node is a contents [c], then [Contents.is_val c] | ||||||
should also be [true]. *) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe the doc should also mention that it returns true also when there is no node at the path given |
||||||
|
||||||
(** {1 Diffs} *) | ||||||
|
||||||
val diff : t -> t -> (path * (contents * metadata) Diff.t) list Lwt.t | ||||||
|
@@ -128,6 +134,10 @@ module type S = sig | |||||
(** Equivalent to {!val-force}, but raises an exception if the lazy content | ||||||
value is not present in the underlying repository. *) | ||||||
|
||||||
val is_val : t -> bool | ||||||
(** [is_val x] is [true] iff [x] has already been forced (and so is loaded | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
in memory). *) | ||||||
|
||||||
val clear : t -> unit | ||||||
(** [clear t] clears [t]'s cache. *) | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.