[OpenWrt-Devel] [PATCH] scripts: add a new patch-rename.sh script
Mathieu Olivari
mathieu at codeaurora.org
Wed Aug 5 20:10:56 EDT 2015
During quilt based development, it is sometimes necessary to reorder
patch files, which can become a tedious process as the patch list gets
bigger. This script can help when doing such operations, by allowing to
increment or decrement the number of multiple patch files at once:
$ ./scripts/patch-rename.sh -i 5 target/linux/generic/1*
Add 5 to all the prefix numbers of all the patch files specified as an
argument.
Signed-off-by: Mathieu Olivari <mathieu at codeaurora.org>
---
scripts/patch-rename.sh | 66 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 66 insertions(+)
create mode 100755 scripts/patch-rename.sh
diff --git a/scripts/patch-rename.sh b/scripts/patch-rename.sh
new file mode 100755
index 0000000..011d179
--- /dev/null
+++ b/scripts/patch-rename.sh
@@ -0,0 +1,66 @@
+#!/bin/bash
+
+usage() {
+ echo "Usage: `basename $0` [ -i addval ] [ -d decval ] xxx.patch yyy.patch ..."
+ echo -e "\t -i ==> increment patch files by \"addval\""
+ echo -e "\t -d ==> decrement patch files by \"decval\""
+ exit 1
+}
+
+_do_rename() {
+ local mod=$1
+ local op=$2
+ local file=$3
+ local oldval newval
+
+ [ -f $file ] || { echo "Can't find file: $file"; exit 1; }
+
+ oldval=$(echo $file | sed 's/.*\/\([0-9]*\)-[^\/]*/\1/')
+ digits=${#oldval}
+ newval=$((${oldval##0*0} $op $mod))
+ # Pad newval to the previous number of characters
+ newval=$(printf "%0${#oldval}d" $newval)
+ rename "s/$oldval/$newval/" $file || { \
+ echo "Can't rename file: $file\n"; \
+ exit 1; \
+ }
+}
+
+dec_patches() {
+ local decval=$1; shift
+ # process the lowest patch first to avoid having conflicting numbers
+ local patchlist=$(echo $@ | sort -n)
+ local oldval newval
+
+ for p in ${patchlist}; do
+ _do_rename $decval - $p
+ done
+}
+
+inc_patches() {
+ local incval=$1; shift
+ # process the highest patch first to avoid having conflicting numbers
+ local patchlist=$(echo $@ | sort -nr)
+ local oldval newval
+
+ for p in ${patchlist}; do
+ _do_rename $incval + $p
+ done
+}
+
+while getopts "i:d:" OPTION; do
+ case $OPTION in
+ i ) INCVAL=$OPTARG;;
+ d ) DECVAL=$OPTARG;;
+ * ) usage;;
+ esac
+done
+
+shift $((OPTIND-1))
+PATCH_LIST=$@
+
+# If the user didn't provide any file, show the usage information
+[ ${#PATCH_LIST} == 0 ] && usage
+
+[ -n "$INCVAL" ] && inc_patches $INCVAL $PATCH_LIST
+[ -n "$DECVAL" ] && dec_patches $DECVAL $PATCH_LIST
--
2.1.4
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list