1.1 --- a/scripts/patch-renumber.sh Wed Nov 11 14:44:53 2009 -0800
1.2 +++ b/scripts/patch-renumber.sh Tue Nov 10 19:32:11 2009 +0100
1.3 @@ -9,37 +9,47 @@
1.4
1.5 doUsage() {
1.6 cat <<_EOF_
1.7 -Usage: ${myname} <dir> <base> <inc> [sed_re]
1.8 - Will renumber all patches found in 'dir', starting at 'base', and with
1.9 - an increment of 'inc'.
1.10 +Usage: ${myname} <src_dir> <dst_dir> <base> <inc> [sed_re]
1.11 + Renumbers all patches found in 'src_dir', starting at 'base', with an
1.12 + increment of 'inc', and puts the renumbered patches in 'dst_dir'.
1.13 + Leading digits are replaced with the new indexes, and a subsequent '_'
1.14 + is replaced with a '-'.
1.15 If 'sed_re' is given, it is interpreted as a valid sed expression, and
1.16 - it will be applied to the patch name.
1.17 - If the environment variable FAKE is set to 'y', then the command will
1.18 - only be printed, and not executed (so you can check beforehand).
1.19 + is be applied to the patch name.
1.20 + If the environment variable FAKE is set to 'y', then nothing gets done,
1.21 + the command to run is only be printed, and not executed (so you can
1.22 + check beforehand).
1.23 + 'dst_dir' must not yet exist.
1.24 Eg.:
1.25 - patch-renumber.sh patches/gcc/4.3.1 100 10
1.26 - patch-renumber.sh patches/gcc/4.2.4 100 10 's/(all[_-])*(gcc[-_])*//;'
1.27 + patch-renumber.sh patches/gcc/4.2.3 patches/gcc/4.2.4 100 10
1.28 + patch-renumber.sh /some/dir/my-patches patches/gcc/4.3.1 100 10 's/(all[_-])*(gcc[-_])*//;'
1.29 _EOF_
1.30 }
1.31
1.32 -[ $# -lt 3 -o $# -gt 4 ] && { doUsage; exit 1; }
1.33 -[ -d "${1}" ] || { doUsage; exit 1; }
1.34 +[ $# -lt 4 -o $# -gt 5 ] && { doUsage; exit 1; }
1.35
1.36 -dir="${1}"
1.37 -cpt="${2}"
1.38 -inc="${3}"
1.39 -sed_re="${4}"
1.40 -
1.41 -case "$(LC_ALL=C hg id "${dir}" 2>/dev/null)" in
1.42 - "") CMD="";;
1.43 - *) CMD="hg";;
1.44 -esac
1.45 -
1.46 -if [ "${FAKE}" = "y" ]; then
1.47 - CMD="echo ${CMD}"
1.48 +src="${1}"
1.49 +dst="${2}"
1.50 +cpt="${3}"
1.51 +inc="${4}"
1.52 +sed_re="${5}"
1.53 +if [ ! -d "${src}" ]; then
1.54 + printf "%s: '%s': not a directory\n" "${myname}" "${src}"
1.55 + exit 1
1.56 +fi
1.57 +if [ -d "${dst}" ]; then
1.58 + printf "%s: '%s': directory already exists\n" "${myname}" "${dst}"
1.59 + exit 1
1.60 fi
1.61
1.62 -for p in "${dir}"/*.patch*; do
1.63 +Q=
1.64 +if [ -n "${FAKE}" ]; then
1.65 + printf "%s: won't do anything: FAKE='%s'\n" "${myname}" "${FAKE}"
1.66 + Q="echo"
1.67 +fi
1.68 +
1.69 +${Q} mkdir -pv "${dst}"
1.70 +for p in "${src}/"*.patch*; do
1.71 [ -e "${p}" ] || { echo "No such file '${p}'"; exit 1; }
1.72 newname="$(printf "%03d-%s" \
1.73 "${cpt}" \
1.74 @@ -48,6 +58,6 @@
1.75 -e "${sed_re}" \
1.76 )" \
1.77 )"
1.78 - [ "${p}" = "${dir}/${newname}" ] || ${CMD} mv -v "${p}" "${dir}/${newname}"
1.79 + ${Q} cp -v "${p}" "${dst}/${newname}"
1.80 cpt=$((cpt+inc))
1.81 done