2014-05-17 07:27:29 +02: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 03:54:31 +02:00
|
|
|
{ lib, fetchurl, patchutils }:
|
2018-06-05 04:29:22 +02:00
|
|
|
{ stripLen ? 0, extraPrefix ? null, excludes ? [], includes ? [], ... }@args:
|
2014-05-17 07:27:29 +02:00
|
|
|
|
|
|
|
fetchurl ({
|
|
|
|
postFetch = ''
|
|
|
|
tmpfile="$TMPDIR/${args.sha256}"
|
2018-07-15 13:57:37 +02:00
|
|
|
if [ ! -s "$out" ]; then
|
|
|
|
echo "error: Fetched patch file '$out' is empty!" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2014-05-17 07:27:29 +02:00
|
|
|
"${patchutils}/bin/lsdiff" "$out" \
|
|
|
|
| sort -u | sed -e 's/[*?]/\\&/g' \
|
|
|
|
| xargs -I{} \
|
|
|
|
"${patchutils}/bin/filterdiff" \
|
|
|
|
--include={} \
|
|
|
|
--strip=${toString stripLen} \
|
2018-01-04 20:55:19 +01:00
|
|
|
${lib.optionalString (extraPrefix != null) ''
|
|
|
|
--addoldprefix=a/${extraPrefix} \
|
|
|
|
--addnewprefix=b/${extraPrefix} \
|
2016-07-29 03:54:31 +02:00
|
|
|
''} \
|
2014-05-17 07:27:29 +02:00
|
|
|
--clean "$out" > "$tmpfile"
|
2018-07-15 13:57:37 +02:00
|
|
|
if [ ! -s "$tmpfile" ]; then
|
|
|
|
echo "error: Normalized patch '$tmpfile' is empty (while the fetched file was not)!" 1>&2
|
|
|
|
echo "Did you maybe fetch a HTML representation of a patch instead of a raw patch?" 1>&2
|
|
|
|
echo "Fetched file was:" 1>&2
|
|
|
|
cat "$out" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2017-07-26 12:59:02 +02:00
|
|
|
${patchutils}/bin/filterdiff \
|
|
|
|
-p1 \
|
2018-07-15 09:58:47 +02:00
|
|
|
${builtins.toString (builtins.map (x: "-x ${lib.escapeShellArg x}") excludes)} \
|
|
|
|
${builtins.toString (builtins.map (x: "-i ${lib.escapeShellArg x}") includes)} \
|
2017-07-26 12:59:02 +02:00
|
|
|
"$tmpfile" > "$out"
|
2015-06-19 18:50:08 +02:00
|
|
|
${args.postFetch or ""}
|
2018-07-15 13:57:37 +02:00
|
|
|
if [ ! -s "$out" ]; then
|
|
|
|
echo "error: Filtered patch '$out$' is empty (while the original patch file was not)!" 1>&2
|
|
|
|
echo "Check your includes and excludes." 1>&2
|
|
|
|
echo "Normalizd patch file was:" 1>&2
|
|
|
|
cat "$tmpfile" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2014-05-17 07:27:29 +02:00
|
|
|
'';
|
2018-06-05 04:29:22 +02:00
|
|
|
meta.broken = excludes != [] && includes != [];
|
|
|
|
} // builtins.removeAttrs args ["stripLen" "extraPrefix" "excludes" "includes" "postFetch"])
|