2014-05-17 09:27:29 +04: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 04:54:31 +03:00
|
|
|
{ lib, fetchurl, patchutils }:
|
|
|
|
{ stripLen ? 0, addPrefixes ? false, ... }@args:
|
2014-05-17 09:27:29 +04: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} \
|
2016-07-29 04:54:31 +03:00
|
|
|
${lib.optionalString addPrefixes ''
|
|
|
|
--addoldprefix=a/ \
|
|
|
|
--addnewprefix=b/ \
|
|
|
|
''} \
|
2014-05-17 09:27:29 +04:00
|
|
|
--clean "$out" > "$tmpfile"
|
|
|
|
mv "$tmpfile" "$out"
|
2015-06-19 19:50:08 +03:00
|
|
|
${args.postFetch or ""}
|
2014-05-17 09:27:29 +04:00
|
|
|
'';
|
2016-07-29 04:54:31 +03:00
|
|
|
} // builtins.removeAttrs args ["stripLen" "addPrefixes"])
|