-
Notifications
You must be signed in to change notification settings - Fork 377
[API] Abstract over repository roots to simplify the addition of new repository formats #6680
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
base: master
Are you sure you want to change the base?
Conversation
| let target = OpamRepositoryRoot.Dir.backup ~tmp_dir dir in | ||
| OpamRepositoryRoot.Dir.copy ~src:dir ~dst:target; | ||
| fun () -> OpamRepositoryRoot.Dir.copy ~src:target ~dst:dir) |
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.
Why use Dir here instead of the abstraction OpamRepositoryRoot.t ?
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 code is guarded under the else branch of if OpamFilename.exists tar so in this case we know that we're working with directories
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.
Yes, i saw. What i wanted to highlight is that (almost) the same code is used for tar & dir repositories : copy in tmp dir the do the copy and return the function that does the copy back. I was wondering if it is possible to factorise it using the abstraction.
if OpamFilename.exists tar then
(let target = OpamFilename.create tmp_dir (OpamFilename.basename tar) in
OpamFilename.copy ~src:tar ~dst:target;
fun () -> OpamFilename.copy ~src:target ~dst:tar)
else
( [...]
let target = OpamRepositoryRoot.Dir.backup ~tmp_dir dir in
OpamRepositoryRoot.Dir.copy ~src:dir ~dst:target;
fun () -> OpamRepositoryRoot.Dir.copy ~src:target ~dst:dir)
src/state/opamUpdate.ml
Outdated
| let safe_read_repo_file = function | ||
| | OpamRepositoryRoot.Dir dir -> | ||
| OpamFile.Repo.safe_read (OpamRepositoryPath.repo dir) |
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.
better have this function is OpamRepositoryState (cf related comment in 6625)
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.
I used the already existing OpamRepositoryRoot.delayed_read_repo function instead
|
I've pushed some commits that contains some reviews proposals, left some comments. It is a very preliminary review comments, i still have some blind spot (that's why i refer to 6625 comments too). |
283ee7a to
17fd765
Compare
…s called everywhere
17fd765 to
baf0725
Compare
| let target = OpamRepositoryRoot.Dir.backup ~tmp_dir dir in | ||
| OpamRepositoryRoot.Dir.copy ~src:dir ~dst:target; | ||
| fun () -> OpamRepositoryRoot.Dir.copy ~src:target ~dst:dir) |
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.
Yes, i saw. What i wanted to highlight is that (almost) the same code is used for tar & dir repositories : copy in tmp dir the do the copy and return the function that does the copy back. I was wondering if it is possible to factorise it using the abstraction.
if OpamFilename.exists tar then
(let target = OpamFilename.create tmp_dir (OpamFilename.basename tar) in
OpamFilename.copy ~src:tar ~dst:target;
fun () -> OpamFilename.copy ~src:target ~dst:tar)
else
( [...]
let target = OpamRepositoryRoot.Dir.backup ~tmp_dir dir in
OpamRepositoryRoot.Dir.copy ~src:dir ~dst:target;
fun () -> OpamRepositoryRoot.Dir.copy ~src:target ~dst:dir)| | Some (new_url, f) -> | ||
| OpamFilename.cleandir repo_root; | ||
| OpamRepositoryRoot.remove repo_root; | ||
| OpamRepositoryRoot.make_empty repo_root; |
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.
Do we need to create an empty directory here ? OpamHTTP and OpamVCS fetch_repo_update does not need the directory to exist, but OpamLocal requires it. I think it should be in there that the change should be applied. Plus, it'll make the functions more homogeneous.
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.
And like that, there is only the need to have Seems to be used in 6625 - OpamRepositoryRoot.Dir.make_empty and no OpamRepositoryRoot.make_emptyOpamHTTP.fetch_repo_update
| let copy = OpamFilename.copy_dir | ||
| let copy_except_vcs = OpamFilename.copy_dir_except_vcs |
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.
Doesn't worth to have only 1 function ?
| let copy = OpamFilename.copy_dir | |
| let copy_except_vcs = OpamFilename.copy_dir_except_vcs | |
| let copy ?(include_vcs=true) = | |
| if include_vcs then OpamFilename.copy_dir | |
| else OpamFilename.copy_dir_except_vcs |
| implementation (could be a database, a file, a directory, etc.) *) | ||
|
|
||
| (** Repository root implemented as a directory *) | ||
| module Dir : sig |
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.
Some functions are only present in the Dir module, and not meant to be abstracted via OpamRepositoryRoot module. In that case, they will be used only in the match case OpamRepositoryRoot.Dir dir, does it worth to work directly with OpamFilename functions for those part instead of having the redirections?
A good example of that is the change in OpamLocal lines 160-171 (new file)
|
|
||
| val remove : t -> unit | ||
| val is_empty : t -> bool option | ||
| val make_empty : t -> unit |
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.
If not removed
| val make_empty : t -> unit | |
| (* Creates the root of the repository *) | |
| val make_empty : t -> unit |
| "Enables option `--require-checksums' when available \ | ||
| (e.g. for `opam install')."; | ||
| "REPOSITORYTARRING", cli_between cli2_2 cli2_5, | ||
| "REPOSITORYTARRING", cli_from cli2_2, |
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.
Is the removal of repository tarring moved to 6625 ?
Extracted from #6625
Queued on #6679To be merged at the same time as ocaml-opam/opam-rt#86
As mentioned in #6625, adding abstract types over repository roots allows us to simplify and ensure correctness when adding a new format of repository.
In its current form, this PR also changes a couple of unrelated thing that i failed to change back when extracting from #6625 (removal of some use and logic associated withOpamRepositoryConfig.repo_tarring) so it needs at least a cleanup before it is in a mergable state (on top of being queued on the already substantial #6679)