common/bin/hgforest.sh
author lpriima
Tue, 20 Jan 2015 13:56:01 +0000
changeset 28523 843229b1db9f
parent 28009 987f121a835f
child 29311 bc685175f836
permissions -rw-r--r--
8068795: HttpServer missing tailing space for some response codes Reviewed-by: chegar
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
28009
987f121a835f 8067631: hgforest.sh mishandles arguments with spaces
smarks
parents: 26118
diff changeset
   109
# At this point all command options and args are in "$@".
987f121a835f 8067631: hgforest.sh mishandles arguments with spaces
smarks
parents: 26118
diff changeset
   110
# Always use "$@" (within double quotes) to avoid breaking
987f121a835f 8067631: hgforest.sh mishandles arguments with spaces
smarks
parents: 26118
diff changeset
   111
# args with spaces into separate 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
28009
987f121a835f 8067631: hgforest.sh mishandles arguments with spaces
smarks
parents: 26118
diff changeset
   114
  echo "# Mercurial command argument count: $#" > ${status_output}
987f121a835f 8067631: hgforest.sh mishandles arguments with spaces
smarks
parents: 26118
diff changeset
   115
  for cmdarg in "$@" ; do
987f121a835f 8067631: hgforest.sh mishandles arguments with spaces
smarks
parents: 26118
diff changeset
   116
    echo "# Mercurial command argument: ${cmdarg}" > ${status_output}
987f121a835f 8067631: hgforest.sh mishandles arguments with spaces
smarks
parents: 26118
diff changeset
   117
  done
26118
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   118
fi
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   119
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   120
# 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
   121
tmp=/tmp/forest.$$
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   122
rm -f -r ${tmp}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   123
mkdir -p ${tmp}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   124
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   125
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   126
if [ "${HGFOREST_DEBUG:-false}" = "true" ] ; then
26118
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   127
  # ignores redirection.
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   128
  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
   129
fi
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   130
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   131
# 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
   132
echo "1" > ${tmp}/read
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   133
while_subshell=1
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   134
while read line; do
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   135
  while_subshell=0
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   136
  break;
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   137
done < ${tmp}/read
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   138
rm ${tmp}/read
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   139
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   140
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
   141
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   142
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
   143
  # 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
   144
  # 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
   145
  # 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
   146
  have_fifos="false"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   147
else
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   148
  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
   149
fi
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   150
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   151
safe_interrupt () {
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   152
  if [ -d ${tmp} ]; then
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   153
    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
   154
      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
   155
      sleep 1
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   156
      # 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
   157
      # a subprocess that has already exited.
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   158
      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
   159
      wait
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   160
      echo "Interrupt complete!" > ${status_output}
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   161
    fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   162
    rm -f -r ${tmp}
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   163
  fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   164
  exit 130
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   165
}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   166
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   167
nice_exit () {
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   168
  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
   169
    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
   170
      wait
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   171
    fi
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   172
    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
   173
      rm -f -r ${tmp}
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   174
    fi
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   175
  fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   176
}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   177
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   178
trap 'safe_interrupt' INT QUIT
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   179
trap 'nice_exit' EXIT
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   180
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   181
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
   182
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
   183
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   184
# 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
   185
pull_default=""
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   186
repos=""
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   187
repos_extra=""
23427
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   188
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
   189
  # we must be a clone
23427
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   190
  if [ ! -f .hg/hgrc ] ; then
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   191
    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
   192
    exit 1
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   193
  fi
