Skip to content
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

Apply patches when dealing with repositories via an OCaml implementation of patch #5892

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kit-ty-kate
Copy link
Member

@kit-ty-kate kit-ty-kate commented Mar 20, 2024

WIP

Fixes #6019
Fixes #3782
requires hannesm/patch#9
requires hannesm/patch#7
see #5891

cc @hannesm

TODO:

  • add one test per operation type for each backend
  • in each of those tests show the output of the resulting patch file

@kit-ty-kate kit-ty-kate added the PR: WIP Not for merge at this stage label Mar 20, 2024
let internal_patch ~dir p =
let fmt = Printf.sprintf in
let get_path file =
let dir = real_path dir in
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
let dir = real_path dir in
(* NOTE: Important to keep this `concat dir ""` to ensure the
is_prefix_of doesn't match another directory *)
let dir = Filename.concat (real_path dir) "" in

@kit-ty-kate
Copy link
Member Author

Could be coupled with ocaml-patch's implementation of diff via hannesm/patch#12

@@ -36,6 +36,7 @@ depends: [
"sha" {>= "1.13"}
"jsonm"
"swhid_core"
"patch" {>= "1.0.1"}
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
"patch" {>= "1.0.1"}
"patch" {>= "2.0.0"}

log "Internal diff (empty) done in %.2fs." (chrono ());
None
| diffs ->
log "Internal diff (non-empty) done in %.2fs." (chrono ());
Copy link
Member Author

Choose a reason for hiding this comment

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

TODO: add a benchmark to show improvement before and after #5896

@@ -205,7 +205,7 @@ module VCS : OpamVCS.VCS = struct
else if OpamSystem.file_is_empty patch_file then
(finalise (); Done None)
else
Done (Some (OpamFilename.of_string patch_file))
Done (Some (OpamFilename.of_string patch_file, Patch.to_diffs ~p:1 (String.concat "\n" r.r_stdout)))
Copy link
Member Author

Choose a reason for hiding this comment

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

the use of Patch.to_diffs should be avoided in opam as long as the diff parser isn't complete and well tested.

Instead we can use OpamRepositoryBackend.get_diff, ignore all the changes in .git/.hg/.darcs and voilà (hopefully)

@@ -42,8 +42,9 @@ module type VCS = sig
val patch_applied: dirname -> url -> unit OpamProcess.job

(** Returns the pending modifications in the form of a patch file, or None if
val diff: dirname -> url -> (filename * Patch.t list) option OpamProcess.job
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
val diff: dirname -> url -> (filename * Patch.t list) option OpamProcess.job

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: WIP Not for merge at this stage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

gpatch @ macos GNU patch < 2.7.6 doesn't apply executable bit correctly
1 participant