bin/unshuffle_patch.sh
author rkennke
Wed, 25 Oct 2017 10:05:17 +0200
changeset 47819 ee36a8e36561
parent 47217 72e3ae9a25eb
permissions -rw-r--r--
8183542: Factor out serial GC specific code from GenCollectedHeap into its own subclass Reviewed-by: kbarrett, jgeorge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47217
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
     1
#!/bin/bash
25854
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
     2
#
47217
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
     3
# Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
25854
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
     4
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
     5
#
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
     6
# This code is free software; you can redistribute it and/or modify it
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
     7
# under the terms of the GNU General Public License version 2 only, as
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
     8
# published by the Free Software Foundation.
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
     9
#
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    10
# This code is distributed in the hope that it will be useful, but WITHOUT
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    11
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    12
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    13
# version 2 for more details (a copy is included in the LICENSE file that
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    14
# accompanied this code).
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    15
#
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    16
# You should have received a copy of the GNU General Public License version
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    17
# 2 along with this work; if not, write to the Free Software Foundation,
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    18
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    19
#
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    20
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    21
# or visit www.oracle.com if you need additional information or have any
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    22
# questions.
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    23
#
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    24
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    25
# Script for updating a patch file as per the shuffled/unshuffled source location.
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    26
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    27
usage() {
47217
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
    28
  echo "Usage: $0 [-h|--help] [-v|--verbose] [-to9|-to10] [-r <repo>] <input_patch> <output_patch>"
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
    29
  echo "where:"
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
    30
  echo "  -to9            create patches appropriate for a JDK 9 source tree"
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
    31
  echo "                  When going to 9, the output patches will be suffixed with the"
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
    32
  echo "                  repo name"
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
    33
  echo "  -to10           create patches appropriate for a JDK 10 source tree"
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
    34
  echo "  -r <repo>       specify repo for source patch, set to 'top' for top repo"
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
    35
  echo "  <input_patch>   is the input patch file, that needs shuffling/unshuffling"
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
    36
  echo "  <output_patch>  is the updated patch file "
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
    37
  echo " "
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
    38
  exit 1
25854
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    39
}
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    40
26674
b002f9eb2b5e 8059101: unshuffle_patch.sh should be able to deal with stdin/stdout
igerasim
parents: 25854
diff changeset
    41
SCRIPT_DIR=`dirname $0`
25854
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    42
UNSHUFFLE_LIST=$SCRIPT_DIR"/unshuffle_list.txt"
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    43
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    44
if [ ! -f "$UNSHUFFLE_LIST" ] ; then
26674
b002f9eb2b5e 8059101: unshuffle_patch.sh should be able to deal with stdin/stdout
igerasim
parents: 25854
diff changeset
    45
  echo "FATAL: cannot find $UNSHUFFLE_LIST" >&2
25854
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    46
  exit 1
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    47
fi
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    48
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    49
vflag="false"
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    50
while [ $# -gt 0 ]
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    51
do
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    52
  case $1 in
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    53
    -h | --help )
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    54
      usage
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    55
      ;;
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    56
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    57
    -v | --verbose )
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    58
      vflag="true"
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    59
      ;;
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    60
47217
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
    61
    -r)
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
    62
      repo="$2"
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
    63
      shift
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
    64
      ;;
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
    65
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
    66
    -to9)
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
    67
      shuffle_to=9
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
    68
      ;;
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
    69
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
    70
    -to10)
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
    71
      shuffle_to=10
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
    72
      ;;
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
    73
25854
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    74
    -*)  # bad option
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    75
      usage
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    76
      ;;
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    77
47217
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
    78
    * )  # non option
25854
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    79
      break
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    80
      ;;
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    81
  esac
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    82
  shift
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    83
done
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    84
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    85
# Make sure we have the right number of arguments
47217
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
    86
