fetchpatch: add "decode" argument for gerrit

(and gitiles)

This allows fetching a patch from servers that return them
base64-encoded, like this:

    fetchpatch {
      name = "gcc.patch";
      url = "f37ae3b1a8^!?format=TEXT";
      decode = "base64 -d";
      sha256 = "11j1bqz2p8xrfzgfrylgdvmqs45489c4ckl7l0ra1dpfgbqy94a8";
    }
This commit is contained in:
Alyssa Ross 2021-07-02 14:58:42 +00:00
parent d4f3301440
commit dd6e94f2c1

View file

@ -8,6 +8,7 @@
{ relative ? null
, stripLen ? 0
, decode ? "cat" # custom command to decode patch e.g. base64 -d
, extraPrefix ? null
, excludes ? []
, includes ? []
@ -36,6 +37,17 @@ fetchurl ({
exit 1
fi
set +e
${decode} < "$out" > "$tmpfile"
if [ $? -ne 0 ] || [ ! -s "$tmpfile" ]; then
echo 'Failed to decode patch with command "'${lib.escapeShellArg decode}'"' >&2
echo 'Fetched file was (limited to 128 bytes):' >&2
od -A x -t x1z -v -N 128 "$out" >&2
exit 1
fi
set -e
mv "$tmpfile" "$out"
"${patchutils}/bin/lsdiff" \
${lib.optionalString (relative != null) "-p1 -i ${lib.escapeShellArg relative}/'*'"} \
"$out" \
@ -76,5 +88,6 @@ fetchurl ({
mv "$tmpfile" "$out"
'' + postFetch;
} // builtins.removeAttrs args [
"relative" "stripLen" "extraPrefix" "excludes" "includes" "revert" "postFetch"
"relative" "stripLen" "decode" "extraPrefix" "excludes" "includes" "revert"
"postFetch"
])