freebsd.mkDerivation: process patches generated with git

The diff parsing was pretty hardcoded for diff -u. Now it should handle
git diff/show as well.
This commit is contained in:
Audrey Dutcher 2024-05-27 12:27:21 -07:00
parent 2785d4f4ae
commit ba5f1b4400

View File

@ -128,15 +128,17 @@ lib.makeOverridable (
splitPatch =
patchFile:
let
allLines' = lib.strings.splitString "\n" (builtins.readFile patchFile);
allLines = builtins.filter (
line: !((lib.strings.hasPrefix "diff --git" line) || (lib.strings.hasPrefix "index " line))
) allLines';
foldFunc =
a: b:
if (lib.strings.hasPrefix "--- " b) then
if ((lib.strings.hasPrefix "--- " b) || (lib.strings.hasPrefix "diff --git " b)) then
(a ++ [ [ b ] ])
else
((lib.lists.init a) ++ (lib.lists.singleton ((lib.lists.last a) ++ [ b ])));
partitionedPatches' = lib.lists.foldl foldFunc [ [ ] ] (
lib.strings.splitString "\n" (builtins.readFile patchFile)
);
partitionedPatches' = lib.lists.foldl foldFunc [ [ ] ] allLines;
partitionedPatches =
if (builtins.length partitionedPatches' > 1) then
(lib.lists.drop 1 partitionedPatches')