diff options
| author | Jeremy Fleischman <jeremyfleischman@gmail.com> | 2025-05-23 14:15:40 -0700 |
|---|---|---|
| committer | Jeremy Fleischman <jeremyfleischman@gmail.com> | 2025-05-23 14:32:28 -0700 |
| commit | 1d32087125a9bb3e700b206ceb6eea28fdf07716 (patch) | |
| tree | bc4e95519f6795f40f20f699a080b2faee4cad17 /pkgs/build-support/fetchpatch | |
| parent | python3Packages.pinocchio: 3.6.0 -> 3.7.0 (#410159) (diff) | |
| download | nixpkgs-1d32087125a9bb3e700b206ceb6eea28fdf07716.tar.gz | |
fetchpatch: add support for patches to files with apostrophes
We're feeding a list of files from `lsdiff` to `filterdiff` via `xargs`.
That list is newline separated, and looks something like this:
```
$ lsdiff <(curl -s https://github.com/jfly/annoying-filenames/commit/1e86a219f5fc9c4137b409bc9c38036f3922724b.patch)
a/README.md
b/files/The Answer to the Ultimate Question of Life, The Universe, and Everything.txt
```
However, if the list contains files with apostrophes in it, xargs freaks
out:
```
$ echo "there's an apostrophe here" | xargs -I{} python -c "import sys; print(sys.argv)" {}
xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option
```
The fix is simple, just explicitly specify a delimiter:
```
$ echo "there's an apostrophe here" | xargs -I{} --delimiter='\n' python -c "import sys; print(sys.argv)" {}
['-c', "there's an apostrophe here"]
```
I added 2 tests here:
- `nix-build -A pkgs.tests.fetchpatch.fileWithApostrophe` fails without the code change.
- `nix-build -A pkgs.tests.fetchpatch.fileWithSpace` passes both before
and after this change, but I wanted to add it to prove that I didn't
break anything.
Diffstat (limited to 'pkgs/build-support/fetchpatch')
| -rw-r--r-- | pkgs/build-support/fetchpatch/default.nix | 2 | ||||
| -rw-r--r-- | pkgs/build-support/fetchpatch/tests.nix | 18 |
2 files changed, 19 insertions, 1 deletions
diff --git a/pkgs/build-support/fetchpatch/default.nix b/pkgs/build-support/fetchpatch/default.nix index 1b1f23b44c69..fa06d8631be4 100644 --- a/pkgs/build-support/fetchpatch/default.nix +++ b/pkgs/build-support/fetchpatch/default.nix @@ -67,7 +67,7 @@ lib.throwIfNot (excludes == [ ] || includes == [ ]) ${lib.optionalString (relative != null) "-p1 -i ${lib.escapeShellArg relative}/'*'"} \ "$out" \ | sort -u | sed -e 's/[*?]/\\&/g' \ - | xargs -I{} \ + | xargs -I{} --delimiter='\n' \ filterdiff \ --include={} \ --strip=${toString stripLen} \ diff --git a/pkgs/build-support/fetchpatch/tests.nix b/pkgs/build-support/fetchpatch/tests.nix index 82482a820592..77fe380d9710 100644 --- a/pkgs/build-support/fetchpatch/tests.nix +++ b/pkgs/build-support/fetchpatch/tests.nix @@ -48,4 +48,22 @@ in else "sha256-SJHk8XrutqAyoIdORlhCpBCN626P+uzed7mjKz5eQYY="; }; + + fileWithSpace = testers.invalidateFetcherByDrvHash fetchpatch { + url = "https://github.com/jfly/annoying-filenames/commit/1e86a219f5fc9c4137b409bc9c38036f3922724b.patch"; + sha256 = + if isFetchpatch2 then + "sha256-RB6pjigoXtzHILkGFXYd3Lz2aM9DvO0NRmLdey1N6gg=" + else + "sha256-aptUvVojqIIIVNuHqkl+C+dZBGFfs+1MUd0FNV+4j4E="; + }; + + fileWithApostrophe = testers.invalidateFetcherByDrvHash fetchpatch { + url = "https://github.com/jfly/annoying-filenames/commit/8b6d8f8d7094ce646523b3369cfdf5030289c66c.patch"; + sha256 = + if isFetchpatch2 then + "sha256-CrQFmVvLEvWpo2ucVrWyLb5qk2GVOxyUbFN3hp9sV68=" + else + "sha256-CrQFmVvLEvWpo2ucVrWyLb5qk2GVOxyUbFN3hp9sV68="; + }; } |
