common/bin/hgforest.sh
author joehw
Tue, 09 Jul 2013 16:34:52 -0700
changeset 18890 25bdeca3173b
parent 16658 e276f5dfe4b6
child 19752 935eac795255
child 21160 81fda7dbde35
permissions -rw-r--r--
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown Summary: jaxp 1.5 feature update Reviewed-by: alanb, dfuchs, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
     1
#!/bin/sh
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
     2
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
     3
#
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
     4
# Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
     5
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
     6
#
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
     7
# This code is free software; you can redistribute it and/or modify it
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
     8
# under the terms of the GNU General Public License version 2 only, as
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
     9
# published by the Free Software Foundation.
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    10
#
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    11
# This code is distributed in the hope that it will be useful, but WITHOUT
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    13
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    14
# version 2 for more details (a copy is included in the LICENSE file that
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    15
# accompanied this code).
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    16
#
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    17
# You should have received a copy of the GNU General Public License version
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    18
# 2 along with this work; if not, write to the Free Software Foundation,
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    19
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    20
#
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    21
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    22
# or visit www.oracle.com if you need additional information or have any
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    23
# questions.
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    24
#
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    25
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    26
# Shell script for a fast parallel forest command
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    27
command="$1"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    28
pull_extra_base="$2"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    29
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    30
# Python always buffers stdout significantly, thus we will not see any output from hg clone jdk,
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    31
# until a lot of time has passed! By passing -u to python, we get incremental updates
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    32
# on stdout. Much nicer.
16658
e276f5dfe4b6 8011350: hgforest.sh uses non-POSIX sh features that may fail with some shells
mduigou
parents: 16657
diff changeset
    33
