common/bin/hgforest.sh
author dholmes
Tue, 12 Jan 2016 19:48:00 -0500
changeset 35485 9ee1d7aba342
parent 29311 bc685175f836
child 39926 7a6d5289e7b0
permissions -rw-r--r--
8146855: Update hotspot sources to recognize Solaris Studio 12u4 compiler Reviewed-by: dcubed, gthornbr
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}
29311
bc685175f836 8074910: hgforest.sh needs an option to bring over a smaller set of extra repos
prr
parents: 28009
diff changeset
    29
      echo "command format : mercurial-command [ "jdk" ] [ extra-url ]"
bc685175f836 8074910: hgforest.sh needs an option to bring over a smaller set of extra repos
prr
parents: 28009
diff changeset
    30
      echo "command option: jdk : used only with clone command to request just the extra repos for JDK-only builds"
bc685175f836 8074910: hgforest.sh needs an option to bring over a smaller set of extra repos
prr
parents: 28009
diff changeset
    31
      echo "command option : extra-url : server hosting the extra repositories"
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    32
      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
    33
      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
    34
      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
    35
      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
    36
      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
    37
      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
    38
      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
    39
      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
    40
      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
    41
      exit 1
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    42
}
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    43
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    44
global_opts="${HGFOREST_GLOBALOPTS:-}"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    45
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
    46
qflag="${HGFOREST_QUIET:-false}"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    47
vflag="${HGFOREST_VERBOSE:-false}"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    48
sflag="${HGFOREST_SEQUENTIAL:-false}"
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    49
while [ $# -gt 0 ]
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    50
do
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    51
  case $1 in
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    52
    -h | --help )
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    53
      usage
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    54
      ;;
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    55
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    56
    -q | --quiet )
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    57
      qflag="true"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    58
      ;;
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
    -v | --verbose )
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    61
      vflag="true"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    62
      ;;
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    63
23436
90d12e975106 8039990: Add sequential operation support to hgforest
chegar
parents: 23427
diff changeset
    64
    -s | --sequential )
90d12e975106 8039990: Add sequential operation support to hgforest
chegar
parents: 23427
diff changeset
    65
      sflag="true"
90d12e975106 8039990: Add sequential operation support to hgforest
chegar
parents: 23427
diff changeset
    66
      ;;
90d12e975106 8039990: Add sequential operation support to hgforest
chegar
parents: 23427
diff changeset
    67
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    68
    '--' ) # no more options
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    69
      shift; break
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    70
      ;;
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    71
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    72
    -*)  # bad option
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    73
      usage
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    74
      ;;
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
     * )  # non option
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    77
      break
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    78
      ;;
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    79
  esac
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    80
  shift
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    81
done
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    82
26118
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
    83
# debug mode
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
    84
if [ "${HGFOREST_DEBUG:-false}" = "true" ] ; then
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
    85
  global_opts="${global_opts} --debug"
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
    86
fi
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
    87
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    88
# silence standard output?
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    89
if [ ${qflag} = "true" ] ; then
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    90
  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
    91
  status_output="/dev/null"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    92
fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    93
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    94
# verbose output?
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    95
if [ ${vflag} = "true" ] ; then
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    96
  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
    97
fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    98
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    99
# Make sure we have a command.
26118
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   100
if [ ${#} -lt 1 -o -z "${1:-}" ] ; then
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   101
  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
   102
  usage > ${status_output}
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   103
fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   104
26118
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   105
# grab command
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   106
command="${1}"; shift
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   107
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   108
if [ ${vflag} = "true" ] ; then
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   109
  echo "# Mercurial command: ${command}" > ${status_output}
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   110
fi
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   111
28009
987f121a835f 8067631: hgforest.sh mishandles arguments with spaces
smarks
parents: 26118
diff changeset
   112
# At this point all command options and args are in "$@".
987f121a835f 8067631: hgforest.sh mishandles arguments with spaces
smarks
parents: 26118
diff changeset
   113
# Always use "$@" (within double quotes) to avoid breaking
987f121a835f 8067631: hgforest.sh mishandles arguments with spaces
smarks
parents: 26118
diff changeset
   114
# args with spaces into separate args.
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   115
26118
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   116
if [ ${vflag} = "true" ] ; then
28009
987f121a835f 8067631: hgforest.sh mishandles arguments with spaces
smarks
parents: 26118
diff changeset
   117
  echo "# Mercurial command argument count: $#" > ${status_output}
987f121a835f 8067631: hgforest.sh mishandles arguments with spaces
smarks
parents: 26118
diff changeset
   118
  for cmdarg in "$@" ; do
987f121a835f 8067631: hgforest.sh mishandles arguments with spaces
smarks
parents: 26118
diff changeset
   119
    echo "# Mercurial command argument: ${cmdarg}" > ${status_output}
987f121a835f 8067631: hgforest.sh mishandles arguments with spaces
smarks
parents: 26118
diff changeset
   120
  done
26118
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   121
fi
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   122
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   123
# 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
   124
tmp=/tmp/forest.$$
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   125
rm -f -r ${tmp}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   126
mkdir -p ${tmp}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   127
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   128
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   129
if [ "${HGFOREST_DEBUG:-false}" = "true" ] ; then
26118
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   130
  # ignores redirection.
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   131
  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
   132
fi
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   133
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   134
# 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
   135
echo "1" > ${tmp}/read
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   136
while_subshell=1
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   137
while read line; do
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   138
  while_subshell=0
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   139
  break;
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   140
done < ${tmp}/read
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   141
rm ${tmp}/read
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   142
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   143
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
   144
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   145
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
   146
  # 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
   147
  # 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
   148
  # 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
   149
  have_fifos="false"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   150
else
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   151
  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
   152
fi
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   153
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   154
safe_interrupt () {
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   155
  if [ -d ${tmp} ]; then
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   156
    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
   157
      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
   158
      sleep 1
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   159
      # 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
   160
      # a subprocess that has already exited.
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   161
      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
   162
      wait
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   163
      echo "Interrupt complete!" > ${status_output}
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   164
    fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   165
    rm -f -r ${tmp}
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   166
  fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   167
  exit 130
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   168
}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   169
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   170
nice_exit () {
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   171
  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
   172
    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
   173
      wait
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   174
    fi
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   175
    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
   176
      rm -f -r ${tmp}
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   177
    fi
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   178
  fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   179
}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   180
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   181
trap 'safe_interrupt' INT QUIT
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   182
trap 'nice_exit' EXIT
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   183
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   184
subrepos="corba jaxp jaxws langtools jdk hotspot nashorn"
29311
bc685175f836 8074910: hgforest.sh needs an option to bring over a smaller set of extra repos
prr
parents: 28009
diff changeset
   185
jdk_subrepos_extra="closed jdk/src/closed jdk/make/closed jdk/test/closed hotspot/make/closed hotspot/src/closed hotspot/test/closed"
bc685175f836 8074910: hgforest.sh needs an option to bring over a smaller set of extra repos
prr
parents: 28009
diff changeset
   186
subrepos_extra="$jdk_subrepos_extra deploy install sponsors pubs"
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   187
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   188
# 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
   189
pull_default=""
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   190
repos=""
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   191
repos_extra=""
23427
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   192
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
   193
  # we must be a clone
23427
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   194
  if [ ! -f .hg/hgrc ] ; then
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   195
    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
   196
    exit 1
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   197
  fi
23427
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
  # 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
   200
  pull_default=`hg paths default`
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   201
  if [ "${pull_default}" = "" ] ; then
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   202
    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
   203
    exit 1
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   204
  fi
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   205
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   206
  # 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
   207
  for i in ${subrepos} ; do
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   208
    if [ ! -f ${i}/.hg/hgrc ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   209
      repos="${repos} ${i}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   210
    fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   211
  done
24233
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   212
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   213
  pull_default_tail=`echo ${pull_default} | sed -e 's@^.*://[^/]*/\(.*\)@\1@'`
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   214
28009
987f121a835f 8067631: hgforest.sh mishandles arguments with spaces
smarks
parents: 26118
diff changeset
   215
  if [ $# -gt 0 ] ; then
29311
bc685175f836 8074910: hgforest.sh needs an option to bring over a smaller set of extra repos
prr
parents: 28009
diff changeset
   216
    if [ "x${1}" = "xjdk" ] ; then
bc685175f836 8074910: hgforest.sh needs an option to bring over a smaller set of extra repos
prr
parents: 28009
diff changeset
   217
       subrepos_extra=$jdk_subrepos_extra
bc685175f836 8074910: hgforest.sh needs an option to bring over a smaller set of extra repos
prr
parents: 28009
diff changeset
   218
       echo "subrepos being cloned are $subrepos_extra"
bc685175f836 8074910: hgforest.sh needs an option to bring over a smaller set of extra repos
prr
parents: 28009
diff changeset
   219
       shift
bc685175f836 8074910: hgforest.sh needs an option to bring over a smaller set of extra repos
prr
parents: 28009
diff changeset
   220
    fi
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   221
    # 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
   222
    if [ "x${pull_default}" = "x${pull_default_tail}" ] ; then
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   223
      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
   224
      exit 1
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   225
    fi
28009
987f121a835f 8067631: hgforest.sh mishandles arguments with spaces
smarks
parents: 26118
diff changeset
   226
    # assume that "extra sources" path is the first arg
987f121a835f 8067631: hgforest.sh mishandles arguments with spaces
smarks
parents: 26118
diff changeset
   227
    pull_extra="${1}/${pull_default_tail}"
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   228
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   229
    # 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
   230
    for i in ${subrepos_extra} ; do
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   231
      if [ ! -f ${i}/.hg/hgrc ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   232
        repos_extra="${repos_extra} ${i}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   233
      fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   234
    done
24233
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   235
  else
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   236
    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
   237
      # 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
   238
      for i in ${subrepos_extra} ; do
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   239
        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
   240
          # sub-repo there in source but not here
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   241
          repos_extra="${repos_extra} ${i}"
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   242
        fi
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   243
      done
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   244
    fi
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   245
  fi
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   246
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   247
  # Any repos to deal with?
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   248
  if [ "${repos}" = "" -a "${repos_extra}" = "" ] ; then
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   249
    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
   250
    exit
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   251
  fi
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   252
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   253
  # 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
   254
  at_a_time="${HGFOREST_CONCURRENCY:-2}"
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   255
else
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   256
  # 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
   257
  for i in . ${subrepos} ${subrepos_extra} ; do
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   258
    if [ -d ${i}/.hg ] ; then
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   259
      repos="${repos} ${i}"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   260
    fi
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   261
  done
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   262
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   263
  # Any repos to deal with?
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   264
  if [ "${repos}" = "" ] ; then
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   265
    echo "No repositories to process." > ${status_output}
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   266
    exit
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   267
  fi
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   268
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   269
  # 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
   270
  locked=""
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   271
  for i in ${repos} ; do
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   272
    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
   273
      locked="${i} ${locked}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   274
    fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   275
  done
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   276
  if [ "${locked}" != "" ] ; then
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   277
    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
   278
    exit 1
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   279
  fi
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   280
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   281
  # Repos to process concurrently.
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   282
  at_a_time="${HGFOREST_CONCURRENCY:-8}"
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   283
fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   284
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   285
# 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
   286
echo "# Repositories: ${repos} ${repos_extra}" > ${status_output}
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   287
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   288
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
   289
  # "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
   290
  (
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   291
    (
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   292
      cwd=`pwd`
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   293
      serving=`basename ${cwd}`
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   294
      (
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   295
        echo "[web]"
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   296
        echo "description = ${serving}"
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   297
        echo "allow_push = *"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   298
        echo "push_ssl = False"
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   299
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   300
        echo "[paths]"
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   301
        for i in ${repos} ; do
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   302
          if [ "${i}" != "." ] ; then
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   303
            echo "/${serving}/${i} = ${i}"
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   304
          else
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   305
            echo "/${serving} = ${cwd}"
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   306
          fi
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   307
        done
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   308
      ) > ${tmp}/serve.web-conf
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   309
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   310
      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
   311
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   312
      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
   313
      (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
   314
    ) 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
   315
  ) &
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   316
else
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   317
  # Run the supplied command on all repos in parallel.
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   318
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   319
  # 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
   320
  n=0
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   321
  if [ ${have_fifos} = "true" ]; then
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   322
    # if we have fifos use them to detect command completion.
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   323
    mkfifo ${tmp}/fifo
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   324
    exec 3<>${tmp}/fifo
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   325
  fi
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   326
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   327
  # iterate over all of the subrepos.
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   328
  for i in ${repos} ${repos_extra} ; do
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   329
    n=`expr ${n} '+' 1`
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   330
    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
   331
    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
   332
    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
   333
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   334
    # 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
   335
    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
   336
      if [ "${i}" = "${j}" ] ; then
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   337
        # it's an "extra"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   338
        pull_base="${pull_extra}"
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   339
      fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   340
    done
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   341
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   342
    # remove trailing slash
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   343
    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
   344
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   345
    # execute the command on the subrepo
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   346
    (
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   347
      (
23427
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   348
        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
   349
          # some form of clone
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   350
          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
   351
          parent_path="`dirname ${i}`"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   352
          if [ "${parent_path}" != "." ] ; then
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   353
            times=0
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   354
            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
   355
              if [ "${sflag}" = "true" ] ; then
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   356
                # 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
   357
                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
   358
                exit 1
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   359
              fi
24306
6d8861ac0307 8043182: hgforest.sh: syntax error on line 329
mduigou
parents: 24305
diff changeset
   360
              times=`expr ${times} '+' 1`
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   361
              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
   362
                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
   363
              fi
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   364
              sleep 5
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   365
            done
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   366
          fi
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   367
          # run the clone command.
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   368
          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
   369
          (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
   370
        else
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   371
          # run the command.
28009
987f121a835f 8067631: hgforest.sh mishandles arguments with spaces
smarks
parents: 26118
diff changeset
   372
          echo "cd ${i} && hg${global_opts} ${command} ${@}" > ${status_output}
987f121a835f 8067631: hgforest.sh mishandles arguments with spaces
smarks
parents: 26118
diff changeset
   373
          cd ${i} && (PYTHONUNBUFFERED=true hg${global_opts} ${command} "${@}"; echo "$?" > ${tmp}/${repopidfile}.pid.rc ) 2>&1 &
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   374
        fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   375
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   376
        echo $! > ${tmp}/${repopidfile}.pid
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   377
      ) 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
   378
      # 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
   379
      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
   380
        echo "${i}" >&3
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   381
      fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   382
    ) &
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   383
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   384
    if [ "${sflag}" = "true" ] ; then
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   385
      # 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
   386
      wait
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   387
    else
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   388
      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
   389
        # 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
   390
        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
   391
          # 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
   392
          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
   393
            n=`expr ${n} '-' 1`
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   394
            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
   395
              # 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
   396
              break;
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   397
            fi
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   398
          done <&3
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   399
        fi
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   400
      else
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   401
        # 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
   402
        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
   403
        while [ `expr ${n} '-' ${completed}` -ge ${at_a_time} ] ; do
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   404
          # sleep a short time to give time for something to complete
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   405
          sleep 1
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   406
          completed="`(ls -a1 ${tmp}/*.pid.rc 2> /dev/null | wc -l) || echo 0`"
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   407
        done
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   408
      fi
23436
90d12e975106 8039990: Add sequential operation support to hgforest
chegar
parents: 23427
diff changeset
   409
    fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   410
  done
26118
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   411
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   412
  if [ ${have_fifos} = "true" ]; then
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   413
    # done with the fifo
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   414
    exec 3>&-
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   415
  fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   416
fi
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   417
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   418
# Wait for all subprocesses to complete
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   419
wait
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   420
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   421
# 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
   422
# Terminate with highest exit code of subprocesses
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   423
ec=0
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   424
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
   425
  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
   426
  for rc in ${rcfiles} ; do
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   427
    exit_code=`cat ${rc} | tr -d ' \n\r'`
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   428
    if [ "${exit_code}" != "0" ] ; then
26118
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   429
      if [ ${exit_code} -gt 1 ]; then
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   430
        # 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
   431
      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
   432
      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
   433
      fi
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   434
      if [ ${exit_code} -gt ${ec} ]; then
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   435
        # assume that larger exit codes are more significant
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   436
        ec=${exit_code}
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   437
      fi
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   438
    fi
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   439
  done
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   440
fi
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   441
exit ${ec}