mirror of
https://github.com/crosstool-ng/crosstool-ng.git
synced 2025-02-21 01:21:27 +00:00
scripts: add sed expression to apply when renumbering patches
Some patchsets have superfluous members in their names (eg. the ones coming from Gentoo), so it can come in handy to pass a sed RE to strip them out of the final patch name. Also add a 'fake' mode, where the command will only be printed and not executed, so we can check beforehand if the rename will be OK.
This commit is contained in:
parent
039ee6c125
commit
d28227a914
@ -9,33 +9,45 @@ myname="$0"
|
||||
|
||||
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
|
||||
Usage: ${myname} <dir> <base> <inc> [sed_re]
|
||||
Will renumber all patches found in 'dir', starting at 'base', and with
|
||||
an increment of 'inc'.
|
||||
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).
|
||||
Eg.:
|
||||
patch-renumber.sh patches/gcc/4.3.1 100 10
|
||||
patch-renumber.sh patches/gcc/4.2.4 100 10 's/(all[_-])*(gcc[-_])*//;'
|
||||
_EOF_
|
||||
}
|
||||
|
||||
[ $# -eq 3 ] || { doUsage; exit 1; }
|
||||
[ $# -lt 3 -o $# -gt 4 ] && { doUsage; exit 1; }
|
||||
[ -d "${1}" ] || { doUsage; exit 1; }
|
||||
|
||||
dir="${1}"
|
||||
cpt="${2}"
|
||||
inc="${3}"
|
||||
sed_re="${4}"
|
||||
|
||||
case "$(LC_ALL=C hg id "${dir}" 2>/dev/null)" in
|
||||
"") CMD="mv -v";;
|
||||
*) CMD="hg mv";;
|
||||
"") CMD="";;
|
||||
*) CMD="hg";;
|
||||
esac
|
||||
|
||||
for p in "${dir}"/*.patch; do
|
||||
if [ "${FAKE}" = "y" ]; then
|
||||
CMD="echo ${CMD}"
|
||||
fi
|
||||
|
||||
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:]]+[-_]//' \
|
||||
)" \
|
||||
newname="$(printf "%03d-%s" \
|
||||
"${cpt}" \
|
||||
"$( basename "${p}" \
|
||||
|"${sed}" -r -e 's/^[[:digit:]]+[-_]//' \
|
||||
-e "${sed_re}" \
|
||||
)" \
|
||||
)"
|
||||
[ "${p}" = "${dir}/${newname}" ] || ${CMD} "${p}" "${dir}/${newname}"
|
||||
[ "${p}" = "${dir}/${newname}" ] || ${CMD} mv -v "${p}" "${dir}/${newname}"
|
||||
cpt=$((cpt+inc))
|
||||
done
|
||||
|
Loading…
x
Reference in New Issue
Block a user