scripts/patch-renumber.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Feb 01 23:15:59 2009 +0000 (2009-02-01)
changeset 1192 bc411ace3c8f
parent 1175 417b32da90bf
child 1577 c774b2cc7863
permissions -rwxr-xr-x
Fix patch-renumber:
- look at the patch directory when using svnversion, not at current directory
- some code beautification.

/trunk/scripts/patch-renumber.sh | 9 7 2 0 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
yann@756
     1
#!/bin/sh
yann@756
     2
# Yes, this intends to be a true POSIX script file.
yann@1175
     3
set -e
yann@756
     4
yann@756
     5
myname="$0"
yann@756
     6
yann@1175
     7
# Parse the tools' paths configuration
yann@1175
     8
. "paths.mk"
yann@1175
     9
yann@756
    10
doUsage() {
yann@756
    11
  cat <<_EOF_
yann@756
    12
Usage: ${myname} <dir> <base> <inc>
yann@756
    13
    Will renumber all patches found in <dir>, starting at <base>, and with
yann@756
    14
    an increment of <inc>
yann@756
    15
    Eg.: patch-renumber patches/gcc/4.3.1 100 10
yann@756
    16
_EOF_
yann@756
    17
}
yann@756
    18
yann@756
    19
[ $# -eq 3 ] || { doUsage; exit 1; }
yann@756
    20
[ -d "${1}" ] || { doUsage; exit 1; }
yann@756
    21
yann@756
    22
dir="${1}"
yann@756
    23
cpt="${2}"
yann@756
    24
inc="${3}"
yann@756
    25
yann@1192
    26
case "$(LC_ALL=C svnversion "${dir}" 2>/dev/null)" in
yann@756
    27
    exported)   CMD="mv -v";;
yann@756
    28
    *)          CMD="svn mv";;
yann@756
    29
esac
yann@756
    30
yann@756
    31
for p in "${dir}"/*.patch; do
yann@756
    32
    [ -e "${p}" ] || { echo "No such file '${p}'"; exit 1; }
yann@1192
    33
    newname="$(printf "%03d-%s"                                 \
yann@1192
    34
                      "${cpt}"                                  \
yann@1192
    35
                      "$(basename "${p}"                        \
yann@1192
    36
                        |"${sed}" -r -e 's/^[[:digit:]]+[-_]//' \
yann@1192
    37
                       )"                                       \
yann@1192
    38
              )"
yann@756
    39
    [ "${p}" = "${dir}/${newname}" ] || ${CMD} "${p}" "${dir}/${newname}"
yann@756
    40
    cpt=$((cpt+inc))
yann@756
    41
done