Skip to content

Conversation

@kit-ty-kate
Copy link
Member

@kit-ty-kate kit-ty-kate commented Sep 9, 2025

Extracted from #6625
Queued on #6679
To 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 with OpamRepositoryConfig.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)

Comment on lines +2520 to +2522
let target = OpamRepositoryRoot.Dir.backup ~tmp_dir dir in
OpamRepositoryRoot.Dir.copy ~src:dir ~dst:target;
fun () -> OpamRepositoryRoot.Dir.copy ~src:target ~dst:dir)
Copy link
Collaborator

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 ?

Copy link
Member Author

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

Copy link
Collaborator

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)

Comment on lines 21 to 23
let safe_read_repo_file = function
| OpamRepositoryRoot.Dir dir ->
OpamFile.Repo.safe_read (OpamRepositoryPath.repo dir)
Copy link
Collaborator

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)

Copy link
Member Author

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

@rjbou
Copy link
Collaborator

rjbou commented Oct 9, 2025

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).

@rjbou rjbou force-pushed the abstract-repository-root branch from 283ee7a to 17fd765 Compare October 10, 2025 17:28
@kit-ty-kate kit-ty-kate force-pushed the abstract-repository-root branch from 17fd765 to baf0725 Compare October 10, 2025 22:33
@kit-ty-kate kit-ty-kate marked this pull request as ready for review October 11, 2025 00:04
@kit-ty-kate kit-ty-kate removed PR: QUEUED Pending pull request, waiting for other work to be merged or closed PR: WIP Not for merge at this stage labels Oct 11, 2025
kit-ty-kate added a commit to kit-ty-kate/opam-rt that referenced this pull request Oct 11, 2025
@kit-ty-kate kit-ty-kate requested a review from rjbou October 11, 2025 22:10
Comment on lines +2520 to +2522
let target = OpamRepositoryRoot.Dir.backup ~tmp_dir dir in
OpamRepositoryRoot.Dir.copy ~src:dir ~dst:target;
fun () -> OpamRepositoryRoot.Dir.copy ~src:target ~dst:dir)
Copy link
Collaborator

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;
Copy link
Collaborator

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.

Copy link
Collaborator

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 OpamRepositoryRoot.Dir.make_empty and no OpamRepositoryRoot.make_empty Seems to be used in 6625 - OpamHTTP.fetch_repo_update

Comment on lines +29 to +30
let copy = OpamFilename.copy_dir
let copy_except_vcs = OpamFilename.copy_dir_except_vcs
Copy link
Collaborator

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 ?

Suggested change
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
Copy link
Collaborator

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not removed

Suggested change
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,
Copy link
Collaborator

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants