changeset 25800:7b2312def76b

build: ensure hg commands are not affected by user settings * get-source-mtime.sh, mk-hg-id.sh (hg_safe): New shell function to call hg commands safely.
author Mike Miller <mtmiller@octave.org>
date Wed, 15 Aug 2018 13:03:29 -0700
parents d04b74f5d02e
children 95eb72d50fb0
files build-aux/get-source-mtime.sh build-aux/mk-hg-id.sh
diffstat 2 files changed, 22 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/build-aux/get-source-mtime.sh	Wed Aug 15 15:26:10 2018 -0400
+++ b/build-aux/get-source-mtime.sh	Wed Aug 15 13:03:29 2018 -0700
@@ -36,11 +36,21 @@
 
 srcdir="$1"
 
+## A user's ~/.hgrc may redefine or add default options to any hg subcommand,
+## potentially altering its behavior and possibly its standard output.  Always
+## run hg subcommands with configuration variables set to ensure that the
+## user's preferences do not influence the expected behavior.
+hg_safe ()
+{
+  cmd=$1; shift
+  hg --config alias.${cmd}=${cmd} --config defaults.${cmd}= ${cmd} "$@"
+}
+
 if [ x"$SOURCE_DATE_EPOCH" != x ]; then
   # Allow the source modification time to be overridden by SOURCE_DATE_EPOCH
   t=$SOURCE_DATE_EPOCH
 elif [ -d $srcdir/.hg ]; then
-  t=$( cd $srcdir && hg log --rev . --template '{date|hgdate}' )
+  t=$( cd $srcdir && hg_safe log --rev . --template '{date|hgdate}' )
   t=$( echo $t | $SED -n 's/^\([0-9]\+\) .*/\1/p' )
 elif [ -f $srcdir/HG-ID ]; then
   t=$( $PERL -e '@s = stat($ARGV[0]); print($s[9]) if @s;' $srcdir/HG-ID )
--- a/build-aux/mk-hg-id.sh	Wed Aug 15 15:26:10 2018 -0400
+++ b/build-aux/mk-hg-id.sh	Wed Aug 15 13:03:29 2018 -0700
@@ -34,11 +34,21 @@
 hg_id=HG-ID
 move_if_change="$srcdir/build-aux/move-if-change"
 
+## A user's ~/.hgrc may redefine or add default options to any hg subcommand,
+## potentially altering its behavior and possibly its standard output.  Always
+## run hg subcommands with configuration variables set to ensure that the
+## user's preferences do not influence the expected behavior.
+hg_safe ()
+{
+  cmd=$1; shift
+  hg --config alias.${cmd}=${cmd} --config defaults.${cmd}= ${cmd} "$@"
+}
+
 if [ $# -eq 2 ] && [ x"$2" = x--disable ]; then
   echo "hg-id-disabled" > ${hg_id}-t
   ${move_if_change} ${hg_id}-t ${hg_id}
 elif [ -d $srcdir/.hg ]; then
-  ( cd $srcdir && hg identify --id || echo "unknown" ) > ${hg_id}-t
+  ( cd $srcdir && hg_safe identify --id || echo "unknown" ) > ${hg_id}-t
   ${move_if_change} ${hg_id}-t ${hg_id}
 elif [ ! -f $srcdir/${hg_id} ]; then
   echo "WARNING: $srcdir/${hg_id} is missing!" 1>&2