Skip to content

Commit

Permalink
Merge pull request #5400 from kit-ty-kate/no-gpatch
Browse files Browse the repository at this point in the history
Replace the dependency on GNU patch by a strict dependency on git
  • Loading branch information
kit-ty-kate authored Mar 4, 2024
2 parents a4a651a + 30f9ab7 commit 321ca42
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 26 deletions.
14 changes: 8 additions & 6 deletions doc/pages/Manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -888,10 +888,11 @@ files.
- <a id="opamfield-patches">`patches: [ <string> { <filter> } ... ]`</a>: a list
of files relative to the project source root (often added through the `files/`
metadata subdirectory). The listed patch files will be applied sequentially to
the source as with the `patch` command, stripping one level of leading
directories (`-p1`) -- which is what version control systems generally use .
Variable interpolation is available, so you can specify `patches: [ "file" ]`
to have the patch processed from `file.in`.
the source using the `patch` command (before opam 2.2) or `git apply`
(since opam 2.2), stripping one level of leading directories (`-p1`) -- which
is what version control systems generally use. Variable interpolation is
available, so you can specify `patches: [ "file" ]` to have the patch
processed from `file.in`.

Patches may be applied conditionally by adding _filters_.

Expand Down Expand Up @@ -1531,8 +1532,9 @@ them modified with [`opam option --global`](man/opam-option.html).
- `quorum`: integer, the currently defined quorum
- `repo`: directory containing the already-validated state of the repository
(empty for an initial validation)
- `patch`: for incremental validation, filename of a patch applying to
`repo` (with `patch -p1`) and that needs verification
- `patch`: for incremental validation, filename of a patch applying to `repo`
(using `patch -p1` before opam 2.2, and using `git apply -p1` since opam 2.2)
and that needs verification
- `dir`: for initial validation, the directory to verify
- `incremental`: `false` if doing an initial validation based on `dir`,
`true` for an incremental validation based on `repo` and `patch`.
Expand Down
2 changes: 2 additions & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ users)
* Fix `git-location` handling in init config file [#5848 @rjbou - fix #5845]
* Fix MSYS2 support [#5843 @rjbou - fix #5683]
* Test if file exists before sourcing in fish + powershell [#5864 @ElectreAAS]
* Replace the dependency on GNU patch by a strict dependency on git [#5400 @kit-ty-kate - fix #3433 #3782 #3639]

## Config report

Expand Down Expand Up @@ -155,3 +156,4 @@ users)

## opam-core
* `OpamStd.Sys`: add `is_cygwin_variant_cygcheck` that returns true if in path `cygcheck` is from a Cygwin or MSYS2 installation [#5843 @rjbou]
* `OpamSystem.patch`: use `git -c core.autocrlf=false apply --unsafe-paths -p1 <patch>` instead of `patch` [#5400 @kit-ty-kate - fix #3433 #3782 #3639]
6 changes: 1 addition & 5 deletions src/client/opamInitDefaults.ml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ let not_win32_filter =
FOp (FIdent ([], OpamVariable.of_string "os", None), `Neq, FString "win32")
let sandbox_filter = FOr (linux_filter, macos_filter)

let gpatch_filter = FOr (openbsd_filter, freebsd_filter)
let patch_filter = FNot gpatch_filter

let gtar_filter = openbsd_filter
let tar_filter = FNot gtar_filter

Expand Down Expand Up @@ -134,8 +131,7 @@ let required_tools ~sandboxing () =
req_dl_tools () @
[
["diff"], None, None;
["patch"], None, Some patch_filter;
["gpatch"], None, Some gpatch_filter;
["git"], None, None;
["tar"], None, Some tar_filter;
["gtar"], None, Some gtar_filter;
["unzip"], None, None;
Expand Down
8 changes: 1 addition & 7 deletions src/core/opamSystem.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1645,13 +1645,7 @@ let patch ?(preprocess=true) ~dir p =
else
p
in
let patch_cmd =
match OpamStd.Sys.os () with
| OpamStd.Sys.OpenBSD
| OpamStd.Sys.FreeBSD -> "gpatch"
| _ -> "patch"
in
make_command ~name:"patch" ~dir patch_cmd ["-p1"; "-i"; p'] @@> fun r ->
make_command ~name:"git apply" ~dir "git" ["-c"; "core.autocrlf=false"; "apply"; "--unsafe-paths"; "-p1"; p'] @@> fun r ->
if not (OpamConsole.debug ()) then Sys.remove p';
if OpamProcess.is_success r then Done None
else Done (Some (Process_error r))
Expand Down
16 changes: 8 additions & 8 deletions tests/reftests/repository.test
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ build: ["test" "-f" "bar"]
some content
### : Internal repository storage as archive or plain directory :
### opam switch create tarring --empty
### opam update -vv | grep '^\+' | sed-cmd diff | sed-cmd patch | 'patch-[^"]+' -> 'patch'
### opam update -vv | grep '^\+' | sed-cmd diff | sed-cmd git | 'patch-[^"]+' -> 'patch'
+ diff "-ruaN" "default" "default.new" (CWD=${BASEDIR}/OPAM/repo)
+ patch "-p1" "-i" "${BASEDIR}/OPAM/log/patch" (CWD=${BASEDIR}/OPAM/repo/default)
+ git "-c" "core.autocrlf=false" "apply" "--unsafe-paths" "-p1" "${BASEDIR}/OPAM/log/patch" (CWD=${BASEDIR}/OPAM/repo/default)
### ls $OPAMROOT/repo | grep -v "cache"
default
lock
Expand All @@ -24,9 +24,9 @@ opam-version: "2.0"
build: ["test" "-f" "baz"]
### <REPO/packages/foo/foo.2/files/baz>
some content
### opam update default -vv | grep '^\+' | sed-cmd tar | sed-cmd diff | sed-cmd patch | 'patch-[^"]+' -> 'patch'
### opam update default -vv | grep '^\+' | sed-cmd tar | sed-cmd diff | sed-cmd git | 'patch-[^"]+' -> 'patch'
+ diff "-ruaN" "default" "default.new" (CWD=${BASEDIR}/OPAM/repo)
+ patch "-p1" "-i" "${BASEDIR}/OPAM/log/patch" (CWD=${BASEDIR}/OPAM/repo/default)
+ git "-c" "core.autocrlf=false" "apply" "--unsafe-paths" "-p1" "${BASEDIR}/OPAM/log/patch" (CWD=${BASEDIR}/OPAM/repo/default)
+ tar "cfz" "${BASEDIR}/OPAM/repo/default.tar.gz.tmp" "-C" "${BASEDIR}/OPAM/repo" "default"
### ls $OPAMROOT/repo | grep -v "cache"
default.tar.gz
Expand Down Expand Up @@ -61,10 +61,10 @@ opam-version: "2.0"
build: ["test" "-f" "baz"]
### <REPO/packages/foo/foo.4/files/baz>
some content
### opam update -vv | grep '^\+' | sed-cmd tar | sed-cmd diff | sed-cmd patch | 'patch-[^"]+' -> 'patch'
### opam update -vv | grep '^\+' | sed-cmd tar | sed-cmd diff | sed-cmd git | 'patch-[^"]+' -> 'patch'
+ tar "xfz" "${BASEDIR}/OPAM/repo/tarred.tar.gz" "-C" "${OPAMTMP}"
+ diff "-ruaN" "tarred" "tarred.new" (CWD=${OPAMTMP})
+ patch "-p1" "-i" "${BASEDIR}/OPAM/log/patch" (CWD=${OPAMTMP}/tarred)
+ git "-c" "core.autocrlf=false" "apply" "--unsafe-paths" "-p1" "${BASEDIR}/OPAM/log/patch" (CWD=${OPAMTMP}/tarred)
+ tar "cfz" "${BASEDIR}/OPAM/repo/tarred.tar.gz.tmp" "-C" "${OPAMTMP}" "tarred"
### opam install foo.4 -vv | grep '^\+' | sed-cmd test | sed-cmd tar
+ tar "xfz" "${BASEDIR}/OPAM/repo/tarred.tar.gz" "-C" "${OPAMTMP}"
Expand All @@ -83,10 +83,10 @@ opam-version: "2.0"
build: ["test" "-f" "quux"]
### <REPO/packages/foo/foo.5/files/quux>
some content
### opam update -vv | grep '^\+' | sed-cmd tar | sed-cmd diff | sed-cmd patch | 'patch-[^"]+' -> 'patch'
### opam update -vv | grep '^\+' | sed-cmd tar | sed-cmd diff | sed-cmd git | 'patch-[^"]+' -> 'patch'
+ tar "xfz" "${BASEDIR}/OPAM/repo/tarred.tar.gz" "-C" "${OPAMTMP}"
+ diff "-ruaN" "tarred" "tarred.new" (CWD=${OPAMTMP})
+ patch "-p1" "-i" "${BASEDIR}/OPAM/log/patch" (CWD=${OPAMTMP}/tarred)
+ git "-c" "core.autocrlf=false" "apply" "--unsafe-paths" "-p1" "${BASEDIR}/OPAM/log/patch" (CWD=${OPAMTMP}/tarred)
### opam install foo.5 -vv | grep '^\+' | sed-cmd test
+ test "-f" "quux" (CWD=${BASEDIR}/OPAM/tarring/.opam-switch/build/foo.5)
### ls $OPAMROOT/repo | grep -v "cache"
Expand Down

0 comments on commit 321ca42

Please sign in to comment.