1.1 --- a/get_source.sh Mon Oct 20 23:00:27 2014 -0700 1.2 +++ b/get_source.sh Fri Oct 24 17:04:51 2014 -0700 1.3 @@ -1,7 +1,7 @@ 1.4 #!/bin/sh 1.5 1.6 # 1.7 -# Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. 1.8 +# Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. 1.9 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.10 # 1.11 # This code is free software; you can redistribute it and/or modify it 1.12 @@ -25,9 +25,76 @@ 1.13 # questions. 1.14 # 1.15 1.16 -# Get clones of all nested repositories 1.17 -sh ./common/bin/hgforest.sh clone "$@" || exit 1 1.18 +to_stderr() { 1.19 + echo "$@" >&2 1.20 +} 1.21 + 1.22 +error() { 1.23 + to_stderr "ERROR: $1" 1.24 + exit ${2:-126} 1.25 +} 1.26 + 1.27 +warning() { 1.28 + to_stderr "WARNING: $1" 1.29 +} 1.30 + 1.31 +version_field() { 1.32 + # rev is typically omitted for minor and major releases 1.33 + field=`echo ${1}.0 | cut -f ${2} -d .` 1.34 + if expr 1 + $field >/dev/null 2> /dev/null; then 1.35 + echo $field 1.36 + else 1.37 + echo -1 1.38 + fi 1.39 +} 1.40 + 1.41 +# Version check 1.42 + 1.43 +# required 1.44 +reqdmajor=1 1.45 +reqdminor=4 1.46 +reqdrev=0 1.47 + 1.48 +# requested 1.49 +rqstmajor=2 1.50 +rqstminor=6 1.51 +rqstrev=3 1.52 + 1.53 + 1.54 +# installed 1.55 +hgwhere="`command -v hg`" 1.56 +if [ "x$hgwhere" = "x" ]; then 1.57 + error "Could not locate Mercurial command" 1.58 +fi 1.59 + 1.60 +hgversion="`hg --version 2> /dev/null | sed -n -e 's@^Mercurial Distributed SCM (version \([^+]*\).*)\$@\1@p'`" 1.61 +if [ "x${hgversion}" = "x" ] ; then 1.62 + error "Could not determine Mercurial version of $hgwhere" 1.63 +fi 1.64 + 1.65 +hgmajor="`version_field $hgversion 1`" 1.66 +hgminor="`version_field $hgversion 2`" 1.67 +hgrev="`version_field $hgversion 3`" 1.68 + 1.69 +if [ $hgmajor -eq -1 -o $hgminor -eq -1 -o $hgrev -eq -1 ] ; then 1.70 + error "Could not determine Mercurial version of $hgwhere from \"$hgversion\"" 1.71 +fi 1.72 + 1.73 + 1.74 +# Require 1.75 +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.76 + error "Mercurial version $reqdmajor.$reqdminor.$reqdrev or later is required. $hgwhere is version $hgversion" 1.77 +fi 1.78 + 1.79 + 1.80 +# Request 1.81 +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.82 + warning "Mercurial version $rqstmajor.$rqstminor.$rqstrev or later is recommended. $hgwhere is version $hgversion" 1.83 +fi 1.84 + 1.85 + 1.86 +# Get clones of all absent nested repositories (harmless if already exist) 1.87 +sh ./common/bin/hgforest.sh clone "$@" || exit $? 1.88 1.89 # Update all existing repositories to the latest sources 1.90 sh ./common/bin/hgforest.sh pull -u 1.91 -