at 17.09-beta 30 lines 1.1 kB view raw
1# This function downloads and normalizes a patch/diff file. 2# This is primarily useful for dynamically generated patches, 3# such as GitHub's or cgit's, where the non-significant content parts 4# often change with updating of git or cgit. 5# stripLen acts as the -p parameter when applying a patch. 6 7{ lib, fetchurl, patchutils }: 8{ stripLen ? 0, addPrefixes ? false, excludes ? [], ... }@args: 9 10fetchurl ({ 11 postFetch = '' 12 tmpfile="$TMPDIR/${args.sha256}" 13 "${patchutils}/bin/lsdiff" "$out" \ 14 | sort -u | sed -e 's/[*?]/\\&/g' \ 15 | xargs -I{} \ 16 "${patchutils}/bin/filterdiff" \ 17 --include={} \ 18 --strip=${toString stripLen} \ 19 ${lib.optionalString addPrefixes '' 20 --addoldprefix=a/ \ 21 --addnewprefix=b/ \ 22 ''} \ 23 --clean "$out" > "$tmpfile" 24 ${patchutils}/bin/filterdiff \ 25 -p1 \ 26 ${builtins.toString (builtins.map (x: "-x ${x}") excludes)} \ 27 "$tmpfile" > "$out" 28 ${args.postFetch or ""} 29 ''; 30} // builtins.removeAttrs args ["stripLen" "addPrefixes" "excludes"])