2008-08-04 12:09:54 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# Yes, this intends to be a true POSIX script file.
|
2009-01-29 19:00:08 +00:00
|
|
|
set -e
|
2008-08-04 12:09:54 +00:00
|
|
|
|
|
|
|
myname="$0"
|
|
|
|
|
2009-01-29 19:00:08 +00:00
|
|
|
# Parse the tools' paths configuration
|
|
|
|
. "paths.mk"
|
|
|
|
|
2008-08-04 12:09:54 +00:00
|
|
|
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}"
|
|
|
|
|
2009-10-10 15:19:51 +00:00
|
|
|
case "$(LC_ALL=C hg id "${dir}" 2>/dev/null)" in
|
|
|
|
"") CMD="mv -v";;
|
|
|
|
*) CMD="hg mv";;
|
2008-08-04 12:09:54 +00:00
|
|
|
esac
|
|
|
|
|
|
|
|
for p in "${dir}"/*.patch; do
|
|
|
|
[ -e "${p}" ] || { echo "No such file '${p}'"; exit 1; }
|
2009-02-01 23:15:59 +00:00
|
|
|
newname="$(printf "%03d-%s" \
|
|
|
|
"${cpt}" \
|
|
|
|
"$(basename "${p}" \
|
|
|
|
|"${sed}" -r -e 's/^[[:digit:]]+[-_]//' \
|
|
|
|
)" \
|
|
|
|
)"
|
2008-08-04 12:09:54 +00:00
|
|
|
[ "${p}" = "${dir}/${newname}" ] || ${CMD} "${p}" "${dir}/${newname}"
|
|
|
|
cpt=$((cpt+inc))
|
|
|
|
done
|