-
Notifications
You must be signed in to change notification settings - Fork 401
Homogenize the behaviour of initial repository loads and subsequent loads from diff #6924
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?
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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -101,17 +101,7 @@ let get_repo_files rt name dir = | |||||||||
|
|
||||||||||
| let read_package_opam ~repo_name ~repo_root package_dir = | ||||||||||
| match OpamFileTools.read_repo_opam ~repo_name ~repo_root package_dir with | ||||||||||
| | Some opam -> | ||||||||||
| (try | ||||||||||
| let nv = | ||||||||||
| OpamPackage.of_string | ||||||||||
| (OpamFilename.Base.to_string (OpamFilename.basename_dir package_dir)) | ||||||||||
| in | ||||||||||
| Some (nv, opam) | ||||||||||
| with Failure _ -> | ||||||||||
| log "ERR: directory name not a valid package: ignored %s" | ||||||||||
| (OpamFilename.to_string OpamFilename.Op.(package_dir // "opam")); | ||||||||||
| None) | ||||||||||
| | Some opam -> Some opam | ||||||||||
| | None -> | ||||||||||
| log "ERR: Could not load %s, ignored" | ||||||||||
| (OpamFilename.to_string OpamFilename.Op.(package_dir // "opam")); | ||||||||||
|
|
@@ -123,71 +113,72 @@ let load_opams_from_dir repo_name repo_root = | |||||||||
| (OpamConsole.colorise `blue (OpamRepositoryName.to_string repo_name)); | ||||||||||
| (* FIXME: why is this different from OpamPackage.list ? *) | ||||||||||
| let rec aux r dir = | ||||||||||
| if OpamFilename.exists_dir dir then | ||||||||||
| let fnames = Sys.readdir (OpamFilename.Dir.to_string dir) in | ||||||||||
| if Array.exists (fun f -> f = "opam") fnames then | ||||||||||
| match read_package_opam ~repo_name ~repo_root dir with | ||||||||||
| | Some (nv, opam) -> OpamPackage.Map.add nv opam r | ||||||||||
| let full_path = | ||||||||||
| OpamFilename.Op.(repo_root / OpamFilename.Unix.Dir.to_string dir) | ||||||||||
| in | ||||||||||
| if OpamFilename.exists_dir full_path then | ||||||||||
| match OpamRepositoryPath.get_pkg_dir OpamFilename.Unix.Op.(dir // "") with | ||||||||||
| | Some (nv, _pkg_dir) -> | ||||||||||
| (* NOTE: we ignore [pkg_dir] because load_opams_from_dir | ||||||||||
| will always scan parent directories before going deeper *) | ||||||||||
| begin match read_package_opam ~repo_name ~repo_root full_path with | ||||||||||
|
Collaborator
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. we need to check here if the file is
Member
Author
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. mmh i don't think so. Do you have an example where it does that? |
||||||||||
| | Some opam -> OpamPackage.Map.add nv opam r | ||||||||||
| | None -> r | ||||||||||
|
Comment on lines
+124
to
126
Collaborator
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. We no longer have the error
Member
Author
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. The error cannot happen in the new version since we're checking using get_pkg_dir. Also i'm unable to find this debug log anywhere in our testsuite |
||||||||||
| else | ||||||||||
| Array.fold_left (fun r name -> aux r OpamFilename.Op.(dir / name)) | ||||||||||
| r fnames | ||||||||||
| end | ||||||||||
| | None -> | ||||||||||
| Array.fold_left (fun r name -> aux r OpamFilename.Unix.Op.(dir / name)) | ||||||||||
| r (Sys.readdir (OpamFilename.Dir.to_string full_path)) | ||||||||||
| else r | ||||||||||
| in | ||||||||||
| Fun.protect | ||||||||||
| (fun () -> aux OpamPackage.Map.empty (OpamRepositoryPath.packages_dir repo_root)) | ||||||||||
| (fun () -> | ||||||||||
| aux OpamPackage.Map.empty (OpamFilename.Unix.Dir.of_string "packages")) | ||||||||||
| ~finally:OpamConsole.clear_status | ||||||||||
|
|
||||||||||
| let load_opams_from_diff repo diffs rt = | ||||||||||
| if OpamConsole.disp_status_line () || OpamConsole.verbose () then | ||||||||||
| OpamConsole.status_line "Processing: [%s: loading data]" | ||||||||||
| (OpamConsole.colorise `blue (OpamRepositoryName.to_string repo.repo_name)); | ||||||||||
| (OpamConsole.colorise `blue | ||||||||||
| (OpamRepositoryName.to_string repo.repo_name)); | ||||||||||
| let existing_opams = | ||||||||||
| OpamRepositoryName.Map.find repo.repo_name rt.repo_opams | ||||||||||
| in | ||||||||||
| let repo_root = get_repo_root rt repo in | ||||||||||
| (* processed_dirs: used to avoid re-read in case of diff generated by extra files. | ||||||||||
| added_pkgs: used to skip removing version-equivalent packages *) | ||||||||||
| let process_file (opams, processed_dirs, added_pkgs) file ~is_removal = | ||||||||||
| let pkg_dir = | ||||||||||
| let file = OpamFilename.raw file in | ||||||||||
| let dirname = OpamFilename.dirname file in | ||||||||||
| let basename = OpamFilename.basename_dir dirname in | ||||||||||
| let full_path = | ||||||||||
| Filename.concat | ||||||||||
| (OpamFilename.Dir.to_string repo_root) | ||||||||||
| (OpamFilename.Dir.to_string dirname) | ||||||||||
| in | ||||||||||
| if OpamFilename.Base.to_string basename = "files" then | ||||||||||
| OpamFilename.Dir.of_string (Filename.dirname full_path) | ||||||||||
| else | ||||||||||
| OpamFilename.Dir.of_string full_path | ||||||||||
| in | ||||||||||
| if OpamFilename.Dir.Set.mem pkg_dir processed_dirs then | ||||||||||
| match OpamRepositoryPath.get_pkg_dir file with | ||||||||||
| | None -> | ||||||||||
| log "ERR: file name not a valid package: ignored %s" | ||||||||||
|
Collaborator
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
Member
Author
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. Well %s is not a directory but a file, so it should rather be
Suggested change
|
||||||||||
| (OpamFilename.Unix.to_string file); | ||||||||||
| opams, processed_dirs, added_pkgs | ||||||||||
| else | ||||||||||
| let processed_dirs = OpamFilename.Dir.Set.add pkg_dir processed_dirs in | ||||||||||
| match read_package_opam ~repo_name:repo.repo_name ~repo_root pkg_dir with | ||||||||||
| | Some (nv, opam) -> | ||||||||||
| let added_pkgs = OpamPackage.Set.add nv added_pkgs in | ||||||||||
| OpamPackage.Map.add nv opam opams, processed_dirs, added_pkgs | ||||||||||
| | None -> | ||||||||||
| if is_removal then | ||||||||||
| match OpamPackage.of_dirname pkg_dir with | ||||||||||
| | None -> | ||||||||||
| log "ERR: directory name not a valid package: ignored %s" | ||||||||||
| (OpamFilename.Dir.to_string pkg_dir); | ||||||||||
| opams, processed_dirs, added_pkgs | ||||||||||
| | Some nv -> | ||||||||||
| | Some (nv, pkg_dir) -> | ||||||||||
| if OpamFilename.Unix.Dir.Set.mem pkg_dir processed_dirs then | ||||||||||
| opams, processed_dirs, added_pkgs | ||||||||||
| else | ||||||||||
| let processed_dirs = OpamFilename.Unix.Dir.Set.add pkg_dir processed_dirs in | ||||||||||
| let full_path = | ||||||||||
| OpamFilename.Op.(repo_root / OpamFilename.Unix.Dir.to_string pkg_dir) | ||||||||||
| in | ||||||||||
| match read_package_opam ~repo_name:repo.repo_name ~repo_root full_path with | ||||||||||
| | Some opam -> | ||||||||||
| let added_pkgs = OpamPackage.Set.add nv added_pkgs in | ||||||||||
| OpamPackage.Map.add nv opam opams, processed_dirs, added_pkgs | ||||||||||
| | None -> | ||||||||||
| if is_removal then | ||||||||||
| if OpamPackage.Set.mem nv added_pkgs then | ||||||||||
| opams, processed_dirs, added_pkgs | ||||||||||
| else | ||||||||||
| OpamPackage.Map.remove nv opams, processed_dirs, added_pkgs | ||||||||||
| else | ||||||||||
| opams, processed_dirs, added_pkgs | ||||||||||
| else | ||||||||||
| opams, processed_dirs, added_pkgs | ||||||||||
| in | ||||||||||
| let remove_file file acc = | ||||||||||
| process_file acc (OpamFilename.Unix.of_string file) ~is_removal:true | ||||||||||
| in | ||||||||||
| let add_file file acc = | ||||||||||
| process_file acc (OpamFilename.Unix.of_string file) ~is_removal:false | ||||||||||
| in | ||||||||||
| let remove_file file acc = process_file acc file ~is_removal:true in | ||||||||||
| let add_file file acc = process_file acc file ~is_removal:false in | ||||||||||
| let process_operation acc = function | ||||||||||
| | Patch.Edit (old_file, new_file) -> | ||||||||||
| if String.equal old_file new_file | ||||||||||
|
|
@@ -207,7 +198,9 @@ let load_opams_from_diff repo diffs rt = | |||||||||
| (fun () -> | ||||||||||
| let opams, _, _ = | ||||||||||
| List.fold_left process_operation | ||||||||||
| (existing_opams, OpamFilename.Dir.Set.empty, OpamPackage.Set.empty) | ||||||||||
| (existing_opams, | ||||||||||
| OpamFilename.Unix.Dir.Set.empty, | ||||||||||
| OpamPackage.Set.empty) | ||||||||||
| diffs | ||||||||||
| in | ||||||||||
| opams) | ||||||||||
|
|
||||||||||
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.