2014-05-17 05:27:29 +00:00
|
|
|
# This function downloads and normalizes a patch/diff file.
|
|
|
|
# This is primarily useful for dynamically generated patches,
|
|
|
|
# such as GitHub's or cgit's, where the non-significant content parts
|
|
|
|
# often change with updating of git or cgit.
|
|
|
|
# stripLen acts as the -p parameter when applying a patch.
|
|
|
|
|
2016-07-29 01:54:31 +00:00
|
|
|
{ lib, fetchurl, patchutils }:
|
2018-06-05 02:29:22 +00:00
|
|
|
{ stripLen ? 0, extraPrefix ? null, excludes ? [], includes ? [], ... }@args:
|
2014-05-17 05:27:29 +00:00
|
|
|
|
|
|
|
fetchurl ({
|
|
|
|
postFetch = ''
|
|
|
|
tmpfile="$TMPDIR/${args.sha256}"
|
|
|
|
"${patchutils}/bin/lsdiff" "$out" \
|
|
|
|
| sort -u | sed -e 's/[*?]/\\&/g' \
|
|
|
|
| xargs -I{} \
|
|
|
|
"${patchutils}/bin/filterdiff" \
|
|
|
|
--include={} \
|
|
|
|
--strip=${toString stripLen} \
|
2018-01-04 19:55:19 +00:00
|
|
|
${lib.optionalString (extraPrefix != null) ''
|
|
|
|
--addoldprefix=a/${extraPrefix} \
|
|
|
|
--addnewprefix=b/${extraPrefix} \
|
2016-07-29 01:54:31 +00:00
|
|
|
''} \
|
2014-05-17 05:27:29 +00:00
|
|
|
--clean "$out" > "$tmpfile"
|
2017-07-26 10:59:02 +00:00
|
|
|
${patchutils}/bin/filterdiff \
|
|
|
|
-p1 \
|
|
|
|
${builtins.toString (builtins.map (x: "-x ${x}") excludes)} \
|
2018-06-05 02:29:22 +00:00
|
|
|
${builtins.toString (builtins.map (x: "-i ${x}") includes)} \
|
2017-07-26 10:59:02 +00:00
|
|
|
"$tmpfile" > "$out"
|
2015-06-19 16:50:08 +00:00
|
|
|
${args.postFetch or ""}
|
2014-05-17 05:27:29 +00:00
|
|
|
'';
|
2018-06-05 02:29:22 +00:00
|
|
|
meta.broken = excludes != [] && includes != [];
|
|
|
|
} // builtins.removeAttrs args ["stripLen" "extraPrefix" "excludes" "includes" "postFetch"])
|