hg 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env bash
  2. # We want to catch any unexpected failure, and exit immediately
  3. set -e
  4. # Download helper for hg, to be called from the download wrapper script
  5. #
  6. # Options:
  7. # -q Be quiet.
  8. # -o FILE Generate archive in FILE.
  9. # -u URI Clone from repository at URI.
  10. # -c CSET Use changeset (or revision) CSET.
  11. # -n NAME Use basename NAME.
  12. #
  13. # Environment:
  14. # HG : the hg command to call
  15. quiet=
  16. while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
  17. case "${OPT}" in
  18. q) quiet=-q;;
  19. o) output="${OPTARG}";;
  20. u) uri="${OPTARG}";;
  21. c) cset="${OPTARG}";;
  22. n) basename="${OPTARG}";;
  23. :) printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
  24. \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
  25. esac
  26. done
  27. shift $((OPTIND-1)) # Get rid of our options
  28. # Caller needs to single-quote its arguments to prevent them from
  29. # being expanded a second time (in case there are spaces in them)
  30. _hg() {
  31. if [ -z "${quiet}" ]; then
  32. printf '%s ' ${HG} "${@}"; printf '\n'
  33. fi
  34. eval ${HG} "${@}"
  35. }
  36. _hg clone ${quiet} "${@}" --noupdate "'${uri}'" "'${basename}'"
  37. _hg archive ${quiet} --repository "'${basename}'" --type tgz \
  38. --prefix "'${basename}'" --rev "'${cset}'" \
  39. - >"${output}"