common/bin/hgforest.sh
author sgabdura
Mon, 17 Nov 2014 13:11:37 +0100
changeset 27790 2fcd7b664d99
parent 26118 dd063cd6c737
child 28009 987f121a835f
permissions -rw-r--r--
8048050: Agent NullPointerException when rmi.port in use Reviewed-by: jbachorik, dfuchs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23427
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
     1
#!/bin/sh
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
     2
#
22712
489b8278503c 8034146: Update hgforest.sh for new closed tree
iris
parents: 21173
diff changeset
     3
# Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
     4
# 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
     5
#
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
     6
# 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
     7
# 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
     8
# published by the Free Software Foundation.
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
     9
#
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    10
# 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
    11
# 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
    12
# 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
    13
# 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
    14
# accompanied this code).
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    15
#
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    16
# 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
    17
# 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
    18
# 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
    19
#
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    20
# 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
    21
# 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
    22
# questions.
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    23
#
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    24
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    25
# Shell script for a fast parallel forest/trees command
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    26
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    27
usage() {
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    28
      echo "usage: $0 [-h|--help] [-q|--quiet] [-v|--verbose] [-s|--sequential] [--] <command> [commands...]" > ${status_output}
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    29
      echo "Environment variables which modify behaviour:"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    30
      echo "   HGFOREST_QUIET      : (boolean) If 'true' then standard output is redirected to /dev/null"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    31
      echo "   HGFOREST_VERBOSE    : (boolean) If 'true' then Mercurial asked to produce verbose output"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    32
      echo "   HGFOREST_SEQUENTIAL : (boolean) If 'true' then repos are processed sequentially. Disables concurrency"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    33
      echo "   HGFOREST_GLOBALOPTS : (string, must begin with space) Additional Mercurial global options"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    34
      echo "   HGFOREST_REDIRECT   : (file path) Redirect standard output to specified file"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    35
      echo "   HGFOREST_FIFOS      : (boolean) Default behaviour for FIFO detection. Does not override FIFOs disabled"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    36
      echo "   HGFOREST_CONCURRENCY: (positive integer) Number of repos to process concurrently"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    37
      echo "   HGFOREST_DEBUG      : (boolean) If 'true' then temp files are retained"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    38
      exit 1
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    39
}
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    40
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    41
global_opts="${HGFOREST_GLOBALOPTS:-}"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    42
status_output="${HGFOREST_REDIRECT:-/dev/stdout}"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    43
qflag="${HGFOREST_QUIET:-false}"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    44
vflag="${HGFOREST_VERBOSE:-false}"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    45
sflag="${HGFOREST_SEQUENTIAL:-false}"
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    46
while [ $# -gt 0 ]
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    47
do
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    48
  case $1 in
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    49
    -h | --help )
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    50
      usage
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    51
      ;;
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    52
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    53
    -q | --quiet )
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    54
      qflag="true"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    55
      ;;
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    56
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    57
    -v | --verbose )
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    58
      vflag="true"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    59
      ;;
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    60
23436
90d12e975106 8039990: Add sequential operation support to hgforest
chegar
parents: 23427
diff changeset
    61
    -s | --sequential )
90d12e975106 8039990: Add sequential operation support to hgforest
chegar
parents: 23427
diff changeset
    62
      sflag="true"
90d12e975106 8039990: Add sequential operation support to hgforest
chegar
parents: 23427
diff changeset
    63
      ;;
90d12e975106 8039990: Add sequential operation support to hgforest
chegar
parents: 23427
diff changeset
    64
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    65
    '--' ) # no more options
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    66
      shift; break
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    67
      ;;
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    68
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    69
    -*)  # bad option
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    70
      usage
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    71
      ;;
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    72
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    73
     * )  # non option
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    74
      break
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    75
      ;;
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    76
  esac
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    77
  shift
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    78
done
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    79
26118
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
    80
# debug mode
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
    81
if [ "${HGFOREST_DEBUG:-false}" = "true" ] ; then
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
    82
  global_opts="${global_opts} --debug"
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
    83
