common/bin/hgforest.sh
author mduigou
Mon, 24 Mar 2014 15:40:29 -0700
changeset 23425 f4c75b6d7e44
parent 22712 489b8278503c
child 23427 abbf38fbeb4c
permissions -rw-r--r--
8030681: add "serve" command and --quiet and --verbose options to hgforest Reviewed-by: ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
     1
#!/bin/bash
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"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    32
while [ $# -gt 0 ]
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    33
do
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    34
  case $1 in
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    35
    -q | --quiet )
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    36
      qflag="true"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    37
      global_opts="${global_opts} -q"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    38
      status_output="/dev/null"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    39
      ;;
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
    -v | --verbose )
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    42
      vflag="true"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    43
      global_opts="${global_opts} -v"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    44
      ;;
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
    '--' ) # no more options
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    47
      shift; break
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    48
      ;;
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    49
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    50
    -*)  # bad option
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    51
      usage
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    52
      ;;
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    53
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    54
     * )  # non option
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    55
      break
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
  esac
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    58
  shift
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    59
done
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    60
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
command="$1"; shift
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    63
repo_base="$@"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    64
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    65
usage() {
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    66
      echo "usage: $0 [-q|--quiet] [-v|--verbose] [--] <command> [repo_base_path]" > ${status_output}
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    67
      exit 1
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    68
}
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
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    71
if [ "x" = "x$command" ] ; then
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    72
  echo "ERROR: No command to hg supplied!"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    73
  usage
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    74
fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    75
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    76
# 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
    77
tmp=/tmp/forest.$$
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    78
rm -f -r ${tmp}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    79
mkdir -p ${tmp}
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
safe_interrupt () {
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
    82
  if [ -d ${tmp} ]; then
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
    83
    if [ "`ls ${tmp}/*.pid`" != "" ]; then
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    84
      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
    85
      sleep 1
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    86
      # 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
    87
      # a subprocess that has already exited.
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
    88
      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
    89
      wait
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    90
      echo "Interrupt complete!" > ${status_output}
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
    91
    fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    92
    rm -f -r ${tmp}
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    93
  fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
    94
  exit 130
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    95
}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    96
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    97
nice_exit () {
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
    98
  if [ -d ${tmp} ]; then
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
    99
    if [ "`ls ${tmp}`" != "" ]; then
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   100
      wait
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   101
    fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   102
    rm -f -r ${tmp}
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   103
  fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   104
}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   105
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   106
trap 'safe_interrupt' INT QUIT
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   107
trap 'nice_exit' EXIT
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   108
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   109
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
   110
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
   111
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   112
# 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
   113
