python311Packages.moto: 4.2.6 -> 4.2.10
[NixPkgs.git] / pkgs / build-support / fetchsvn / nix-prefetch-svn
blob03b9eb9a03dfd15ebafa6561a80205dd90e51148
1 #! /bin/sh -e
3 url=$1
4 rev=$2
5 expHash=$3
7 hashType=$NIX_HASH_ALGO
8 if test -z "$hashType"; then
9 hashType=sha256
11 if test -z "$hashFormat"; then
12 hashFormat=--base32
15 if test -z "$url"; then
16 echo "syntax: nix-prefetch-svn URL [REVISION [EXPECTED-HASH]]" >&2
17 exit 1
20 test -n "$rev" || rev="HEAD"
22 repoName=$(echo $url | sed '
23 s,.*/\([^/]\+\)/trunk/*$,\1,;t
24 s,.*/\([^/]\+\)/branches/\([^/]\+\)/*$,\1-\2,;t
25 s,.*/\([^/]\+\)/tags/\([^/]\+\)/*$,\1-\2,;t
26 s,.*/\([^/]\+\)/*$,\1,;t
28 dstFile=$repoName-r$rev
30 # If the hash was given, a file with that hash may already be in the
31 # store.
32 if test -n "$expHash"; then
33 finalPath=$(nix-store --print-fixed-path --recursive "$hashType" "$expHash" $dstFile)
34 if ! nix-store --check-validity "$finalPath" 2> /dev/null; then
35 finalPath=
37 hash=$expHash
41 # If we don't know the hash or a path with that hash doesn't exist,
42 # download the file and add it to the store.
43 if test -z "$finalPath"; then
44 tmpPath="$(mktemp -d "${TMPDIR:-/tmp}/svn-checkout-tmp-XXXXXXXX")"
45 trap "rm -rf \"$tmpPath\"" EXIT
47 tmpFile="$tmpPath/$dstFile"
49 # Perform the checkout.
50 if test "$NIX_PREFETCH_SVN_LEAVE_DOT_SVN" != 1
51 then
52 command="export"
53 else
54 command="checkout"
57 echo p | svn "$command" --quiet -r "$rev" "$url" "$tmpFile" >&2
58 echo "svn revision is $(svn info -r "$rev" "$url" | grep "Revision: " | cut -d' ' -f2)"
60 # Compute the hash.
61 hash=$(nix-hash --type $hashType $hashFormat $tmpFile)
62 if ! test -n "$QUIET"; then echo "hash is $hash" >&2; fi
64 # Add the downloaded file to the Nix store.
65 finalPath=$(nix-store --add-fixed --recursive "$hashType" $tmpFile)
67 if test -n "$expHash" -a "$expHash" != "$hash"; then
68 echo "hash mismatch for URL \`$url'"
69 exit 1
73 if ! test -n "$QUIET"; then echo "path is $finalPath" >&2; fi
75 echo $hash
77 if test -n "$PRINT_PATH"; then
78 echo $finalPath