summaryrefslogtreecommitdiff
path: root/scripts/patch-renumber.sh
blob: f670b90a431d1bb3679b311a841af4c50a13e9fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/sh
# Yes, this intends to be a true POSIX script file.
set -e

myname="$0"

# Parse the tools' paths configuration
. "paths.mk"

doUsage() {
  cat <<_EOF_
Usage: ${myname} <dir> <base> <inc>
    Will renumber all patches found in <dir>, starting at <base>, and with
    an increment of <inc>
    Eg.: patch-renumber patches/gcc/4.3.1 100 10
_EOF_
}

[ $# -eq 3 ] || { doUsage; exit 1; }
[ -d "${1}" ] || { doUsage; exit 1; }

dir="${1}"
cpt="${2}"
inc="${3}"

case "$(LC_ALL=C svnversion "${dir}" 2>/dev/null)" in
    exported)   CMD="mv -v";;
    *)          CMD="svn mv";;
esac

for p in "${dir}"/*.patch; do
    [ -e "${p}" ] || { echo "No such file '${p}'"; exit 1; }
    newname="$(printf "%03d-%s"                                 \
                      "${cpt}"                                  \
                      "$(basename "${p}"                        \
                        |"${sed}" -r -e 's/^[[:digit:]]+[-_]//' \
                       )"                                       \
              )"
    [ "${p}" = "${dir}/${newname}" ] || ${CMD} "${p}" "${dir}/${newname}"
    cpt=$((cpt+inc))
done