common/bin/hgforest.sh
author cl
Thu, 07 Nov 2013 08:16:38 -0800
changeset 21547 1fbd33ac5531
parent 21173 0cd521b18e6b
child 22712 489b8278503c
permissions -rw-r--r--
Added tag jdk8-b115 for changeset 115e1128ce1a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
     1
#!/bin/sh
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
#
20631
6f71614260ea 8025796: hgforest.sh could trigger unbuffered output from hg without complicated machinations
mduigou
parents: 19752
diff changeset
     4
# Copyright (c) 2009, 2013, 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
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    27
command="$1"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    28
pull_extra_base="$2"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    29
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    30
if [ "" = "$command" ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    31
  echo No command to hg supplied!
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    32
  exit 1
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    33
fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    34
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    35
# 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
    36
tmp=/tmp/forest.$$
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    37
rm -f -r ${tmp}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    38
mkdir -p ${tmp}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    39
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    40
safe_interrupt () {
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
    41
  if [ -d ${tmp} ]; then
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
    42
    if [ "`ls ${tmp}/*.pid`" != "" ]; then
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
    43
      echo "Waiting for processes ( `cat ${tmp}/*.pid | tr '\n' ' '`) to terminate nicely!"
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    44
      sleep 1
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    45
      # 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
    46
      # a subprocess that has already exited.
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
    47
      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
    48
      wait
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
    49
      echo Interrupt complete!
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
    50
    fi
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    51
  fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    52
  rm -f -r ${tmp}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    53
  exit 1
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    54
}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    55
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    56
nice_exit () {
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
    57
  if [ -d ${tmp} ]; then
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
    58
    if [ "`ls ${tmp}`" != "" ]; then
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
    59
      wait
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
    60
    fi
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    61
  fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    62
  rm -f -r ${tmp}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    63
}
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    64
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    65
trap 'safe_interrupt' INT QUIT
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    66
trap 'nice_exit' EXIT
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
    67
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    68
# 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
    69
pull_default=""
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    70
repos=""
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    71
repos_extra=""
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    72
if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then
15903
bc0e6cd9d760 8008914: Add nashorn to the tl build
jjg
parents: 15575
diff changeset
    73
  subrepos="corba jaxp jaxws langtools jdk hotspot nashorn"
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    74
  if [ -f .hg/hgrc ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    75
    pull_default=`hg paths default`
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    76
    if [ "${pull_default}" = "" ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    77
      echo "ERROR: Need initial clone with 'hg paths default' defined"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    78
      exit 1
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
  fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    81
  if [ "${pull_default}" = "" ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    82
    echo "ERROR: Need initial repository to use this script"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    83
    exit 1
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    84
  fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    85
  for i in ${subrepos} ; do
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    86
    if [ ! -f ${i}/.hg/hgrc ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    87
      repos="${repos} ${i}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    88
    fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    89
  done
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    90
  if [ "${pull_extra_base}" != "" ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    91
    subrepos_extra="jdk/src/closed jdk/make/closed jdk/test/closed hotspot/make/closed hotspot/src/closed hotspot/test/closed deploy install sponsors pubs"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    92
    pull_default_tail=`echo ${pull_default} | sed -e 's@^.*://[^/]*/\(.*\)@\1@'`
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    93
    pull_extra="${pull_extra_base}/${pull_default_tail}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    94
    for i in ${subrepos_extra} ; do
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    95
      if [ ! -f ${i}/.hg/hgrc ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    96
        repos_extra="${repos_extra} ${i}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    97
      fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    98
    done
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
    99
  fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   100
  at_a_time=2
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   101
  # Any repos to deal with?
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   102
  if [ "${repos}" = "" -a "${repos_extra}" = "" ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   103
    exit
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   104
  fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   105
else
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   106
  hgdirs=`ls -d ./.hg ./*/.hg ./*/*/.hg ./*/*/*/.hg ./*/*/*/*/.hg 2>/dev/null`
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   107
  # Derive repository names from the .hg directory locations
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   108
  for i in ${hgdirs} ; do
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   109
    repos="${repos} `echo ${i} | sed -e 's@/.hg$@@'`"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   110
  done
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   111
  for i in ${repos} ; do
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   112
    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
   113
      locked="${i} ${locked}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   114
    fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   115
  done
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   116
  at_a_time=8
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   117
  # Any repos to deal with?
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   118
  if [ "${repos}" = "" ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   119
    echo "No repositories to process."
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   120
    exit
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   121
  fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   122
  if [ "${locked}" != "" ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   123
    echo "These repositories are locked: ${locked}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   124
    exit
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   125
  fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   126
fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   127
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   128
# Echo out what repositories we do a command on.
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   129
echo "# Repositories: ${repos} ${repos_extra}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   130
echo
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   131
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   132
# Run the supplied command on all repos in parallel.
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   133
n=0
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   134
for i in ${repos} ${repos_extra} ; do
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   135
  n=`expr ${n} '+' 1`
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   136
  repopidfile=`echo ${i} | sed -e 's@./@@' -e 's@/@_@g'`
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   137
  reponame=`echo ${i} | sed -e :a -e 's/^.\{1,20\}$/ &/;ta'`
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   138
  pull_base="${pull_default}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   139
  for j in $repos_extra ; do
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   140
      if [ "$i" = "$j" ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   141
          pull_base="${pull_extra}"
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   142
      fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   143
  done
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
      if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   147
        pull_newrepo="`echo ${pull_base}/${i} | sed -e 's@\([^:]/\)//*@\1@g'`"
20631
6f71614260ea 8025796: hgforest.sh could trigger unbuffered output from hg without complicated machinations
mduigou
parents: 19752
diff changeset
   148
        echo hg clone ${pull_newrepo} ${i}
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   149
        path="`dirname ${i}`"
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   150
        if [ "${path}" != "." ] ; then
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   151
          times=0
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   152
          while [ ! -d "${path}" ]   ## nested repo, ensure containing dir exists
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   153
          do
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   154
            times=`expr ${times} '+' 1`
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   155
            if [ `expr ${times} '%' 10` -eq 0 ] ; then
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   156
              echo ${path} still not created, waiting...
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   157
            fi
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   158
            sleep 5
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   159
          done
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   160
        fi
20631
6f71614260ea 8025796: hgforest.sh could trigger unbuffered output from hg without complicated machinations
mduigou
parents: 19752
diff changeset
   161
        (PYTHONUNBUFFERED=true hg clone ${pull_newrepo} ${i}; echo "$?" > ${tmp}/${repopidfile}.pid.rc )&
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   162
      else
20631
6f71614260ea 8025796: hgforest.sh could trigger unbuffered output from hg without complicated machinations
mduigou
parents: 19752
diff changeset
   163
        echo "cd ${i} && hg $*"
6f71614260ea 8025796: hgforest.sh could trigger unbuffered output from hg without complicated machinations
mduigou
parents: 19752
diff changeset
   164
        cd ${i} && (PYTHONUNBUFFERED=true hg "$@"; echo "$?" > ${tmp}/${repopidfile}.pid.rc )&
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   165
      fi
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   166
      echo $! > ${tmp}/${repopidfile}.pid
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   167
    ) 2>&1 | sed -e "s@^@${reponame}:   @") &
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   168
14735
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   169
  if [ `expr ${n} '%' ${at_a_time}` -eq 0 ] ; then
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   170
    sleep 2
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   171
    echo Waiting 5 secs before spawning next background command.
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   172
    sleep 3
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   173
  fi
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   174
done
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   175
# Wait for all hg commands to complete
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   176
wait
804551752e64 8004145: New improved hgforest.sh, ctrl-c now properly terminates mercurial processes.
ohrstrom
parents:
diff changeset
   177
15575
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   178
# 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
   179
ec=0
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   180
if [ -d ${tmp} ]; then
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   181
  for rc in ${tmp}/*.pid.rc ; do
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   182
    exit_code=`cat ${rc} | tr -d ' \n\r'`
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   183
    if [ "${exit_code}" != "0" ] ; then
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   184
      echo "WARNING: ${rc} exited abnormally."
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   185
      ec=1
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   186
    fi
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   187
  done
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   188
fi
75a4e041b420 8007625: race with nested repos in /common/bin/hgforest.sh
chegar
parents: 14735
diff changeset
   189
exit ${ec}