pull_default=""
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   114
repos=""
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   115
repos_extra=""
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   116
if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   117
  if [ -f .hg/hgrc ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   118
    pull_default=`hg paths default`
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   119
    if [ "${pull_default}" = "" ] ; then
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   120
      echo "ERROR: Need initial clone with 'hg paths default' defined" > ${status_output}
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   121
      exit 1
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   122
    fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   123
  fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   124
  if [ "${pull_default}" = "" ] ; then
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   125
    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
   126
    exit 1
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   127
  fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   128
  for i in ${subrepos} ; do
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   129
    if [ ! -f ${i}/.hg/hgrc ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   130
      repos="${repos} ${i}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   131
    fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   132
  done
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   133
  if [ "${repo_base}" != "" ] ; then
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   134
    pull_default_tail=`echo ${pull_default} | sed -e 's@^.*://[^/]*/\(.*\)@\1@'`
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   135
    pull_extra="${repo_base}/${pull_default_tail}"
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   136
    for i in ${subrepos_extra} ; do
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   137
      if [ ! -f ${i}/.hg/hgrc ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   138
        repos_extra="${repos_extra} ${i}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   139
      fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   140
    done
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   141
  fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   142
  at_a_time=2
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   143
  # Any repos to deal with?
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   144
  if [ "${repos}" = "" -a "${repos_extra}" = "" ] ; then
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   145
    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
   146
    exit
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   147
  fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   148
else
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   149
  for i in . ${subrepos} ${subrepos_extra} ; do
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   150
    if [ -d ${i}/.hg ] ; then
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   151
      repos="${repos} ${i}"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   152
    fi
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   153
  done
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   154
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   155
  # Any repos to deal with?
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   156
  if [ "${repos}" = "" ] ; then
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   157
    echo "No repositories to process." > ${status_output}
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   158
    exit
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   159
  fi
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   160
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   161
  # any of the repos locked?
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   162
  for i in ${repos} ; do
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   163
    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
   164
      locked="${i} ${locked}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   165
    fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   166
  done
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   167
  if [ "${locked}" != "" ] ; then
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   168
    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
   169
    exit 1
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   170
  fi
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   171
  at_a_time=8
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   172
fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   173
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   174
# 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
   175
echo "# Repositories: ${repos} ${repos_extra}" > ${status_output}
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   176
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   177
if [ "${command}" = "serve" ] ; then
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   178
  # "serve" is run for all the repos.
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   179
  (
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   180
    (
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   181
      (
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   182
        echo "[web]"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   183
        echo "description = $(basename $(pwd))"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   184
        echo "allow_push = *"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   185
        echo "push_ssl = False"
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   186
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   187
        echo "[paths]"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   188
        for i in ${repos} ${repos_extra} ; do
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   189
          if [ "${i}" != "." ] ; then
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   190
            echo "/$(basename $(pwd))/${i} = ${i}"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   191
          else
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   192
            echo "/$(basename $(pwd)) = $(pwd)"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   193
          fi
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   194
        done
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   195
      ) > ${tmp}/serve.web-conf
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   196
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   197
      echo "serving root repo $(basename $(pwd))"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   198
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   199
      (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
   200
    ) 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
   201
  ) &
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   202
else
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   203
  # 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
   204
  n=0
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   205
  for i in ${repos} ${repos_extra} ; do
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   206
    n=`expr ${n} '+' 1`
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   207
    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
   208
    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
   209
    pull_base="${pull_default}"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   210
    for j in $repos_extra ; do
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   211
      if [ "$i" = "$j" ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   212
          pull_base="${pull_extra}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   213
      fi
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   214
    done
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   215
    (
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   216
      (
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   217
        if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   218
          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
   219
          echo "hg clone ${pull_newrepo} ${i}" > ${status_output}
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   220
          path="`dirname ${i}`"
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   221
          if [ "${path}" != "." ] ; then
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   222
            times=0
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   223
            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
   224
            do
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   225
              times=`expr ${times} '+' 1`
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   226
              if [ `expr ${times} '%' 10` -eq 0 ] ; then
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   227
                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
   228
              fi
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   229
              sleep 5
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   230
            done
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   231
          fi
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   232
          (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
   233
        else
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   234
          echo "cd ${i} && hg${global_opts} ${command} ${repo_base}" > ${status_output}
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   235
          cd ${i} && (PYTHONUNBUFFERED=true hg${global_opts} ${command} ${command_repo}; echo "$?" > ${tmp}/${repopidfile}.pid.rc ) 2>&1 &
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   236
        fi
23425
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
        echo $! > ${tmp}/${repopidfile}.pid
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   239
      ) 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
   240
    ) &
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   241
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   242
    if [ `expr ${n} '%' ${at_a_time}` -eq 0 ] ; then
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   243
      sleep 2
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   244
      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
   245
      sleep 3
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   246
    fi
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   247
  done
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   248
fi
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   249
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   250
# Wait for all hg commands to complete
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   251
wait
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   252
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   253
# 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
   254
ec=0
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   255
if [ -d ${tmp} ]; then
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   256
  for rc in ${tmp}/*.pid.rc ; do
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   257
    exit_code=`cat ${rc} | tr -d ' \n\r'`
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   258
    if [ "${exit_code}" != "0" ] ; then
23425
f4c75b6d7e44 8030681: add "serve" command and --quiet and --verbose options to hgforest
mduigou
parents: 22712
diff changeset
   259
      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
   260
      echo "WARNING: ${repo} exited abnormally." > ${status_output}
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   261
      ec=1
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   262
    fi
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   263
  done
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   264
fi
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   265
exit ${ec}