whichhg="`which hg 2> /dev/null | grep -v '^no hg in'`"
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    34
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    35
if [ "${whichhg}" = "" ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    36
  echo Cannot find hg!
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    37
  exit 1
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    38
fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    39
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    40
if [ "" = "$command" ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    41
  echo No command to hg supplied!
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    42
  exit 1
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    43
fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    44
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    45
has_hash_bang="`head -n 1 "${whichhg}" | cut -b 1-2`"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    46
python=""
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    47
bpython=""
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    48
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    49
if [ "#!" = "$has_hash_bang" ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    50
   python="`head -n 1 ${whichhg} | cut -b 3-`"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    51
   bpython="`basename "$python"`"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    52
fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    53
16658
e276f5dfe4b6 8011350: hgforest.sh uses non-POSIX sh features that may fail with some shells
mduigou
parents: 16657
diff changeset
    54
if [ -x "$python" -a ! -d "$python" -a "`${python} -V 2>&1 | cut -f 1 -d ' '`" = "Python" ] ; then
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    55
  hg="${python} -u ${whichhg}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    56
else
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    57
  echo Cannot find python from hg launcher. Running plain hg, which probably has buffered stdout.
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    58
  hg="hg"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    59
fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    60
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    61
# Clean out the temporary directory that stores the pid files.
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    62
tmp=/tmp/forest.$$
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    63
rm -f -r ${tmp}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    64
mkdir -p ${tmp}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    65
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    66
safe_interrupt () {
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
    67
  if [ -d ${tmp} ]; then
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
    68
    if [ "`ls ${tmp}/*.pid`" != "" ]; then
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
    69
      echo "Waiting for processes ( `cat ${tmp}/*.pid | tr '\n' ' '`) to terminate nicely!"
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    70
      sleep 1
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    71
      # Pipe stderr to dev/null to silence kill, that complains when trying to kill
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    72
      # a subprocess that has already exited.
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
    73
      kill -TERM `cat ${tmp}/*.pid | tr '\n' ' '` 2> /dev/null
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
    74
      wait
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
    75
      echo Interrupt complete!
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
    76
    fi
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    77
  fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    78
  rm -f -r ${tmp}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    79
  exit 1
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    80
}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    81
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    82
nice_exit () {
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
    83
  if [ -d ${tmp} ]; then
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
    84
    if [ "`ls ${tmp}`" != "" ]; then
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
    85
      wait
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
    86
    fi
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    87
  fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    88
  rm -f -r ${tmp}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    89
}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    90
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    91
trap 'safe_interrupt' INT QUIT
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    92
trap 'nice_exit' EXIT
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
    93
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    94
# Only look in specific locations for possible forests (avoids long searches)
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    95
pull_default=""
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    96
repos=""
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    97
repos_extra=""
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    98
if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then
15903
bc0e6cd9d760 8008914: Add nashorn to the tl build
jjg
parents: 15575
diff changeset
    99
  subrepos="corba jaxp jaxws langtools jdk hotspot nashorn"
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   100
  if [ -f .hg/hgrc ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   101
    pull_default=`hg paths default`
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   102
    if [ "${pull_default}" = "" ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   103
      echo "ERROR: Need initial clone with 'hg paths default' defined"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   104
      exit 1
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   105
    fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   106
  fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   107
  if [ "${pull_default}" = "" ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   108
    echo "ERROR: Need initial repository to use this script"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   109
    exit 1
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   110
  fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   111
  for i in ${subrepos} ; do
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   112
    if [ ! -f ${i}/.hg/hgrc ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   113
      repos="${repos} ${i}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   114
    fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   115
  done
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   116
  if [ "${pull_extra_base}" != "" ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   117
    subrepos_extra="jdk/src/closed jdk/make/closed jdk/test/closed hotspot/make/closed hotspot/src/closed hotspot/test/closed deploy install sponsors pubs"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   118
    pull_default_tail=`echo ${pull_default} | sed -e 's@^.*://[^/]*/\(.*\)@\1@'`
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   119
    pull_extra="${pull_extra_base}/${pull_default_tail}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   120
    for i in ${subrepos_extra} ; do
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   121
      if [ ! -f ${i}/.hg/hgrc ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   122
        repos_extra="${repos_extra} ${i}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   123
      fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   124
    done
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   125
  fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   126
  at_a_time=2
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   127
  # Any repos to deal with?
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   128
  if [ "${repos}" = "" -a "${repos_extra}" = "" ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   129
    exit
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   130
  fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   131
else
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   132
  hgdirs=`ls -d ./.hg ./*/.hg ./*/*/.hg ./*/*/*/.hg ./*/*/*/*/.hg 2>/dev/null`
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   133
  # Derive repository names from the .hg directory locations
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   134
  for i in ${hgdirs} ; do
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   135
    repos="${repos} `echo ${i} | sed -e 's@/.hg$@@'`"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   136
  done
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   137
  for i in ${repos} ; do
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   138
    if [ -h ${i}/.hg/store/lock -o -f ${i}/.hg/store/lock ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   139
      locked="${i} ${locked}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   140
    fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   141
  done
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   142
  at_a_time=8
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   143
  # Any repos to deal with?
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   144
  if [ "${repos}" = "" ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   145
    echo "No repositories to process."
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   146
    exit
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   147
  fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   148
  if [ "${locked}" != "" ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   149
    echo "These repositories are locked: ${locked}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   150
    exit
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   151
  fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   152
fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   153
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   154
# Echo out what repositories we do a command on.
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   155
echo "# Repositories: ${repos} ${repos_extra}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   156
echo
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   157
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   158
# Run the supplied command on all repos in parallel.
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   159
n=0
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   160
for i in ${repos} ${repos_extra} ; do
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   161
  n=`expr ${n} '+' 1`
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   162
  repopidfile=`echo ${i} | sed -e 's@./@@' -e 's@/@_@g'`
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   163
  reponame=`echo ${i} | sed -e :a -e 's/^.\{1,20\}$/ &/;ta'`
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   164
  pull_base="${pull_default}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   165
  for j in $repos_extra ; do
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   166
      if [ "$i" = "$j" ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   167
          pull_base="${pull_extra}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   168
      fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   169
  done
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   170
  (
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   171
    (
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   172
      if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   173
        pull_newrepo="`echo ${pull_base}/${i} | sed -e 's@\([^:]/\)//*@\1@g'`"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   174
        echo ${hg} clone ${pull_newrepo} ${i}
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   175
        path="`dirname ${i}`"
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   176
        if [ "${path}" != "." ] ; then
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   177
          times=0
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   178
          while [ ! -d "${path}" ]   ## nested repo, ensure containing dir exists
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   179
          do
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   180
            times=`expr ${times} '+' 1`
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   181
            if [ `expr ${times} '%' 10` -eq 0 ] ; then
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   182
              echo ${path} still not created, waiting...
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   183
            fi
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   184
            sleep 5
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   185
          done
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   186
        fi
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   187
        (${hg} clone ${pull_newrepo} ${i}; echo "$?" > ${tmp}/${repopidfile}.pid.rc )&
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   188
      else
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   189
        echo "cd ${i} && ${hg} $*"
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   190
        cd ${i} && (${hg} "$@"; echo "$?" > ${tmp}/${repopidfile}.pid.rc )&
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   191
      fi
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   192
      echo $! > ${tmp}/${repopidfile}.pid
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   193
    ) 2>&1 | sed -e "s@^@${reponame}:   @") &
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   194
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   195
  if [ `expr ${n} '%' ${at_a_time}` -eq 0 ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   196
    sleep 2
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   197
    echo Waiting 5 secs before spawning next background command.
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   198
    sleep 3
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   199
  fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   200
done
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   201
# Wait for all hg commands to complete
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   202
wait
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   203
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   204
# Terminate with exit 0 only if all subprocesses were successful
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   205
ec=0
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   206
if [ -d ${tmp} ]; then
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   207
  for rc in ${tmp}/*.pid.rc ; do
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   208
    exit_code=`cat ${rc} | tr -d ' \n\r'`
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   209
    if [ "${exit_code}" != "0" ] ; then
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   210
      echo "WARNING: ${rc} exited abnormally."
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   211
      ec=1
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   212
    fi
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   213
  done
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   214
fi
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   215
exit ${ec}