common/bin/hgforest.sh
author serb
Fri, 18 Apr 2014 20:10:39 +0400
changeset 24521 97047c850d31
parent 23436 90d12e975106
child 23989 da174d121fd3
permissions -rw-r--r--
8026252: [macosx] Change AWT_DEBUG_BUG_REPORT_MESSAGE for macosx platform Reviewed-by: azvegint, pchelko
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
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
     3
#
22712
489b8278503c 8034146: Update hgforest.sh for new closed tree
iris
parents: 21173
diff changeset
     4
# 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
     5
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
     6
#
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
     7
# This code is free software; you can redistribute it and/or modify it
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
     8
# under the terms of the GNU General Public License version 2 only, as
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
     9
# published by the Free Software Foundation.
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    10
#
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    11
# This code is distributed in the hope that it will be useful, but WITHOUT
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    13
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    14
# version 2 for more details (a copy is included in the LICENSE file that
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    15
# accompanied this code).
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    16
#
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    17
# You should have received a copy of the GNU General Public License version
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    18
# 2 along with this work; if not, write to the Free Software Foundation,
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    19
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    20
#
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    21
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    22
# or visit www.oracle.com if you need additional information or have any
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    23
# questions.
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    24
#
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    25
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    26
# Shell script for a fast parallel forest command
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    27
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    28
global_opts=""
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    29
status_output="/dev/stdout"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    30
qflag="false"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    31
vflag="false"
23436
90d12e975106 8039990: Add sequential operation support to hgforest
chegar
parents: 23427
diff changeset
    32
sflag="false"
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    33
while [ $# -gt 0 ]
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    34
do
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    35
  case $1 in
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    36
    -q | --quiet )
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    37
      qflag="true"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    38
      global_opts="${global_opts} -q"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    39
      status_output="/dev/null"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    40
      ;;
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    41
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    42
    -v | --verbose )
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    43
      vflag="true"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    44
      global_opts="${global_opts} -v"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    45
      ;;
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    46
23436
90d12e975106 8039990: Add sequential operation support to hgforest
chegar
parents: 23427
diff changeset
    47
    -s | --sequential )
90d12e975106 8039990: Add sequential operation support to hgforest
chegar
parents: 23427
diff changeset
    48
      sflag="true"
90d12e975106 8039990: Add sequential operation support to hgforest
chegar
parents: 23427
diff changeset
    49
      ;;
90d12e975106 8039990: Add sequential operation support to hgforest
chegar
parents: 23427
diff changeset
    50
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    51
    '--' ) # no more options
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    52
      shift; break
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    53
      ;;
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    54
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    55
    -*)  # bad option
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    56
      usage
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    57
      ;;
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    58
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    59
     * )  # non option
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    60
      break
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    61
      ;;
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    62
  esac
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    63
  shift
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    64
done
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    65
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    66
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    67
command="$1"; shift
23427
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
    68
command_args="$@"
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    69
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    70
usage() {
23436
90d12e975106 8039990: Add sequential operation support to hgforest
chegar
parents: 23427
diff changeset
    71
      echo "usage: $0 [-q|--quiet] [-v|--verbose] [-s|--sequential] [--] <command> [commands...]" > ${status_output}
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    72
      exit 1
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    73
}
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    74
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    75
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    76
if [ "x" = "x$command" ] ; then
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    77
  echo "ERROR: No command to hg supplied!"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    78
  usage
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    79
fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    80
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    81
# 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
    82
