Commit dd6e94f2 authored by Alyssa Ross's avatar Alyssa Ross
Browse files

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 = "https://chromium.googlesource.com/aosp/platform/external/libchrome/+/f37ae3b1a873d74182a2ac31d96742ead9c1f523^!?format=TEXT";
      decode = "base64 -d";
      sha256 = "11j1bqz2p8xrfzgfrylgdvmqs45489c4ckl7l0ra1dpfgbqy94a8";
    }
parent d4f33014
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -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"
])