fi
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
    84
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    85
# silence standard output?
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    86
if [ ${qflag} = "true" ] ; then
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    87
  global_opts="${global_opts} -q"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    88
  status_output="/dev/null"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    89
fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    90
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    91
# verbose output?
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    92
if [ ${vflag} = "true" ] ; then
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    93
  global_opts="${global_opts} -v"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    94
fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    95
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    96
# Make sure we have a command.
26118
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
    97
if [ ${#} -lt 1 -o -z "${1:-}" ] ; then
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
    98
  echo "ERROR: No command to hg supplied!" > ${status_output}
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
    99
  usage > ${status_output}
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   100
fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   101
26118
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   102
# grab command
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   103
command="${1}"; shift
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   104
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   105
if [ ${vflag} = "true" ] ; then
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   106
  echo "# Mercurial command: ${command}" > ${status_output}
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   107
fi
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   108
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   109
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   110
# capture command options and arguments (if any)
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   111
command_args="${@:-}"
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   112
26118
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   113
if [ ${vflag} = "true" ] ; then
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   114
  echo "# Mercurial command arguments: ${command_args}" > ${status_output}
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   115
fi
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   116
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   117
# 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
   118
tmp=/tmp/forest.$$
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   119
rm -f -r ${tmp}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   120
mkdir -p ${tmp}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   121
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   122
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   123
if [ "${HGFOREST_DEBUG:-false}" = "true" ] ; then
26118
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   124
  # ignores redirection.
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   125
  echo "DEBUG: temp files are in: ${tmp}" >&2
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   126
fi
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   127
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   128
# Check if we can use fifos for monitoring sub-process completion.
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   129
echo "1" > ${tmp}/read
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   130
while_subshell=1
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   131
while read line; do
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   132
  while_subshell=0
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   133
  break;
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   134
done < ${tmp}/read
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   135
rm ${tmp}/read
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   136
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   137
on_windows=`uname -s | egrep -ic -e 'cygwin|msys'`
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   138
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   139
if [ ${while_subshell} = "1" -o ${on_windows} = "1" ]; then
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   140
  # cygwin has (2014-04-18) broken (single writer only) FIFOs
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   141
  # msys has (2014-04-18) no FIFOs.
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   142
  # older shells create a sub-shell for redirect to while
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   143
  have_fifos="false"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   144
else
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   145
  have_fifos="${HGFOREST_FIFOS:-true}"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   146
fi
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   147
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   148
safe_interrupt () {
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   149
  if [ -d ${tmp} ]; then
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   150
    if [ "`ls ${tmp}/*.pid`" != "" ]; then
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   151
      echo "Waiting for processes ( `cat ${tmp}/.*.pid ${tmp}/*.pid 2> /dev/null | tr '\n' ' '`) to terminate nicely!" > ${status_output}
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   152
      sleep 1
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   153
      # 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
   154
      # a subprocess that has already exited.
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   155
      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
   156
      wait
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   157
      echo "Interrupt complete!" > ${status_output}
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   158
    fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   159
    rm -f -r ${tmp}
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   160
  fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   161
  exit 130
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   162
}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   163
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   164
nice_exit () {
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   165
  if [ -d ${tmp} ]; then
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   166
    if [ "`ls -A ${tmp} 2> /dev/null`" != "" ]; then
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   167
      wait
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   168
    fi
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   169
    if [ "${HGFOREST_DEBUG:-false}" != "true" ] ; then
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   170
      rm -f -r ${tmp}
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   171
    fi
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   172
  fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   173
}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   174
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   175
trap 'safe_interrupt' INT QUIT
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   176
trap 'nice_exit' EXIT
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   177
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   178
subrepos="corba jaxp jaxws langtools jdk hotspot nashorn"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   179
subrepos_extra="closed jdk/src/closed jdk/make/closed jdk/test/closed hotspot/make/closed hotspot/src/closed hotspot/test/closed deploy install sponsors pubs"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   180
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   181
# 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
   182
pull_default=""
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   183
repos=""
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   184
repos_extra=""
23427
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   185
if [ "${command}" = "clone" -o "${command}" = "fclone" -o "${command}" = "tclone" ] ; then
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   186
  # we must be a clone
23427
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   187
  if [ ! -f .hg/hgrc ] ; then
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   188
    echo "ERROR: Need initial repository to use this script" > ${status_output}
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   189
    exit 1
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   190
  fi
23427
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   191
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   192
  # the clone must know where it came from (have a default pull path).
23427
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   193
  pull_default=`hg paths default`
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   194
  if [ "${pull_default}" = "" ] ; then
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   195
    echo "ERROR: Need initial clone with 'hg paths default' defined" > ${status_output}
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   196
    exit 1
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   197
  fi
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   198
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   199
  # determine which sub repos need to be cloned.
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   200
  for i in ${subrepos} ; do
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   201
    if [ ! -f ${i}/.hg/hgrc ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   202
      repos="${repos} ${i}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   203
    fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   204
  done
24233
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   205
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   206
  pull_default_tail=`echo ${pull_default} | sed -e 's@^.*://[^/]*/\(.*\)@\1@'`
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   207
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   208
  if [ -n "${command_args}" ] ; then
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   209
    # if there is an "extra sources" path then reparent "extra" repos to that path
23427
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   210
    if [ "x${pull_default}" = "x${pull_default_tail}" ] ; then
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   211
      echo "ERROR: Need initial clone from non-local source" > ${status_output}
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   212
      exit 1
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   213
    fi
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   214
    pull_extra="${command_args}/${pull_default_tail}"
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   215
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   216
    # determine which extra subrepos need to be cloned.
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   217
    for i in ${subrepos_extra} ; do
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   218
      if [ ! -f ${i}/.hg/hgrc ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   219
        repos_extra="${repos_extra} ${i}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   220
      fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   221
    done
24233
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   222
  else
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   223
    if [ "x${pull_default}" = "x${pull_default_tail}" ] ; then
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   224
      # local source repo. Clone the "extra" subrepos that exist there.
24233
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   225
      for i in ${subrepos_extra} ; do
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   226
        if [ -f ${pull_default}/${i}/.hg/hgrc -a ! -f ${i}/.hg/hgrc ] ; then
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   227
          # sub-repo there in source but not here
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   228
          repos_extra="${repos_extra} ${i}"
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   229
        fi
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   230
      done
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   231
    fi
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   232
  fi
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   233
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   234
  # Any repos to deal with?
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   235
  if [ "${repos}" = "" -a "${repos_extra}" = "" ] ; then
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   236
    echo "No repositories to process." > ${status_output}
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   237
    exit
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   238
  fi
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   239
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   240
  # Repos to process concurrently. Clone does better with low concurrency.
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   241
  at_a_time="${HGFOREST_CONCURRENCY:-2}"
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   242
else
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   243
  # Process command for all of the present repos
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   244
  for i in . ${subrepos} ${subrepos_extra} ; do
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   245
    if [ -d ${i}/.hg ] ; then
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   246
      repos="${repos} ${i}"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   247
    fi
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   248
  done
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   249
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   250
  # Any repos to deal with?
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   251
  if [ "${repos}" = "" ] ; then
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   252
    echo "No repositories to process." > ${status_output}
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   253
    exit
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   254
  fi
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   255
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   256
  # any of the repos locked?
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   257
  locked=""
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   258
  for i in ${repos} ; do
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   259
    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
   260
      locked="${i} ${locked}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   261
    fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   262
  done
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   263
  if [ "${locked}" != "" ] ; then
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   264
    echo "ERROR: These repositories are locked: ${locked}" > ${status_output}
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   265
    exit 1
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   266
  fi
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   267
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   268
  # Repos to process concurrently.
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   269
  at_a_time="${HGFOREST_CONCURRENCY:-8}"
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   270
fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   271
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   272
# Echo out what repositories we do a command on.
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   273
echo "# Repositories: ${repos} ${repos_extra}" > ${status_output}
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   274
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   275
if [ "${command}" = "serve" ] ; then
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   276
  # "serve" is run for all the repos as one command.
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   277
  (
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   278
    (
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   279
      cwd=`pwd`
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   280
      serving=`basename ${cwd}`
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   281
      (
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   282
        echo "[web]"
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   283
        echo "description = ${serving}"
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   284
        echo "allow_push = *"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   285
        echo "push_ssl = False"
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   286
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   287
        echo "[paths]"
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   288
        for i in ${repos} ; do
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   289
          if [ "${i}" != "." ] ; then
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   290
            echo "/${serving}/${i} = ${i}"
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   291
          else
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   292
            echo "/${serving} = ${cwd}"
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   293
          fi
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   294
        done
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   295
      ) > ${tmp}/serve.web-conf
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   296
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   297
      echo "serving root repo ${serving}" > ${status_output}
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   298
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   299
      echo "hg${global_opts} serve" > ${status_output}
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   300
      (PYTHONUNBUFFERED=true hg${global_opts} serve -A ${status_output} -E ${status_output} --pid-file ${tmp}/serve.pid --web-conf ${tmp}/serve.web-conf; echo "$?" > ${tmp}/serve.pid.rc ) 2>&1 &
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   301
    ) 2>&1 | sed -e "s@^@serve:   @" > ${status_output}
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   302
  ) &
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   303
else
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   304
  # Run the supplied command on all repos in parallel.
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   305
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   306
  # n is the number of subprocess started or which might still be running.
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   307
  n=0
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   308
  if [ ${have_fifos} = "true" ]; then
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   309
    # if we have fifos use them to detect command completion.
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   310
    mkfifo ${tmp}/fifo
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   311
    exec 3<>${tmp}/fifo
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   312
  fi
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   313
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   314
  # iterate over all of the subrepos.
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   315
  for i in ${repos} ${repos_extra} ; do
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   316
    n=`expr ${n} '+' 1`
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   317
    repopidfile=`echo ${i} | sed -e 's@./@@' -e 's@/@_@g'`
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   318
    reponame=`echo ${i} | sed -e :a -e 's/^.\{1,20\}$/ &/;ta'`
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   319
    pull_base="${pull_default}"
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   320
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   321
    # regular repo or "extra" repo?
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   322
    for j in ${repos_extra} ; do
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   323
      if [ "${i}" = "${j}" ] ; then
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   324
        # it's an "extra"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   325
        pull_base="${pull_extra}"
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   326
      fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   327
    done
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   328
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   329
    # remove trailing slash
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   330
    pull_base="`echo ${pull_base} | sed -e 's@[/]*$@@'`"
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   331
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   332
    # execute the command on the subrepo
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   333
    (
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   334
      (
23427
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   335
        if [ "${command}" = "clone" -o "${command}" = "fclone" -o "${command}" = "tclone" ] ; then
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   336
          # some form of clone
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   337
          clone_newrepo="${pull_base}/${i}"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   338
          parent_path="`dirname ${i}`"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   339
          if [ "${parent_path}" != "." ] ; then
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   340
            times=0
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   341
            while [ ! -d "${parent_path}" ] ; do  ## nested repo, ensure containing dir exists
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   342
              if [ "${sflag}" = "true" ] ; then
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   343
                # Missing parent is fatal during sequential operation.
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   344
                echo "ERROR: Missing parent path: ${parent_path}" > ${status_output}
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   345
                exit 1
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   346
              fi
24306
6d8861ac0307 8043182: hgforest.sh: syntax error on line 329
mduigou
parents: 24305
diff changeset
   347
              times=`expr ${times} '+' 1`
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   348
              if [ `expr ${times} '%' 10` -eq 0 ] ; then
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   349
                echo "${parent_path} still not created, waiting..." > ${status_output}
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   350
              fi
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   351
              sleep 5
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   352
            done
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   353
          fi
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   354
          # run the clone command.
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   355
          echo "hg${global_opts} clone ${clone_newrepo} ${i}" > ${status_output}
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   356
          (PYTHONUNBUFFERED=true hg${global_opts} clone ${clone_newrepo} ${i}; echo "$?" > ${tmp}/${repopidfile}.pid.rc ) 2>&1 &
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   357
        else
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   358
          # run the command.
23427
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   359
          echo "cd ${i} && hg${global_opts} ${command} ${command_args}" > ${status_output}
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   360
          cd ${i} && (PYTHONUNBUFFERED=true hg${global_opts} ${command} ${command_args}; echo "$?" > ${tmp}/${repopidfile}.pid.rc ) 2>&1 &
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   361
        fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   362
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   363
        echo $! > ${tmp}/${repopidfile}.pid
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   364
      ) 2>&1 | sed -e "s@^@${reponame}:   @" > ${status_output}
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   365
      # tell the fifo waiter that this subprocess is done.
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   366
      if [ ${have_fifos} = "true" ]; then
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   367
        echo "${i}" >&3
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   368
      fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   369
    ) &
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   370
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   371
    if [ "${sflag}" = "true" ] ; then
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   372
      # complete this task before starting another.
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   373
      wait
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   374
    else
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   375
      if [ "${have_fifos}" = "true" ]; then
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   376
        # check on count of running subprocesses and possibly wait for completion
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   377
        if [ ${n} -ge ${at_a_time} ] ; then
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   378
          # read will block until there are completed subprocesses
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   379
          while read repo_done; do
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   380
            n=`expr ${n} '-' 1`
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   381
            if [ ${n} -lt ${at_a_time} ] ; then
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   382
              # we should start more subprocesses
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   383
              break;
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   384
            fi
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   385
          done <&3
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   386
        fi
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   387
      else
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   388
        # Compare completions to starts
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   389
        completed="`(ls -a1 ${tmp}/*.pid.rc 2> /dev/null | wc -l) || echo 0`"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   390
        while [ `expr ${n} '-' ${completed}` -ge ${at_a_time} ] ; do
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   391
          # sleep a short time to give time for something to complete
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   392
          sleep 1
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   393
          completed="`(ls -a1 ${tmp}/*.pid.rc 2> /dev/null | wc -l) || echo 0`"
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   394
        done
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   395
      fi
23436
90d12e975106 8039990: Add sequential operation support to hgforest
chegar
parents: 23427
diff changeset
   396
    fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   397
  done
26118
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   398
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   399
  if [ ${have_fifos} = "true" ]; then
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   400
    # done with the fifo
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   401
    exec 3>&-
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   402
  fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   403
fi
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   404
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   405
# Wait for all subprocesses to complete
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   406
wait
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   407
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   408
# Terminate with exit 0 only if all subprocesses were successful
26118
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   409
# Terminate with highest exit code of subprocesses
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   410
ec=0
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   411
if [ -d ${tmp} ]; then
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   412
  rcfiles="`(ls -a ${tmp}/*.pid.rc 2> /dev/null) || echo ''`"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   413
  for rc in ${rcfiles} ; do
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   414
    exit_code=`cat ${rc} | tr -d ' \n\r'`
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   415
    if [ "${exit_code}" != "0" ] ; then
26118
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   416
      if [ ${exit_code} -gt 1 ]; then
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   417
        # mercurial exit codes greater than "1" signal errors.
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   418
      repo="`echo ${rc} | sed -e 's@^'${tmp}'@@' -e 's@/*\([^/]*\)\.pid\.rc$@\1@' -e 's@_@/@g'`"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   419
      echo "WARNING: ${repo} exited abnormally (${exit_code})" > ${status_output}
26118
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   420
      fi
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   421
      if [ ${exit_code} -gt ${ec} ]; then
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   422
        # assume that larger exit codes are more significant
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   423
        ec=${exit_code}
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   424
      fi
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   425
    fi
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   426
  done
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   427
fi
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   428
exit ${ec}