Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

nix-prefetch-git: print out valid nix expression; make --quiet very quiet

+50 -10
+50 -10
pkgs/build-support/fetchgit/nix-prefetch-git
··· 12 12 builder= 13 13 branchName=$NIX_PREFETCH_GIT_BRANCH_NAME 14 14 15 + # populated by clone_user_rev() 16 + fullRev= 17 + humanReadableRev= 18 + commitDate= 19 + 15 20 if test -n "$deepClone"; then 16 21 deepClone=true 17 22 else ··· 255 260 } 256 261 257 262 258 - clone_user_rev() { 263 + _clone_user_rev() { 259 264 local dir="$1" 260 265 local url="$2" 261 266 local rev="${3:-HEAD}" ··· 273 278 fi;; 274 279 esac 275 280 276 - local full_revision=$(cd $dir && (git rev-parse $rev 2> /dev/null || git rev-parse refs/heads/$branchName) | tail -n1) 277 - echo "git revision is $full_revision" 278 - echo "git human-readable version is $(cd $dir && (git describe $full_revision 2> /dev/null || git describe --tags $full_revision 2> /dev/null || echo -- none --))" >&2 279 - echo "Commit date is $(cd $dir && git show --no-patch --pretty=%ci $full_revision)" 281 + fullRev="$(cd $dir && (git rev-parse $rev 2> /dev/null || git rev-parse refs/heads/$branchName) | tail -n1)" 282 + humanReadableRev="$(cd $dir && (git describe $fullRev 2> /dev/null || git describe --tags $fullRev 2> /dev/null || echo -- none --))" 283 + commitDate="$(cd $dir && git show --no-patch --pretty=%ci $fullRev)" 280 284 281 285 # Allow doing additional processing before .git removal 282 286 eval "$NIX_PREFETCH_GIT_CHECKOUT_HOOK" ··· 290 294 fi 291 295 } 292 296 297 + clone_user_rev() { 298 + if ! test -n "$QUIET"; then 299 + _clone_user_rev "$@" 300 + else 301 + errfile="$(mktemp "${TMPDIR:-/tmp}/git-checkout-err-XXXXXXXX")" 302 + trap "rm -rf \"$errfile\"" EXIT 303 + _clone_user_rev "$@" 2> "$errfile" || ( 304 + status="$?" 305 + cat "$errfile" >&2 306 + exit "$status" 307 + ) 308 + fi 309 + } 310 + 311 + 312 + print_results() { 313 + hash="$1" 314 + if ! test -n "$QUIET"; then 315 + echo "" >&2 316 + echo "git revision is $fullRev" >&2 317 + if test -n "$finalPath"; then 318 + echo "path is $finalPath" >&2 319 + fi 320 + echo "git human-readable version is $humanReadableRev" >&2 321 + echo "Commit date is $commitDate" >&2 322 + if test -n "$hash"; then 323 + echo "hash is $hash" >&2 324 + fi 325 + fi 326 + if test -n "$hash"; then 327 + echo "{" 328 + echo " url = \"$url\";" 329 + echo " rev = \"$fullRev\";" 330 + echo " $hashType = \"$hash\";" 331 + echo "}" 332 + fi 333 + } 334 + 293 335 if test -z "$branchName"; then 294 336 branchName=fetchgit 295 337 fi ··· 328 370 329 371 # Compute the hash. 330 372 hash=$(nix-hash --type $hashType --base32 $tmpFile) 331 - if ! test -n "$QUIET"; then echo "hash is $hash" >&2; fi 332 373 333 374 # Add the downloaded file to the Nix store. 334 375 finalPath=$(nix-store --add-fixed --recursive "$hashType" "$tmpFile") 335 376 336 377 if test -n "$expHash" -a "$expHash" != "$hash"; then 337 - echo "hash mismatch for URL \`$url'" 378 + print_metadata 379 + echo "hash mismatch for URL \`$url'" >&2 338 380 exit 1 339 381 fi 340 382 fi 341 383 342 - if ! test -n "$QUIET"; then echo "path is $finalPath" >&2; fi 343 - 344 - echo $hash 384 + print_results "$hash" 345 385 346 386 if test -n "$PRINT_PATH"; then 347 387 echo $finalPath