if [ ! $# -eq 2 ] ; then
26674
b002f9eb2b5e 8059101: unshuffle_patch.sh should be able to deal with stdin/stdout
igerasim
parents: 25854
diff changeset
    87
  echo "ERROR: Invalid number of arguments." >&2
25854
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    88
  usage
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    89
fi
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    90
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    91
# Check the given repo
47217
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
    92
repos="top corba jaxp jaxws jdk langtools nashorn hotspot"
25854
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
    93
found="false"
47217
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
    94
if [ -n "$repo" ]; then
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
    95
  for r in $repos ; do
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
    96
    if [ $repo = "$r" ] ; then
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
    97
      found="true"
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
    98
      break;
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
    99
    fi
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   100
  done
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   101
  if [ $found = "false" ] ; then
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   102
    echo "ERROR: Unknown repo: $repo. Should be one of [$repos]." >&2
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   103
    usage
27595
cff167b3bfa2 8065914: Various improvements and cleanup of build system
ihse
parents: 26674
diff changeset
   104
  fi
47217
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   105
fi
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   106
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   107
if [ "$shuffle_to" != "9" -a "$shuffle_to" != "10" ]; then
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   108
  echo "ERROR: Must pick either -to9 or -to10"
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   109
  exit 1
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   110
fi
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   111
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   112
# When going to 10, a repo must be specified for the source patch
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   113
if [ "$shuffle_to" = "10" -a -z "$repo" ]; then
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   114
  echo "ERROR: Must specify src repo for JDK 9 patch"
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   115
  exit 1
25854
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   116
fi
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   117
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   118
# Check given input/output files
47217
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   119
input="$1"
26674
b002f9eb2b5e 8059101: unshuffle_patch.sh should be able to deal with stdin/stdout
igerasim
parents: 25854
diff changeset
   120
if [ "x$input" = "x-" ] ; then
b002f9eb2b5e 8059101: unshuffle_patch.sh should be able to deal with stdin/stdout
igerasim
parents: 25854
diff changeset
   121
  input="/dev/stdin"
b002f9eb2b5e 8059101: unshuffle_patch.sh should be able to deal with stdin/stdout
igerasim
parents: 25854
diff changeset
   122
fi
25854
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   123
26674
b002f9eb2b5e 8059101: unshuffle_patch.sh should be able to deal with stdin/stdout
igerasim
parents: 25854
diff changeset
   124
if [ ! -f $input -a "x$input" != "x/dev/stdin" ] ; then
b002f9eb2b5e 8059101: unshuffle_patch.sh should be able to deal with stdin/stdout
igerasim
parents: 25854
diff changeset
   125
  echo "ERROR: Cannot find input patch file: $input" >&2
25854
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   126
  exit 1
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   127
fi
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   128
47217
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   129
output="$2"
26674
b002f9eb2b5e 8059101: unshuffle_patch.sh should be able to deal with stdin/stdout
igerasim
parents: 25854
diff changeset
   130
if [ "x$output" = "x-" ] ; then
b002f9eb2b5e 8059101: unshuffle_patch.sh should be able to deal with stdin/stdout
igerasim
parents: 25854
diff changeset
   131
  output="/dev/stdout"
b002f9eb2b5e 8059101: unshuffle_patch.sh should be able to deal with stdin/stdout
igerasim
parents: 25854
diff changeset
   132
fi
47217
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   133
base_output="$output"
26674
b002f9eb2b5e 8059101: unshuffle_patch.sh should be able to deal with stdin/stdout
igerasim
parents: 25854
diff changeset
   134
47217
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   135
if [ "$shuffle_to" = "10" ]; then
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   136
  if [ -f $output -a "x$output" != "x/dev/stdout" ] ; then
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   137
    echo "ERROR: Output patch already exists: $output" >&2
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   138
    exit 1
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   139
  fi
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   140
else
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   141
  for r in $repos; do
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   142
    if [ -f "$output.$r" ]; then
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   143
      echo "ERROR: Output patch already exists: $output.$r" >&2
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   144
      exit 1
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   145
    fi
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   146
  done
25854
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   147
fi
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   148
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   149
verbose() {
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   150
  if [ ${vflag} = "true" ] ; then
26674
b002f9eb2b5e 8059101: unshuffle_patch.sh should be able to deal with stdin/stdout
igerasim
parents: 25854
diff changeset
   151
    echo "$@" >&2
25854
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   152
  fi
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   153
}
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   154
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   155
unshuffle() {
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   156
  line=$@
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   157
  verbose "Attempting to rewrite: \"$line\""
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   158
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   159
  # Retrieve the file name
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   160
  path=
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   161
  if echo "$line" | egrep '^diff' > /dev/null ; then
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   162
    if ! echo "$line" | egrep '\-\-git' > /dev/null ; then
26674
b002f9eb2b5e 8059101: unshuffle_patch.sh should be able to deal with stdin/stdout
igerasim
parents: 25854
diff changeset
   163
      echo "ERROR: Only git patches supported. Please use 'hg export --git ...'." >&2
25854
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   164
      exit 1
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   165
    fi
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   166
    path="`echo "$line" | sed -e s@'diff --git a/'@@ -e s@' b/.*$'@@`"
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   167
  elif echo "$line" | egrep '^\-\-\-' > /dev/null ; then
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   168
    path="`echo "$line" | sed -e s@'--- a/'@@`"
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   169
  elif echo "$line" | egrep '^\+\+\+' > /dev/null ; then
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   170
    path="`echo "$line" | sed s@'+++ b/'@@`"
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   171
  fi
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   172
  verbose "Extracted path: \"$path\""
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   173
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   174
  # Find the most specific matches in the shuffle list
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   175
  matches=
47217
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   176
  if [ -n "$repo" -a "$repo" != "top" ]; then
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   177
    matchpath="$repo"/"$path"/x
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   178
  else
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   179
    matchpath="$path"/x
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   180
  fi
25854
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   181
  while [ "$matchpath" != "" ] ; do
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   182
    matchpath="`echo $matchpath | sed s@'\(.*\)/.*$'@'\1'@`"
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   183
47217
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   184
    if [ "$shuffle_to" =  "10" ] ; then
25854
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   185
      pattern=": $matchpath$"
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   186
    else
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   187
      pattern="^$matchpath :"
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   188
    fi
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   189
    verbose "Attempting to find \"$matchpath\""
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   190
    matches=`egrep "$pattern" "$UNSHUFFLE_LIST"`
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   191
    if ! [ "x${matches}" = "x" ] ; then
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   192
      verbose "Got matches: [$matches]"
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   193
      break;
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   194
    fi
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   195
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   196
    if ! echo "$matchpath" | egrep '.*/.*' > /dev/null ; then
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   197
      break;
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   198
    fi
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   199
  done
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   200
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   201
  # Rewrite the line, if we have a match
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   202
  if ! [ "x${matches}" = "x" ] ; then
47217
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   203
    shuffled="${matches%% : *}"
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   204
    unshuffled="${matches#* : }"
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   205
    patch_suffix_9=""
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   206
    for r in $repos; do
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   207
      if [ "$unshuffled" != "${unshuffled#$r}" ]; then
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   208
        unshuffled="${unshuffled#$r\/}"
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   209
        patch_suffix_9=".$r"
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   210
      fi
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   211
    done
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   212
    verbose "shuffled: $shuffled"
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   213
    verbose "unshuffled: $unshuffled"
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   214
    verbose "patch_suffix_9: $patch_suffix_9"
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   215
    if [ "$shuffle_to" =  "10" ] ; then
25854
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   216
      newline="`echo "$line" | sed -e s@"$unshuffled"@"$shuffled"@g`"
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   217
    else
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   218
      newline="`echo "$line" | sed -e s@"$shuffled"@"$unshuffled"@g`"
47217
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   219
      output=$base_output$patch_suffix_9
72e3ae9a25eb 8187444: Forest Consolidation: Make build work
erikj
parents: 47216
diff changeset
   220
      verbose "Writing to $output"
25854
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   221
    fi
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   222
    verbose "Rewriting to \"$newline\""
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   223
    echo "$newline" >> $output
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   224
  else
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   225
    echo "WARNING: no match found for $path"
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   226
    echo "$line" >> $output
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   227
  fi
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   228
}
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   229
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   230
while IFS= read -r line
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   231
do
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   232
  if echo "$line" | egrep '^diff|^\-\-\-|^\+\+\+' > /dev/null ; then
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   233
    unshuffle "$line"
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   234
  else
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   235
    printf "%s\n" "$line" >> $output
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   236
  fi
98ce0879ab4c 8054834: Modular Source Code
chegar
parents:
diff changeset
   237
done < "$input"