scripts/patch-renumber.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Fri Oct 30 19:49:51 2009 +0100 (2009-10-30)
changeset 1618 7f52e1cca71e
parent 1577 c774b2cc7863
child 1622 9ad2a3fd1fcc
permissions -rwxr-xr-x
scripts: fix updating config.{sub,guess}
     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