fetchpatch: support hunks option (#450207)

This commit is contained in:
Philip Taron
2025-10-13 15:25:34 +00:00
committed by GitHub
3 changed files with 30 additions and 5 deletions

View File

@@ -699,6 +699,9 @@ MSCREATE.DIR PINBALL.DOC PINBALL.MID Sounds WAVEMIX.INF
- `extraPrefix`: Prefix pathnames by this string.
- `excludes`: Exclude files matching these patterns (applies after the above arguments).
- `includes`: Include only files matching these patterns (applies after the above arguments).
- `hunks`: Choose the specified hunks from each file (applies after the above arguments).
Note that you can specify a list of numbers or ranges of numbers
(for example, `[ 1 2 3 4 ]`, `[ "1-4" ]`, `[ "-4" ]`, or `[ "1-" ]` would all be the same effective range in a patch applying 4 hunks to a single file).
- `revert`: Revert the patch.
Note that because the checksum is computed after applying these effects, using or modifying these arguments will have no effect unless the `hash` argument is changed as well.

View File

@@ -17,6 +17,7 @@
extraPrefix ? null,
excludes ? [ ],
includes ? [ ],
hunks ? [ ],
revert ? false,
postFetch ? "",
nativeBuildInputs ? [ ],
@@ -90,6 +91,10 @@ lib.throwIfNot (excludes == [ ] || includes == [ ])
-p1 \
${toString (map (x: "-x ${lib.escapeShellArg x}") excludes)} \
${toString (map (x: "-i ${lib.escapeShellArg x}") includes)} \
${
lib.optionalString (hunks != [ ])
"-# ${lib.escapeShellArg (lib.concatMapStringsSep "," toString hunks)}"
} \
"$tmpfile" > "$out"
if [ ! -s "$out" ]; then
@@ -113,6 +118,7 @@ lib.throwIfNot (excludes == [ ] || includes == [ ])
"extraPrefix"
"excludes"
"includes"
"hunks"
"revert"
"postFetch"
"nativeBuildInputs"

View File

@@ -24,18 +24,34 @@ in
"sha256-KlmIbixcds6GyKYt1fx5BxDIrU7msrgDdYo9Va/KJR4=";
};
hunks = testers.invalidateFetcherByDrvHash fetchpatch {
url = "https://github.com/openssh/openssh-portable/commit/35d5917652106aede47621bb3f64044604164043.patch";
stripLen = 1;
hunks = [
2
3
4
5
6
7
];
sha256 =
if isFetchpatch2 then
"sha256-SXJALY4zC4y/ZV7uVglf+XB5cpC5tS4M8QDGlFRmcFM="
else
"sha256-MV7uGgA1ESMR7W6H5FjAIxKcpySdQjWB+L2zaHjd96M=";
};
full = testers.invalidateFetcherByDrvHash fetchpatch {
url = "https://github.com/boostorg/math/commit/7d482f6ebc356e6ec455ccb5f51a23971bf6ce5b.patch";
relative = "test";
stripLen = 1;
extraPrefix = "foo/bar/";
excludes = [ "foo/bar/bernoulli_no_atomic_mp.cpp" ];
# Should result in no change.
hunks = [ "1-" ];
revert = true;
sha256 =
if isFetchpatch2 then
"sha256-+UKmEbr2rIAweCav/hR/7d4ZrYV84ht/domTrHtm8sM="
else
"sha256-+UKmEbr2rIAweCav/hR/7d4ZrYV84ht/domTrHtm8sM=";
sha256 = "sha256-+UKmEbr2rIAweCav/hR/7d4ZrYV84ht/domTrHtm8sM=";
};
decode = testers.invalidateFetcherByDrvHash fetchpatch {