common/bin/hgforest.sh
author tschatzl
Thu, 28 Aug 2014 15:55:05 +0000
changeset 26330 0621bea60fad
parent 24306 6d8861ac0307
child 26118 dd063cd6c737
permissions -rw-r--r--
Merge
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
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    80
# silence standard output?
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    81
if [ ${qflag} = "true" ] ; then
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    82
  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
    83
  status_output="/dev/null"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    84
fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    85
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    86
# verbose output?
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    87
if [ ${vflag} = "true" ] ; then
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    88
  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
    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
# Make sure we have a command.
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    92
if [ $# -lt 1 -o -z "${1:-}" ] ; then
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    93
  echo "ERROR: No command to hg supplied!"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    94
  usage
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    95
fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    96
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    97
command="$1"; shift
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
    98
command_args="${@:-}"
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
    99
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   100
# 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
   101
tmp=/tmp/forest.$$
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   102
rm -f -r ${tmp}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   103
mkdir -p ${tmp}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   104
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   105
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   106
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
   107
  echo "DEBUG: temp files are in: ${tmp}"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   108
fi
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   109
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   110
# 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
   111
echo "1" > ${tmp}/read
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   112
while_subshell=1
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   113
while read line; do
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   114
  while_subshell=0
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   115
  break;
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   116
done < ${tmp}/read
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   117
rm ${tmp}/read
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   118
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   119
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
   120
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   121
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
   122
  # 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
   123
  # 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
   124
  # 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
   125
  have_fifos="false"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   126
else
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   127
  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
   128
fi
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   129
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   130
safe_interrupt () {
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   131
  if [ -d ${tmp} ]; then
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   132
    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
   133
      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
   134
      sleep 1
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   135
      # 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
   136
      # a subprocess that has already exited.
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   137
      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
   138
      wait
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   139
      echo "Interrupt complete!" > ${status_output}
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   140
    fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   141
    rm -f -r ${tmp}
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   142
  fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   143
  exit 130
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   144
}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   145
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   146
nice_exit () {
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   147
  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
   148
    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
   149
      wait
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   150
    fi
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   151
    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
   152
      rm -f -r ${tmp}
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   153
    fi
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   154
  fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   155
}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   156
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   157
trap 'safe_interrupt' INT QUIT
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   158
trap 'nice_exit' EXIT
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   159
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   160
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
   161
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
   162
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   163
# 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
   164
pull_default=""
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   165
repos=""
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   166
repos_extra=""
23427
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   167
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
   168
  # we must be a clone
23427
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   169
  if [ ! -f .hg/hgrc ] ; then
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   170
    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
   171
    exit 1
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   172
  fi
23427
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   173
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   174
  # 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
   175
  pull_default=`hg paths default`
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   176
  if [ "${pull_default}" = "" ] ; then
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   177
    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
   178
    exit 1
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   179
  fi
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   180
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   181
  # 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
   182
  for i in ${subrepos} ; do
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   183
    if [ ! -f ${i}/.hg/hgrc ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   184
      repos="${repos} ${i}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   185
    fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   186
  done
24233
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   187
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   188
  pull_default_tail=`echo ${pull_default} | sed -e 's@^.*://[^/]*/\(.*\)@\1@'`
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   189
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   190
  if [ -n "${command_args}" ] ; then
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   191
    # 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
   192
    if [ "x${pull_default}" = "x${pull_default_tail}" ] ; then
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   193
      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
   194
      exit 1
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   195
    fi
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   196
    pull_extra="${command_args}/${pull_default_tail}"
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   197
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   198
    # 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
   199
    for i in ${subrepos_extra} ; do
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   200
      if [ ! -f ${i}/.hg/hgrc ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   201
        repos_extra="${repos_extra} ${i}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   202
      fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   203
    done
24233
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   204
  else
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   205
    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
   206
      # 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
   207
      for i in ${subrepos_extra} ; do
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   208
        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
   209
          # sub-repo there in source but not here
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   210
          repos_extra="${repos_extra} ${i}"
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   211
        fi
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   212
      done
5c59e988c04e 8042417: hgforest: allow local clone of extra repos
mduigou
parents: 23989
diff changeset
   213
    fi
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   214
  fi
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   215
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   216
  # Any repos to deal with?
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   217
  if [ "${repos}" = "" -a "${repos_extra}" = "" ] ; then
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   218
    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
   219
    exit
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
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
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   222
  # 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
   223
  at_a_time="${HGFOREST_CONCURRENCY:-2}"
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   224
else
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   225
  # 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
   226
  for i in . ${subrepos} ${subrepos_extra} ; do
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   227
    if [ -d ${i}/.hg ] ; then
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   228
      repos="${repos} ${i}"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   229
    fi
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   230
  done
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   231
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   232
  # Any repos to deal with?
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   233
  if [ "${repos}" = "" ] ; then
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   234
    echo "No repositories to process." > ${status_output}
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   235
    exit
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   236
  fi
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   237
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   238
  # 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
   239
  locked=""
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   240
  for i in ${repos} ; do
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   241
    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
   242
      locked="${i} ${locked}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   243
    fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   244
  done
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   245
  if [ "${locked}" != "" ] ; then
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   246
    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
   247
    exit 1
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   248
  fi
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   249
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   250
  # Repos to process concurrently.
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   251
  at_a_time="${HGFOREST_CONCURRENCY:-8}"
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   252
fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   253
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   254
# 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
   255
echo "# Repositories: ${repos} ${repos_extra}" > ${status_output}
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   256
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   257
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
   258
  # "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
   259
  (
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   260
    (
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   261
      cwd=`pwd`
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   262
      serving=`basename ${cwd}`
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   263
      (
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   264
        echo "[web]"
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   265
        echo "description = ${serving}"
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   266
        echo "allow_push = *"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   267
        echo "push_ssl = False"
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   268
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   269
        echo "[paths]"
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   270
        for i in ${repos} ; do
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   271
          if [ "${i}" != "." ] ; then
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   272
            echo "/${serving}/${i} = ${i}"
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   273
          else
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   274
            echo "/${serving} = ${cwd}"
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   275
          fi
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   276
        done
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   277
      ) > ${tmp}/serve.web-conf
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   278
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   279
      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
   280
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   281
      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
   282
      (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
   283
    ) 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
   284
  ) &
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   285
else
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   286
  # Run the supplied command on all repos in parallel.
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   287
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   288
  # 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
   289
  n=0
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   290
  if [ ${have_fifos} = "true" ]; then
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   291
    # if we have fifos use them to detect command completion.
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   292
    mkfifo ${tmp}/fifo
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   293
    exec 3<>${tmp}/fifo
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   294
  fi
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   295
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   296
  # iterate over all of the subrepos.
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   297
  for i in ${repos} ${repos_extra} ; do
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   298
    n=`expr ${n} '+' 1`
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   299
    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
   300
    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
   301
    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
   302
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   303
    # 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
   304
    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
   305
      if [ "${i}" = "${j}" ] ; then
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   306
        # it's an "extra"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   307
        pull_base="${pull_extra}"
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   308
      fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   309
    done
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   310
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   311
    # remove trailing slash
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   312
    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
   313
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   314
    # execute the command on the subrepo
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   315
    (
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   316
      (
23427
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   317
        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
   318
          # some form of clone
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   319
          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
   320
          parent_path="`dirname ${i}`"
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   321
          if [ "${parent_path}" != "." ] ; then
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   322
            times=0
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   323
            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
   324
              if [ "${sflag}" = "true" ] ; then
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   325
                # 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
   326
                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
   327
                exit 1
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   328
              fi
24306
6d8861ac0307 8043182: hgforest.sh: syntax error on line 329
mduigou
parents: 24305
diff changeset
   329
              times=`expr ${times} '+' 1`
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   330
              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
   331
                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
   332
              fi
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   333
              sleep 5
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   334
            done
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   335
          fi
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   336
          # run the clone command.
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   337
          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
   338
          (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
   339
        else
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   340
          # run the command.
23427
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   341
          echo "cd ${i} && hg${global_opts} ${command} ${command_args}" > ${status_output}
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   342
          cd ${i} && (PYTHONUNBUFFERED=true hg${global_opts} ${command} ${command_args}; echo "$?" > ${tmp}/${repopidfile}.pid.rc ) 2>&1 &
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   343
        fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   344
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   345
        echo $! > ${tmp}/${repopidfile}.pid
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   346
      ) 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
   347
      # 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
   348
      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
   349
        echo "${i}" >&3
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   350
      fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   351
    ) &
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   352
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   353
    if [ "${sflag}" = "true" ] ; then
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   354
      # 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
   355
      wait
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   356
    else
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   357
      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
   358
        # 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
   359
        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
   360
          # 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
   361
          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
   362
            n=`expr ${n} '-' 1`
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   363
            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
   364
              # 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
   365
              break;
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   366
            fi
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   367
          done <&3
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   368
        fi
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   369
      else
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   370
        # 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
   371
        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
   372
        while [ `expr ${n} '-' ${completed}` -ge ${at_a_time} ] ; do
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   373
          # sleep a short time to give time for something to complete
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   374
          sleep 1
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   375
          completed="`(ls -a1 ${tmp}/*.pid.rc 2> /dev/null | wc -l) || echo 0`"
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   376
        done
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   377
      fi
23436
90d12e975106 8039990: Add sequential operation support to hgforest
chegar
parents: 23427
diff changeset
   378
    fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   379
  done
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   380
fi
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   381
23989
da174d121fd3 8041151: More concurrent hgforest
mduigou
parents: 23436
diff changeset
   382
# Wait for all subprocesses to complete
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   383
wait
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   384
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   385
# Terminate with exit 0 only if all subprocesses were successful
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   386
ec=0
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   387
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
   388
  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
   389
  for rc in ${rcfiles} ; do
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   390
    exit_code=`cat ${rc} | tr -d ' \n\r'`
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   391
    if [ "${exit_code}" != "0" ] ; then
24305
e70f1f56a8d2 8042810: hgforest: some shells run read in sub-shell and can't use fifo
mduigou
parents: 24233
diff changeset
   392
      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
   393
      echo "WARNING: ${repo} exited abnormally (${exit_code})" > ${status_output}
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   394
      ec=1
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   395
    fi
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   396
  done
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   397
fi
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   398
exit ${ec}