8025796: hgforest.sh could trigger unbuffered output from hg without complicated machinations

Fri, 11 Oct 2013 15:20:13 -0700

author
mduigou
date
Fri, 11 Oct 2013 15:20:13 -0700
changeset 845
3f9873789d44
parent 844
fd3b32cc4b6e
child 846
d35943431696

8025796: hgforest.sh could trigger unbuffered output from hg without complicated machinations
Reviewed-by: mduigou
Contributed-by: Dmitry Samersoff <dmitry.samersoff@oracle.com>

common/bin/hgforest.sh file | annotate | diff | comparison | revisions
     1.1 --- a/common/bin/hgforest.sh	Thu Oct 10 21:22:46 2013 -0700
     1.2 +++ b/common/bin/hgforest.sh	Fri Oct 11 15:20:13 2013 -0700
     1.3 @@ -1,7 +1,7 @@
     1.4  #!/bin/sh
     1.5  
     1.6  #
     1.7 -# Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
     1.8 +# Copyright (c) 2009, 2013, 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 @@ -27,37 +27,11 @@
    1.13  command="$1"
    1.14  pull_extra_base="$2"
    1.15  
    1.16 -# Python always buffers stdout significantly, thus we will not see any output from hg clone jdk,
    1.17 -# until a lot of time has passed! By passing -u to python, we get incremental updates
    1.18 -# on stdout. Much nicer.
    1.19 -whichhg="`which hg 2> /dev/null | grep -v '^no hg in'`"
    1.20 -
    1.21 -if [ "${whichhg}" = "" ] ; then
    1.22 -  echo Cannot find hg!
    1.23 -  exit 1
    1.24 -fi
    1.25 -
    1.26  if [ "" = "$command" ] ; then
    1.27    echo No command to hg supplied!
    1.28    exit 1
    1.29  fi
    1.30  
    1.31 -has_hash_bang="`head -n 1 "${whichhg}" | cut -b 1-2`"
    1.32 -python=""
    1.33 -bpython=""
    1.34 -
    1.35 -if [ "#!" = "$has_hash_bang" ] ; then
    1.36 -   python="`head -n 1 ${whichhg} | cut -b 3- | sed -e 's/^[ \t]*//;s/[ \t]*$//'`"
    1.37 -   bpython="`basename "$python"`"
    1.38 -fi
    1.39 -
    1.40 -if [ -x "$python" -a ! -d "$python" -a "`${python} -V 2>&1 | cut -f 1 -d ' '`" = "Python" ] ; then
    1.41 -  hg="${python} -u ${whichhg}"
    1.42 -else
    1.43 -  echo Cannot find python from hg launcher. Running plain hg, which probably has buffered stdout.
    1.44 -  hg="hg"
    1.45 -fi
    1.46 -
    1.47  # Clean out the temporary directory that stores the pid files.
    1.48  tmp=/tmp/forest.$$
    1.49  rm -f -r ${tmp}
    1.50 @@ -171,7 +145,7 @@
    1.51      (
    1.52        if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then
    1.53          pull_newrepo="`echo ${pull_base}/${i} | sed -e 's@\([^:]/\)//*@\1@g'`"
    1.54 -        echo ${hg} clone ${pull_newrepo} ${i}
    1.55 +        echo hg clone ${pull_newrepo} ${i}
    1.56          path="`dirname ${i}`"
    1.57          if [ "${path}" != "." ] ; then
    1.58            times=0
    1.59 @@ -184,10 +158,10 @@
    1.60              sleep 5
    1.61            done
    1.62          fi
    1.63 -        (${hg} clone ${pull_newrepo} ${i}; echo "$?" > ${tmp}/${repopidfile}.pid.rc )&
    1.64 +        (PYTHONUNBUFFERED=true hg clone ${pull_newrepo} ${i}; echo "$?" > ${tmp}/${repopidfile}.pid.rc )&
    1.65        else
    1.66 -        echo "cd ${i} && ${hg} $*"
    1.67 -        cd ${i} && (${hg} "$@"; echo "$?" > ${tmp}/${repopidfile}.pid.rc )&
    1.68 +        echo "cd ${i} && hg $*"
    1.69 +        cd ${i} && (PYTHONUNBUFFERED=true hg "$@"; echo "$?" > ${tmp}/${repopidfile}.pid.rc )&
    1.70        fi
    1.71        echo $! > ${tmp}/${repopidfile}.pid
    1.72      ) 2>&1 | sed -e "s@^@${reponame}:   @") &

mercurial