-
Notifications
You must be signed in to change notification settings - Fork 159
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
irmin: add a Repo.close operation to the high-level API #845
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,118 @@ module Path = struct | |
module type S = S.PATH | ||
end | ||
|
||
exception Closed | ||
|
||
module CA_check_closed (CA : S.CONTENT_ADDRESSABLE_STORE_MAKER) : | ||
S.CONTENT_ADDRESSABLE_STORE_MAKER = | ||
functor | ||
(K : S.HASH) | ||
(V : Type.S) | ||
-> | ||
struct | ||
module S = CA (K) (V) | ||
|
||
type 'a t = { closed : bool ref; t : 'a S.t } | ||
|
||
type key = S.key | ||
|
||
type value = S.value | ||
|
||
let check_closed t = if !(t.closed) then raise Closed | ||
|
||
let mem t k = | ||
check_closed t; | ||
S.mem t.t k | ||
|
||
let find t k = | ||
check_closed t; | ||
S.find t.t k | ||
|
||
let add t v = | ||
check_closed t; | ||
S.add t.t v | ||
|
||
let unsafe_add t k v = | ||
check_closed t; | ||
S.unsafe_add t.t k v | ||
|
||
let batch t f = | ||
check_closed t; | ||
S.batch t.t (fun w -> f { t = w; closed = t.closed }) | ||
|
||
let v conf = S.v conf >|= fun t -> { closed = ref false; t } | ||
|
||
let close t = | ||
if !(t.closed) then Lwt.return_unit | ||
else ( | ||
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. As an aside, I think the OCamlformat parentheses here are quite ugly |
||
t.closed := true; | ||
S.close t.t ) | ||
end | ||
|
||
module AW_check_closed (AW : S.ATOMIC_WRITE_STORE_MAKER) : | ||
S.ATOMIC_WRITE_STORE_MAKER = | ||
functor | ||
(K : Type.S) | ||
(V : Type.S) | ||
-> | ||
struct | ||
module S = AW (K) (V) | ||
|
||
type t = { closed : bool ref; t : S.t } | ||
|
||
type key = S.key | ||
|
||
type value = S.value | ||
|
||
let check_closed t = if !(t.closed) then raise Closed | ||
|
||
let mem t k = | ||
check_closed t; | ||
S.mem t.t k | ||
|
||
let find t k = | ||
check_closed t; | ||
S.find t.t k | ||
|
||
let set t k v = | ||
check_closed t; | ||
S.set t.t k v | ||
|
||
let test_and_set t k ~test ~set = | ||
check_closed t; | ||
S.test_and_set t.t k ~test ~set | ||
|
||
let remove t k = | ||
check_closed t; | ||
S.remove t.t k | ||
|
||
let list t = | ||
check_closed t; | ||
S.list t.t | ||
|
||
type watch = S.watch | ||
|
||
let watch t ?init f = | ||
check_closed t; | ||
S.watch t.t ?init f | ||
|
||
let watch_key t k ?init f = | ||
check_closed t; | ||
S.watch_key t.t k ?init f | ||
|
||
let unwatch t w = | ||
check_closed t; | ||
S.unwatch t.t w | ||
|
||
let v conf = S.v conf >|= fun t -> { closed = ref false; t } | ||
|
||
let close t = | ||
if !(t.closed) then Lwt.return_unit | ||
else ( | ||
t.closed := true; | ||
S.close t.t ) | ||
end | ||
|
||
module Make_ext | ||
(CA : S.CONTENT_ADDRESSABLE_STORE_MAKER) | ||
(AW : S.ATOMIC_WRITE_STORE_MAKER) | ||
|
@@ -68,6 +180,9 @@ module Make_ext | |
and type step = P.step) | ||
(CT : S.COMMIT with type hash = H.t) = | ||
struct | ||
module CA = CA_check_closed (CA) | ||
module AW = AW_check_closed (AW) | ||
|
||
module X = struct | ||
module Hash = H | ||
|
||
|
@@ -144,6 +259,11 @@ struct | |
let commits = (nodes, commits) in | ||
Branch.v config >|= fun branch -> | ||
{ contents; nodes; commits; branch; config } | ||
|
||
let close t = | ||
Contents.CA.close t.contents >>= fun () -> | ||
Node.CA.close (snd t.nodes) >>= fun () -> | ||
Commit.CA.close (snd t.commits) >>= fun () -> Branch.close t.branch | ||
end | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
no need for this exception any more
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.
this can be raised by the
Make_ext
functor now! (not by the backends)