23427
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   194
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   195
  # 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
   196
  pull_default=`hg paths default`
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   197
  if [ "${pull_default}" = "" ] ; then
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   198
    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
   199
    exit 1
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   200
  fi
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   201
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   202
  # 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
   203
  for i in ${subrepos} ; do
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   204
    if [ ! -f ${i}/.hg/hgrc ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   205
      repos="${repos} ${i}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   206
    fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   207
  done
24233
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   208
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   209
  pull_default_tail=`echo ${pull_default} | sed -e 's@^.*://[^/]*/\(.*\)@\1@'`
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   210
28009
987f121a835f 8067631: hgforest.sh mishandles arguments with spaces
smarks
parents: 26118
diff changeset
   211
  if [ $# -gt 0 ] ; then
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   212
    # 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
   213
    if [ "x${pull_default}" = "x${pull_default_tail}" ] ; then
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   214
      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
   215
      exit 1
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   216
    fi
28009
987f121a835f 8067631: hgforest.sh mishandles arguments with spaces
smarks
parents: 26118
diff changeset
   217
    # assume that "extra sources" path is the first arg
987f121a835f 8067631: hgforest.sh mishandles arguments with spaces
smarks
parents: 26118
diff changeset
   218
    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
   219
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   220
    # 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
   221
    for i in ${subrepos_extra} ; do
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   222
      if [ ! -f ${i}/.hg/hgrc ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   223
        repos_extra="${repos_extra} ${i}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   224
      fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   225
    done
24233
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   226
  else
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   227
    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
   228
      # 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
   229
      for i in ${subrepos_extra} ; do
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   230
        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
   231
          # sub-repo there in source but not here
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   232
          repos_extra="${repos_extra} ${i}"
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   233
        fi
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   234
      done
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   235
    fi
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   236
  fi
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   237
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   238
  # Any repos to deal with?
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   239
  if [ "${repos}" = "" -a "${repos_extra}" = "" ] ; then
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   240
    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
   241
    exit
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   242
  fi
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   243
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   244
  # 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
   245
  at_a_time="${HGFOREST_CONCURRENCY:-2}"
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   246
else
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   247
  # 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
   248
  for i in . ${subrepos} ${subrepos_extra} ; do
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   249
    if [ -d ${i}/.hg ] ; then
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   250
      repos="${repos} ${i}"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   251
    fi
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   252
  done
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   253
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   254
  # Any repos to deal with?
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   255
  if [ "${repos}" = "" ] ; then
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   256
    echo "No repositories to process." > ${status_output}
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   257
    exit
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   258
  fi
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   259
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   260
  # 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
   261
  locked=""
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   262
  for i in ${repos} ; do
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   263
    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
   264
      locked="${i} ${locked}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   265
    fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   266
  done
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   267
  if [ "${locked}" != "" ] ; then
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   268
    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
   269
    exit 1
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   270
  fi
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   271
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   272
  # Repos to process concurrently.
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   273
  at_a_time="${HGFOREST_CONCURRENCY:-8}"
14735
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
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   276
# 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
   277
echo "# Repositories: ${repos} ${repos_extra}" > ${status_output}
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   278
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   279
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
   280
  # "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
   281
  (
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   282
    (
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   283
      cwd=`pwd`
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   284
      serving=`basename ${cwd}`
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   285
      (
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   286
        echo "[web]"
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   287
        echo "description = ${serving}"
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   288
        echo "allow_push = *"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   289
        echo "push_ssl = False"
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   290
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   291
        echo "[paths]"
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   292
        for i in ${repos} ; do
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   293
          if [ "${i}" != "." ] ; then
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   294
            echo "/${serving}/${i} = ${i}"
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   295
          else
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   296
            echo "/${serving} = ${cwd}"
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   297
          fi
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   298
        done
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   299
      ) > ${tmp}/serve.web-conf
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   300
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   301
      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
   302
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   303
      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
   304
      (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
   305
    ) 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
   306
  ) &
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   307
else
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   308
  # Run the supplied command on all repos in parallel.
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   309
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   310
  # 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
   311
  n=0
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   312
  if [ ${have_fifos} = "true" ]; then
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   313
    # if we have fifos use them to detect command completion.
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   314
    mkfifo ${tmp}/fifo
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   315
    exec 3<>${tmp}/fifo
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   316
  fi
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   317
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   318
  # iterate over all of the subrepos.
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   319
  for i in ${repos} ${repos_extra} ; do
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   320
    n=`expr ${n} '+' 1`
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   321
    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
   322
    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
   323
    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
   324
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   325
    # 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
   326
    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
   327
      if [ "${i}" = "${j}" ] ; then
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   328
        # it's an "extra"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   329
        pull_base="${pull_extra}"
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   330
      fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   331
    done
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   332
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   333
    # remove trailing slash
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   334
    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
   335
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   336
    # execute the command on the subrepo
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   337
    (
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   338
      (
23427
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   339
        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
   340
          # some form of clone
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   341
          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
   342
          parent_path="`dirname ${i}`"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   343
          if [ "${parent_path}" != "." ] ; then
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   344
            times=0
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   345
            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
   346
              if [ "${sflag}" = "true" ] ; then
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   347
                # 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
   348
                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
   349
                exit 1
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   350
              fi
24306
6d8861ac0307 8043182: hgforest.sh: syntax error on line 329
mduigou
parents: 24305
diff changeset
   351
              times=`expr ${times} '+' 1`
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   352
              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
   353
                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
   354
              fi
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   355
              sleep 5
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   356
            done
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   357
          fi
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   358
          # run the clone command.
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   359
          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
   360
          (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
   361
        else
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   362
          # run the command.
28009
987f121a835f 8067631: hgforest.sh mishandles arguments with spaces
smarks
parents: 26118
diff changeset
   363
          echo "cd ${i} && hg${global_opts} ${command} ${@}" > ${status_output}
987f121a835f 8067631: hgforest.sh mishandles arguments with spaces
smarks
parents: 26118
diff changeset
   364
          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
   365
        fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   366
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   367
        echo $! > ${tmp}/${repopidfile}.pid
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   368
      ) 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
   369
      # 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
   370
      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
   371
        echo "${i}" >&3
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   372
      fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   373
    ) &
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   374
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   375
    if [ "${sflag}" = "true" ] ; then
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   376
      # 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
   377
      wait
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   378
    else
24305
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
        # 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
   381
        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
   382
          # 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
   383
          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
   384
            n=`expr ${n} '-' 1`
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   385
            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
   386
              # 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
   387
              break;
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   388
            fi
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   389
          done <&3
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   390
        fi
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   391
      else
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   392
        # 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
   393
        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
   394
        while [ `expr ${n} '-' ${completed}` -ge ${at_a_time} ] ; do
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   395
          # sleep a short time to give time for something to complete
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   396
          sleep 1
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   397
          completed="`(ls -a1 ${tmp}/*.pid.rc 2> /dev/null | wc -l) || echo 0`"
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   398
        done
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   399
      fi
23436
90d12e975106 8039990: Add sequential operation support to hgforest
chegar
parents: 23427
diff changeset
   400
    fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   401
  done
26118
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   402
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   403
  if [ ${have_fifos} = "true" ]; then
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   404
    # done with the fifo
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   405
    exec 3>&-
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   406
  fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   407
fi
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   408
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   409
# Wait for all subprocesses to complete
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   410
wait
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   411
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   412
# 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
   413
# Terminate with highest exit code of subprocesses
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   414
ec=0
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   415
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
   416
  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
   417
  for rc in ${rcfiles} ; do
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   418
    exit_code=`cat ${rc} | tr -d ' \n\r'`
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   419
    if [ "${exit_code}" != "0" ] ; then
26118
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   420
      if [ ${exit_code} -gt 1 ]; then
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   421
        # 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
   422
      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
   423
      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
   424
      fi
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   425
      if [ ${exit_code} -gt ${ec} ]; then
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   426
        # assume that larger exit codes are more significant
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   427
        ec=${exit_code}
dd063cd6c737 8055331: cleaner handling of sub-process non-zero exit result.
mduigou
parents: 24306
diff changeset
   428
      fi
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   429
    fi
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   430
  done
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   431
fi
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   432
exit ${ec}