tmp=/tmp/forest.$$
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    83
rm -f -r ${tmp}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    84
mkdir -p ${tmp}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    85
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    86
safe_interrupt () {
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
    87
  if [ -d ${tmp} ]; then
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
    88
    if [ "`ls ${tmp}/*.pid`" != "" ]; then
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    89
      echo "Waiting for processes ( `cat ${tmp}/*.pid | 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
    90
      sleep 1
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    91
      # 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
    92
      # a subprocess that has already exited.
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
    93
      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
    94
      wait
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    95
      echo "Interrupt complete!" > ${status_output}
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
    96
    fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    97
    rm -f -r ${tmp}
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    98
  fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    99
  exit 130
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   100
}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   101
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   102
nice_exit () {
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   103
  if [ -d ${tmp} ]; then
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   104
    if [ "`ls ${tmp}`" != "" ]; then
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   105
      wait
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   106
    fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   107
    rm -f -r ${tmp}
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   108
  fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   109
}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   110
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   111
trap 'safe_interrupt' INT QUIT
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   112
trap 'nice_exit' EXIT
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   113
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   114
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
   115
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
   116
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   117
# 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
   118
pull_default=""
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   119
repos=""
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   120
repos_extra=""
23427
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   121
if [ "${command}" = "clone" -o "${command}" = "fclone" -o "${command}" = "tclone" ] ; then
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   122
  if [ ! -f .hg/hgrc ] ; then
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   123
    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
   124
    exit 1
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   125
  fi
