1.1 --- a/scripts/patch-renumber.sh Sat Oct 10 17:19:51 2009 +0200
1.2 +++ b/scripts/patch-renumber.sh Mon Nov 16 20:24:03 2009 +0100
1.3 @@ -9,33 +9,45 @@
1.4
1.5 doUsage() {
1.6 cat <<_EOF_
1.7 -Usage: ${myname} <dir> <base> <inc>
1.8 - Will renumber all patches found in <dir>, starting at <base>, and with
1.9 - an increment of <inc>
1.10 - Eg.: patch-renumber patches/gcc/4.3.1 100 10
1.11 +Usage: ${myname} <dir> <base> <inc> [sed_re]
1.12 + Will renumber all patches found in 'dir', starting at 'base', and with
1.13 + an increment of 'inc'.
1.14 + If 'sed_re' is given, it is interpreted as a valid sed expression, and
1.15 + it will be applied to the patch name.
1.16 + If the environment variable FAKE is set to 'y', then the command will
1.17 + only be printed, and not executed (so you can check beforehand).
1.18 + Eg.:
1.19 + patch-renumber.sh patches/gcc/4.3.1 100 10
1.20 + patch-renumber.sh patches/gcc/4.2.4 100 10 's/(all[_-])*(gcc[-_])*//;'
1.21 _EOF_
1.22 }
1.23
1.24 -[ $# -eq 3 ] || { doUsage; exit 1; }
1.25 +[ $# -lt 3 -o $# -gt 4 ] && { doUsage; exit 1; }
1.26 [ -d "${1}" ] || { doUsage; exit 1; }
1.27
1.28 dir="${1}"
1.29 cpt="${2}"
1.30 inc="${3}"
1.31 +sed_re="${4}"
1.32
1.33 case "$(LC_ALL=C hg id "${dir}" 2>/dev/null)" in
1.34 - "") CMD="mv -v";;
1.35 - *) CMD="hg mv";;
1.36 + "") CMD="";;
1.37 + *) CMD="hg";;
1.38 esac
1.39
1.40 -for p in "${dir}"/*.patch; do
1.41 +if [ "${FAKE}" = "y" ]; then
1.42 + CMD="echo ${CMD}"
1.43 +fi
1.44 +
1.45 +for p in "${dir}"/*.patch*; do
1.46 [ -e "${p}" ] || { echo "No such file '${p}'"; exit 1; }
1.47 - newname="$(printf "%03d-%s" \
1.48 - "${cpt}" \
1.49 - "$(basename "${p}" \
1.50 - |"${sed}" -r -e 's/^[[:digit:]]+[-_]//' \
1.51 - )" \
1.52 + newname="$(printf "%03d-%s" \
1.53 + "${cpt}" \
1.54 + "$( basename "${p}" \
1.55 + |"${sed}" -r -e 's/^[[:digit:]]+[-_]//' \
1.56 + -e "${sed_re}" \
1.57 + )" \
1.58 )"
1.59 - [ "${p}" = "${dir}/${newname}" ] || ${CMD} "${p}" "${dir}/${newname}"
1.60 + [ "${p}" = "${dir}/${newname}" ] || ${CMD} mv -v "${p}" "${dir}/${newname}"
1.61 cpt=$((cpt+inc))
1.62 done