scripts/patch-renumber.sh
author "Frederic Roussel" <fr.frasc@gmail.com>
Wed Nov 11 14:44:53 2009 -0800 (2009-11-11)
changeset 1621 60446d2e5660
parent 1577 c774b2cc7863
child 1622 9ad2a3fd1fcc
permissions -rwxr-xr-x
patches/binutils/2.20: make patches appliable

Fix filenames in patch files for binutils-2.20.
Some patch files were only usable with patch argument '-p0'.
Fix the diff context to match 2.20 release.

Signed-off-by: Frederic Roussel <fr.frasc@gmail.com>
     1 #!/bin/sh
     2 # Yes, this intends to be a true POSIX script file.
     3 set -e
     4 
     5 myname="$0"
     6 
     7 # Parse the tools' paths configuration
     8 . "paths.mk"
     9 
    10 doUsage() {
    11   cat <<_EOF_
    12 Usage: ${myname} <dir> <base> <inc> [sed_re]
    13     Will renumber all patches found in 'dir', starting at 'base', and with
    14     an increment of 'inc'.
    15     If 'sed_re' is given, it is interpreted as a valid sed expression, and
    16     it will be applied to the patch name.
    17     If the environment variable FAKE is set to 'y', then the command will
    18     only be printed, and not executed (so you can check beforehand).
    19     Eg.:
    20       patch-renumber.sh patches/gcc/4.3.1 100 10
    21       patch-renumber.sh patches/gcc/4.2.4 100 10 's/(all[_-])*(gcc[-_])*//;'
    22 _EOF_
    23 }
    24 
    25 [ $# -lt 3 -o $# -gt 4 ] && { doUsage; exit 1; }
    26 [ -d "${1}" ] || { doUsage; exit 1; }
    27 
    28 dir="${1}"
    29 cpt="${2}"
    30 inc="${3}"
    31 sed_re="${4}"
    32 
    33 case "$(LC_ALL=C hg id "${dir}" 2>/dev/null)" in
    34     "") CMD="";;
    35     *)  CMD="hg";;
    36 esac
    37 
    38 if [ "${FAKE}" = "y" ]; then
    39     CMD="echo ${CMD}"
    40 fi
    41 
    42 for p in "${dir}"/*.patch*; do
    43     [ -e "${p}" ] || { echo "No such file '${p}'"; exit 1; }
    44     newname="$(printf "%03d-%s"                                     \
    45                       "${cpt}"                                      \
    46                       "$( basename "${p}"                           \
    47                           |"${sed}" -r -e 's/^[[:digit:]]+[-_]//'   \
    48                                        -e "${sed_re}"               \
    49                         )"                                          \
    50               )"
    51     [ "${p}" = "${dir}/${newname}" ] || ${CMD} mv -v "${p}" "${dir}/${newname}"
    52     cpt=$((cpt+inc))
    53 done