8 hashType
="${NIX_HASH_ALGO:-sha256}"
9 hashFormat
=${hashFormat:-"--base32"}
21 if [[ -z "$url" ||
"$url" == "--help" ]]; then
22 die
"Usage: nix-prefetch-hg URL [rev [EXPECTED-HASH]]"
25 if [[ "${fetchSubrepos:-0}" == 1 ]]; then
31 # If the hash was given, a file with that hash may already be in the
33 if [[ -n "$expHash" ]]; then
34 finalPath
=$
(nix-store
--print-fixed-path --recursive "$hashType" "$expHash" hg-archive
)
35 if ! nix-store
--check-validity "$finalPath" 2> /dev
/null
; then
42 # If we don't know the hash or a path with that hash doesn't exist,
43 # download the file and add it to the store.
44 if [[ -z "$finalPath" ]]; then
46 tmpPath
="$(mktemp -d "${TMPDIR:-/tmp}/hg-checkout-tmp-XXXXXXXX
")"
47 cleanup
() { x
=$?
; rm -rf "$tmpPath"; exit $x; }; trap cleanup EXIT
49 tmpArchive
="$tmpPath/hg-archive"
51 # Perform the checkout.
52 if [[ "$url" != /* ]]; then
53 tmpClone
="$tmpPath/hg-clone"
54 hg clone
-q -y -U "$url" "$tmpClone" >&2
58 hg archive
-q$subrepoClause -y -r "$rev" --cwd "$tmpClone" "$tmpArchive"
59 rm -f "$tmpArchive/.hg_archival.txt"
61 LOG
"hg revision is $(cd "$tmpClone"; hg id -r "$rev" -i)"
64 hash=$
(nix-hash
--type "$hashType" "$hashFormat" "$tmpArchive")
65 if [[ -z "$QUIET" ]]; then LOG
"hash is $hash"; fi
67 # Add the downloaded file to the Nix store.
68 finalPath
=$
(nix-store
--add-fixed --recursive "$hashType" "$tmpArchive")
70 if [[ -n "$expHash" && "$expHash" != "$hash" ]]; then
71 die
"ERROR: hash mismatch for URL \`$url'"
77 if [[ -z "$QUIET" ]]; then LOG
"path is $finalPath"; fi
81 if [[ -n "$PRINT_PATH" ]]; then