23427
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   126
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   127
  pull_default=`hg paths default`
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   128
  if [ "${pull_default}" = "" ] ; then
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   129
    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
   130
    exit 1
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   131
  fi
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   132
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   133
  for i in ${subrepos} ; do
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   134
    if [ ! -f ${i}/.hg/hgrc ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   135
      repos="${repos} ${i}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   136
    fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   137
  done
23427
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   138
  if [ "${command_args}" != "" ] ; then
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   139
    pull_default_tail=`echo ${pull_default} | sed -e 's@^.*://[^/]*/\(.*\)@\1@'`
23427
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   140
    if [ "x${pull_default}" = "x${pull_default_tail}" ] ; then
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   141
      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
   142
      exit 1
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   143
    fi
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   144
    pull_extra="${command_args}/${pull_default_tail}"
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   145
    for i in ${subrepos_extra} ; do
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   146
      if [ ! -f ${i}/.hg/hgrc ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   147
        repos_extra="${repos_extra} ${i}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   148
      fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   149
    done
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   150
  fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   151
  at_a_time=2
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   152
  # Any repos to deal with?
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   153
  if [ "${repos}" = "" -a "${repos_extra}" = "" ] ; then
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   154
    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
   155
    exit
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   156
  fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   157
else
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   158
  for i in . ${subrepos} ${subrepos_extra} ; do
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   159
    if [ -d ${i}/.hg ] ; then
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   160
      repos="${repos} ${i}"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   161
    fi
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   162
  done
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   163
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   164
  # Any repos to deal with?
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   165
  if [ "${repos}" = "" ] ; then
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   166
    echo "No repositories to process." > ${status_output}
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   167
    exit
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   168
  fi
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   169
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   170
  # any of the repos locked?
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   171
  for i in ${repos} ; do
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   172
    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
   173
      locked="${i} ${locked}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   174
    fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   175
  done
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   176
  if [ "${locked}" != "" ] ; then
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   177
    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
   178
    exit 1
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   179
  fi
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   180
  at_a_time=8
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   181
fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   182
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   183
# 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
   184
echo "# Repositories: ${repos} ${repos_extra}" > ${status_output}
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   185
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   186
if [ "${command}" = "serve" ] ; then
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   187
  # "serve" is run for all the repos.
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   188
  (
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   189
    (
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   190
      (
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   191
        echo "[web]"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   192
        echo "description = $(basename $(pwd))"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   193
        echo "allow_push = *"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   194
        echo "push_ssl = False"
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   195
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   196
        echo "[paths]"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   197
        for i in ${repos} ${repos_extra} ; do
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   198
          if [ "${i}" != "." ] ; then
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   199
            echo "/$(basename $(pwd))/${i} = ${i}"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   200
          else
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   201
            echo "/$(basename $(pwd)) = $(pwd)"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   202
          fi
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   203
        done
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   204
      ) > ${tmp}/serve.web-conf
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   205
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   206
      echo "serving root repo $(basename $(pwd))"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   207
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   208
      (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
   209
    ) 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
   210
  ) &
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   211
else
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   212
  # Run the supplied command on all repos in parallel.
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   213
  n=0
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   214
  for i in ${repos} ${repos_extra} ; do
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   215
    n=`expr ${n} '+' 1`
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   216
    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
   217
    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
   218
    pull_base="${pull_default}"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   219
    for j in $repos_extra ; do
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   220
      if [ "$i" = "$j" ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   221
          pull_base="${pull_extra}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   222
      fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   223
    done
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   224
    (
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   225
      (
23427
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   226
        if [ "${command}" = "clone" -o "${command}" = "fclone" -o "${command}" = "tclone" ] ; then
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   227
          pull_newrepo="`echo ${pull_base}/${i} | sed -e 's@\([^:]/\)//*@\1@g'`"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   228
          path="`dirname ${i}`"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   229
          if [ "${path}" != "." ] ; then
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   230
            times=0
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   231
            while [ ! -d "${path}" ]   ## nested repo, ensure containing dir exists
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   232
            do
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   233
              times=`expr ${times} '+' 1`
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   234
              if [ `expr ${times} '%' 10` -eq 0 ] ; then
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   235
                echo "${path} still not created, waiting..." > ${status_output}
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
              sleep 5
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   238
            done
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   239
          fi
23427
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   240
          echo "hg clone ${pull_newrepo} ${i}" > ${status_output}
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   241
          (PYTHONUNBUFFERED=true hg${global_opts} clone ${pull_newrepo} ${i}; echo "$?" > ${tmp}/${repopidfile}.pid.rc ) 2>&1 &
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   242
        else
23427
abbf38fbeb4c 8038435: Some hgforest.sh commands don't receive parameters
mduigou
parents: 23425
diff changeset
   243
          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
   244
          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
   245
        fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   246
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   247
        echo $! > ${tmp}/${repopidfile}.pid
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   248
      ) 2>&1 | sed -e "s@^@${reponame}:   @" > ${status_output}
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   249
    ) &
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   250
23436
90d12e975106 8039990: Add sequential operation support to hgforest
chegar
parents: 23427
diff changeset
   251
    if [ `expr ${n} '%' ${at_a_time}` -eq 0 -a "${sflag}" = "false" ] ; then
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   252
      sleep 2
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   253
      echo "Waiting 5 secs before spawning next background command." > ${status_output}
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   254
      sleep 3
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   255
    fi
23436
90d12e975106 8039990: Add sequential operation support to hgforest
chegar
parents: 23427
diff changeset
   256
90d12e975106 8039990: Add sequential operation support to hgforest
chegar
parents: 23427
diff changeset
   257
    if [ "${sflag}" = "true" ] ; then
90d12e975106 8039990: Add sequential operation support to hgforest
chegar
parents: 23427
diff changeset
   258
        wait
90d12e975106 8039990: Add sequential operation support to hgforest
chegar
parents: 23427
diff changeset
   259
    fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   260
  done
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   261
fi
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   262
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   263
# Wait for all hg commands to complete
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   264
wait
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   265
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   266
# 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
   267
ec=0
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   268
if [ -d ${tmp} ]; then
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   269
  for rc in ${tmp}/*.pid.rc ; do
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   270
    exit_code=`cat ${rc} | tr -d ' \n\r'`
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   271
    if [ "${exit_code}" != "0" ] ; then
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   272
      repo="`echo ${rc} | sed -e s@^${tmp}@@ -e 's@/*\([^/]*\)\.pid\.rc$@\1@' -e 's@_@/@g'`"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   273
      echo "WARNING: ${repo} exited abnormally." > ${status_output}
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   274
      ec=1
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   275
    fi
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   276
  done
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   277
fi
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   278
exit ${ec}