get_source.sh

changeset 1147
ec58dd8b23b6
parent 1146
406ecd8cce66
child 1288
7801df19942d
child 1741
abafc84654a6
     1.1 --- a/get_source.sh	Tue Jun 24 15:21:47 2014 -0700
     1.2 +++ b/get_source.sh	Tue Jul 08 11:21:43 2014 -0700
     1.3 @@ -25,11 +25,34 @@
     1.4  # questions.
     1.5  #
     1.6  
     1.7 +to_stderr() {
     1.8 +    echo "$@" >&2
     1.9 +}
    1.10 +
    1.11 +error() {
    1.12 +    to_stderr "ERROR: $1"
    1.13 +    exit ${2:-126}
    1.14 +}
    1.15 +
    1.16 +warning() {
    1.17 +    to_stderr "WARNING: $1"
    1.18 +}
    1.19 +
    1.20 +version_field() {
    1.21 +  # rev is typically omitted for minor and major releases
    1.22 +  field=`echo ${1}.0 | cut -f ${2} -d .`
    1.23 +  if expr 1 + $field >/dev/null 2> /dev/null; then
    1.24 +    echo $field
    1.25 +  else
    1.26 +    echo -1
    1.27 +  fi
    1.28 +}
    1.29 +
    1.30  # Version check
    1.31  
    1.32  # required
    1.33  reqdmajor=1
    1.34 -reqdminor=5
    1.35 +reqdminor=4
    1.36  reqdrev=0
    1.37  
    1.38  # requested
    1.39 @@ -37,34 +60,39 @@
    1.40  rqstminor=6
    1.41  rqstrev=3
    1.42  
    1.43 +
    1.44  # installed
    1.45 -hgwhere="`which hg 2> /dev/null | grep -v '^no hg in '`"
    1.46 +hgwhere="`command -v hg`"
    1.47  if [ "x$hgwhere" = "x" ]; then
    1.48 -  echo "ERROR: Could not locate Mercurial command" >&2
    1.49 -  exit 126
    1.50 +  error "Could not locate Mercurial command"
    1.51  fi
    1.52  
    1.53 -hgversion="`hg --version 2> /dev/null | sed -n -e 's@^Mercurial Distributed SCM (version \(.*\))\$@\1@p'`"
    1.54 +hgversion="`hg --version 2> /dev/null | sed -n -e 's@^Mercurial Distributed SCM (version \([^+]*\).*)\$@\1@p'`"
    1.55  if [ "x${hgversion}" = "x" ] ; then
    1.56 -  echo "ERROR: Could not determine Mercurial version" >&2
    1.57 -  exit 126
    1.58 +  error "Could not determine Mercurial version of $hgwhere"
    1.59  fi
    1.60  
    1.61 -hgmajor="`echo $hgversion | cut -f 1 -d .`"
    1.62 -hgminor="`echo $hgversion | cut -f 2 -d .`"
    1.63 -hgrev="`echo $hgversion.0 | cut -f 3 -d .`" # rev is omitted for minor and major releases
    1.64 +hgmajor="`version_field $hgversion 1`"
    1.65 +hgminor="`version_field $hgversion 2`"
    1.66 +hgrev="`version_field $hgversion 3`"
    1.67 +
    1.68 +if [ $hgmajor -eq -1 -o $hgminor -eq -1 -o $hgrev -eq -1 ] ; then
    1.69 +  error "Could not determine Mercurial version of $hgwhere from \"$hgversion\""
    1.70 +fi
    1.71 +
    1.72  
    1.73  # Require
    1.74  if [ $hgmajor -lt $reqdmajor -o \( $hgmajor -eq $reqdmajor -a $hgminor -lt $reqdminor \) -o \( $hgmajor -eq $reqdmajor -a $hgminor -eq $reqdminor -a $hgrev -lt $reqdrev \) ] ; then
    1.75 -  echo "ERROR: Mercurial version $reqdmajor.$reqdminor.$reqdrev or later is required. $hgwhere is version $hgversion" >&2
    1.76 -  exit 126
    1.77 +  error "Mercurial version $reqdmajor.$reqdminor.$reqdrev or later is required. $hgwhere is version $hgversion"
    1.78  fi
    1.79  
    1.80 +
    1.81  # Request
    1.82  if [ $hgmajor -lt $rqstmajor -o \( $hgmajor -eq $rqstmajor -a $hgminor -lt $rqstminor \) -o \( $hgmajor -eq $rqstmajor -a $hgminor -eq $rqstminor -a $hgrev -lt $rqstrev \) ] ; then
    1.83 -  echo "WARNING: Mercurial version $rqstmajor.$rqstminor.$rqstrev or later is recommended. $hgwhere is version $hgversion" >&2
    1.84 +  warning "Mercurial version $rqstmajor.$rqstminor.$rqstrev or later is recommended. $hgwhere is version $hgversion"
    1.85  fi
    1.86  
    1.87 +
    1.88  # Get clones of all absent nested repositories (harmless if already exist)
    1.89  sh ./common/bin/hgforest.sh clone "$@" || exit $?
    1.90  

mercurial