# HG changeset patch # User "Yann E. MORIN" # Date 1257877931 -3600 # Node ID 9ad2a3fd1fcc4fc11dd6c285485e608c3fcf7e3a # Parent 60446d2e5660ca85a6f1b31bc2abf30b98657f0b scripts: output renumbered patches in a new directory When renumbering patches, the original patches get removed and replaced with the new ones. This can be annoying to loose the original patches. Fix this by putting the new patchs in a directory of their own. diff -r 60446d2e5660 -r 9ad2a3fd1fcc scripts/patch-renumber.sh --- a/scripts/patch-renumber.sh Wed Nov 11 14:44:53 2009 -0800 +++ b/scripts/patch-renumber.sh Tue Nov 10 19:32:11 2009 +0100 @@ -9,37 +9,47 @@ doUsage() { cat <<_EOF_ -Usage: ${myname} [sed_re] - Will renumber all patches found in 'dir', starting at 'base', and with - an increment of 'inc'. +Usage: ${myname} [sed_re] + Renumbers all patches found in 'src_dir', starting at 'base', with an + increment of 'inc', and puts the renumbered patches in 'dst_dir'. + Leading digits are replaced with the new indexes, and a subsequent '_' + is replaced with a '-'. If 'sed_re' is given, it is interpreted as a valid sed expression, and - it will be applied to the patch name. - If the environment variable FAKE is set to 'y', then the command will - only be printed, and not executed (so you can check beforehand). + is be applied to the patch name. + If the environment variable FAKE is set to 'y', then nothing gets done, + the command to run is only be printed, and not executed (so you can + check beforehand). + 'dst_dir' must not yet exist. Eg.: - patch-renumber.sh patches/gcc/4.3.1 100 10 - patch-renumber.sh patches/gcc/4.2.4 100 10 's/(all[_-])*(gcc[-_])*//;' + patch-renumber.sh patches/gcc/4.2.3 patches/gcc/4.2.4 100 10 + patch-renumber.sh /some/dir/my-patches patches/gcc/4.3.1 100 10 's/(all[_-])*(gcc[-_])*//;' _EOF_ } -[ $# -lt 3 -o $# -gt 4 ] && { doUsage; exit 1; } -[ -d "${1}" ] || { doUsage; exit 1; } +[ $# -lt 4 -o $# -gt 5 ] && { doUsage; exit 1; } -dir="${1}" -cpt="${2}" -inc="${3}" -sed_re="${4}" - -case "$(LC_ALL=C hg id "${dir}" 2>/dev/null)" in - "") CMD="";; - *) CMD="hg";; -esac - -if [ "${FAKE}" = "y" ]; then - CMD="echo ${CMD}" +src="${1}" +dst="${2}" +cpt="${3}" +inc="${4}" +sed_re="${5}" +if [ ! -d "${src}" ]; then + printf "%s: '%s': not a directory\n" "${myname}" "${src}" + exit 1 +fi +if [ -d "${dst}" ]; then + printf "%s: '%s': directory already exists\n" "${myname}" "${dst}" + exit 1 fi -for p in "${dir}"/*.patch*; do +Q= +if [ -n "${FAKE}" ]; then + printf "%s: won't do anything: FAKE='%s'\n" "${myname}" "${FAKE}" + Q="echo" +fi + +${Q} mkdir -pv "${dst}" +for p in "${src}/"*.patch*; do [ -e "${p}" ] || { echo "No such file '${p}'"; exit 1; } newname="$(printf "%03d-%s" \ "${cpt}" \ @@ -48,6 +58,6 @@ -e "${sed_re}" \ )" \ )" - [ "${p}" = "${dir}/${newname}" ] || ${CMD} mv -v "${p}" "${dir}/${newname}" + ${Q} cp -v "${p}" "${dst}/${newname}" cpt=$((cpt+inc)) done