Skip to contentSkip to conversation

frob-patch-rank: A little script to batch renaming patch files

PATCH Superseded Damien Lespiau 2 participants 7 messages Jun 10, 2014 – Jun 17, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 frob-patch-rank: A little script to batch renaming patch files

The "usage" text should explain it all. I found, in my quilt series handling endeavours, that I wanted to be able to shift the prefix numbers of a patch series.

---
 frob-patch-rank | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100755 frob-patch-rank
frob-patch-rank new file +47 -0
new file mode 100755
index 0000000..4be42e5
@@ -0,0 +1,47 @@
+#!/bin/sh
+set -e
+
+script=$(basename $0)
+[ $# -ge 3 ] || {
+	echo "Usage: $script start end expr"
+	echo
+	echo "  Frob patches."
+	echo
+	echo "  This tiny script renames \"git format-patch\" patches by executing 'expr'"
+	echo "  on the number that prefix the patch file, but only if the patch file name "
+	echo "  starts with a number in ['start','end']."
+	echo
+	echo "Examples:"
+	echo "  $ ls *patch"
+	echo "  0008-Super-patch.patch"
+	echo "  0009-Mega-patch.patch"
+	echo "  $ $script 8 9 -7"
+	echo "  $ ls *patch"
+	echo "  0001-Super-patch.patch"
+	echo "  0002-Mega-patch.patch"
+	echo
+	echo "Examples:"
+	echo "  $ ls *patch"
+	echo "  0117-Super-patch.patch"
+	echo "  0118-Mega-patch.patch"
+	echo "  $ $script 8 9 +900 -17"
+	echo "  $ ls *patch"
+	echo "  1000-Super-patch.patch"
+	echo "  1001-Mega-patch.patch"
+	exit 1
+}
+
+start=$1
+end=$2
+shift 2
+op=$*
+
+for i in $(seq $start $end); do
+	prefix=$(printf "%04d" $i)
+	for f in $(ls $prefix-*.patch); do
+		base=${f#$prefix-}
+		((n=$i $op))
+		new_prefix=$(printf "%04d" $n)
+		mv $prefix-$base $new_prefix-$base
+	done
+done
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 33 lines · Damien Lespiau

The "usage" text should explain it all. I found, in my quilt series handling endeavours, that I wanted to be able to shift the prefix numbers of a patch series.

---
 frob-patch-rank | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100755 frob-patch-rank
frob-patch-rank new file +17 -0
new file mode 100755
index 0000000..4be42e5
@@ -0,0 +1,47 @@
+#!/bin/sh
+set -e
+
+script=$(basename $0)
+[ $# -ge 3 ] || {
+	echo "Usage: $script start end expr"
+	echo
+	echo "  Frob patches."
+	echo
+	echo "  This tiny script renames \"git format-patch\" patches by executing 'expr'"
+	echo "  on the number that prefix the patch file, but only if the patch file name "
+	echo "  starts with a number in ['start','end']."
+	echo
+	echo "Examples:"
+	echo "  $ ls *patch"
+	echo "  0008-Super-patch.patch"
+	echo "  0009-Mega-patch.patch"

frob-patch-rank line 27

Quoted 10 lines
frob-patch-rank new file +10 -0
+	echo "  $ $script 8 9 -7"
+	echo "  $ ls *patch"
+	echo "  0001-Super-patch.patch"
+	echo "  0002-Mega-patch.patch"
+	echo
+	echo "Examples:"
+	echo "  $ ls *patch"
+	echo "  0117-Super-patch.patch"
+	echo "  0118-Mega-patch.patch"
+	echo "  $ $script 8 9 +900 -17"

I was scratching my head for a while with this example. It's wrong isn't it?

The help could benefit from a "here" document.

Quoted 8 lines
frob-patch-rank new file +8 -0
+	echo "  $ ls *patch"
+	echo "  1000-Super-patch.patch"
+	echo "  1001-Mega-patch.patch"
+	exit 1
+}
+
+start=$1
+end=$2

frob-patch-rank line 45

Quoted 10 lines
frob-patch-rank new file +10 -0
+shift 2
+op=$*
+
+for i in $(seq $start $end); do
+	prefix=$(printf "%04d" $i)
+	for f in $(ls $prefix-*.patch); do
+		base=${f#$prefix-}
+		((n=$i $op))
+		new_prefix=$(printf "%04d" $n)
+		mv $prefix-$base $new_prefix-$base

mv -i just in case?

BR,
Jani.

Quoted 9 lines
frob-patch-rank new file +2 -0
+	done
+done
Signature · 6 lines
1.8.3.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 1 line
Jani Nikula, Intel Open Source Technology Center
#2 lore raw

PATCH v2 1/1 frob-patch-rank: A little script to batch renaming patch files

The "usage" text should explain it all. I found, in my quilt series handling endeavours, that I wanted to be able to shift the prefix numbers of a patch series.

v2: Use heredoc for usage string, fix second example, use mv -i (Jani)

---
 frob-patch-rank | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
 create mode 100755 frob-patch-rank
frob-patch-rank new file +51 -0
new file mode 100755
index 0000000..797774e
@@ -0,0 +1,51 @@
+#!/bin/sh
+set -e
+
+script=$(basename $0)
+
+read -r -d '' usage << EOU || true
+Usage: $script start end expr
+
+  Frob patches."
+
+  This tiny script renames \"git format-patch\" patches by executing 'expr'
+  on the number that prefix the patch file, but only if the patch file name
+  starts with a number in ['start','end'].
+
+Examples:
+  $ ls *patch
+  0008-Super-patch.patch
+  0009-Mega-patch.patch
+  $ $script 8 9 -7
+  $ ls *patch
+  0001-Super-patch.patch
+  0002-Mega-patch.patch
+
+  $ ls *patch
+  0117-Super-patch.patch
+  0118-Mega-patch.patch
+  $ $script 117 118 +900 -17
+  $ ls *patch
+  1000-Super-patch.patch
+  1001-Mega-patch.patch
+EOU
+
+[ $# -ge 3 ] || {
+	echo "$usage"
+	exit 1
+}
+
+start=$1
+end=$2
+shift 2
+op=$*
+
+for i in $(seq $start $end); do
+	prefix=$(printf "%04d" $i)
+	for f in $(ls $prefix-*.patch); do
+		base=${f#$prefix-}
+		((n=$i $op))
+		new_prefix=$(printf "%04d" $n)
+		mv -i $prefix-$base $new_prefix-$base
+	done
+done
Signature · 1 line
1.8.3.1
#3 lore raw
Quoted 18 lines · Damien Lespiau

The "usage" text should explain it all. I found, in my quilt series handling endeavours, that I wanted to be able to shift the prefix numbers of a patch series.

v2: Use heredoc for usage string, fix second example, use mv -i (Jani)

---
 frob-patch-rank | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
 create mode 100755 frob-patch-rank
frob-patch-rank new file +0 -0
new file mode 100755
index 0000000..797774e

frob-patch-rank line 6

Quoted 6 lines
frob-patch-rank new file +6 -0
@@ -0,0 +1,51 @@
+#!/bin/sh
+set -e
+
+script=$(basename $0)
+
+read -r -d '' usage << EOU || true

./frob-patch-rank: 6: read: Illegal option -d

$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Feb 19 14:13 /bin/sh -> dash

how about just

usage()
{
cat << EOF
...
EOF
}

Sorry for causing you all this trouble... :(

Jani.

Quoted 52 lines
frob-patch-rank new file +45 -0
+Usage: $script start end expr
+
+  Frob patches."
+
+  This tiny script renames \"git format-patch\" patches by executing 'expr'
+  on the number that prefix the patch file, but only if the patch file name
+  starts with a number in ['start','end'].
+
+Examples:
+  $ ls *patch
+  0008-Super-patch.patch
+  0009-Mega-patch.patch
+  $ $script 8 9 -7
+  $ ls *patch
+  0001-Super-patch.patch
+  0002-Mega-patch.patch
+
+  $ ls *patch
+  0117-Super-patch.patch
+  0118-Mega-patch.patch
+  $ $script 117 118 +900 -17
+  $ ls *patch
+  1000-Super-patch.patch
+  1001-Mega-patch.patch
+EOU
+
+[ $# -ge 3 ] || {
+	echo "$usage"
+	exit 1
+}
+
+start=$1
+end=$2
+shift 2
+op=$*
+
+for i in $(seq $start $end); do
+	prefix=$(printf "%04d" $i)
+	for f in $(ls $prefix-*.patch); do
+		base=${f#$prefix-}
+		((n=$i $op))
+		new_prefix=$(printf "%04d" $n)
+		mv -i $prefix-$base $new_prefix-$base
+	done
+done
Signature · 6 lines
1.8.3.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 1 line
Jani Nikula, Intel Open Source Technology Center
#4 lore raw

PATCH v3 1/1 frob-patch-rank: A little script to batch renaming patch files

The "usage" text should explain it all. I found, in my quilt series handling endeavours, that I wanted to be able to shift the prefix numbers of a patch series.

v2: Use heredoc for usage string, fix second example, use mv -i (Jani)
v3: Don't use a fancy read for usage() (Jani)
Collect the files to rename in a first pass, or the renaming process can interfere with listing the next files to rename

---
 frob-patch-rank | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100755 frob-patch-rank
frob-patch-rank new file +59 -0
new file mode 100755
index 0000000..c791f8d
@@ -0,0 +1,59 @@
+#!/bin/sh
+set -e
+
+script=$(basename $0)
+
+function usage() {
+	cat << EOU
+Usage: $script start end expr
+
+  Frob patches.
+
+  This tiny script renames "git format-patch" patches by executing 'expr'
+  on the number that prefix the patch file, but only if the patch file name
+  starts with a number in ['start','end'].
+
+Examples:
+  $ ls *patch
+  0008-Super-patch.patch
+  0009-Mega-patch.patch
+  $ $script 8 9 -7
+  $ ls *patch
+  0001-Super-patch.patch
+  0002-Mega-patch.patch
+
+  $ ls *patch
+  0117-Super-patch.patch
+  0118-Mega-patch.patch
+  $ $script 117 118 +900 -17
+  $ ls *patch
+  1000-Super-patch.patch
+  1001-Mega-patch.patch
+EOU
+}
+
+[ $# -ge 3 ] || {
+	usage
+	exit 1
+}
+
+start=$1
+end=$2
+shift 2
+op=$*
+
+for i in $(seq $start $end); do
+	prefix=$(printf "%04d" $i)
+	files="$files $(ls $prefix-*.patch)"
+done
+
+for f in $files; do
+	prefix=${f:0:4}
+	base=${f#$prefix-}
+
+	rank=$((10#$prefix))	# don't interpret the leading 0 as base 8
+	((n=$rank $op))
+
+	new_prefix=$(printf "%04d" $n)
+	mv $prefix-$base $new_prefix-$base
+done
Signature · 1 line
1.8.3.1
#5 lore raw
Quoted 21 lines · Damien Lespiau

The "usage" text should explain it all. I found, in my quilt series handling endeavours, that I wanted to be able to shift the prefix numbers of a patch series.

v2: Use heredoc for usage string, fix second example, use mv -i (Jani)
v3: Don't use a fancy read for usage() (Jani)
Collect the files to rename in a first pass, or the renaming process can interfere with listing the next files to rename

---
 frob-patch-rank | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100755 frob-patch-rank
frob-patch-rank new file +0 -0
new file mode 100755
index 0000000..c791f8d

frob-patch-rank line 1

Quoted 1 line
frob-patch-rank new file +1 -0
@@ -0,0 +1,59 @@
+#!/bin/sh

I think you have some bashisms in there, so could reflect that here, but otherwise LGTM.

Jani.

Quoted 65 lines
frob-patch-rank new file +58 -0
+set -e
+
+script=$(basename $0)
+
+function usage() {
+	cat << EOU
+Usage: $script start end expr
+
+  Frob patches.
+
+  This tiny script renames "git format-patch" patches by executing 'expr'
+  on the number that prefix the patch file, but only if the patch file name
+  starts with a number in ['start','end'].
+
+Examples:
+  $ ls *patch
+  0008-Super-patch.patch
+  0009-Mega-patch.patch
+  $ $script 8 9 -7
+  $ ls *patch
+  0001-Super-patch.patch
+  0002-Mega-patch.patch
+
+  $ ls *patch
+  0117-Super-patch.patch
+  0118-Mega-patch.patch
+  $ $script 117 118 +900 -17
+  $ ls *patch
+  1000-Super-patch.patch
+  1001-Mega-patch.patch
+EOU
+}
+
+[ $# -ge 3 ] || {
+	usage
+	exit 1
+}
+
+start=$1
+end=$2
+shift 2
+op=$*
+
+for i in $(seq $start $end); do
+	prefix=$(printf "%04d" $i)
+	files="$files $(ls $prefix-*.patch)"
+done
+
+for f in $files; do
+	prefix=${f:0:4}
+	base=${f#$prefix-}
+
+	rank=$((10#$prefix))	# don't interpret the leading 0 as base 8
+	((n=$rank $op))
+
+	new_prefix=$(printf "%04d" $n)
+	mv $prefix-$base $new_prefix-$base
+done
Signature · 6 lines
1.8.3.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 1 line
Jani Nikula, Intel Open Source Technology Center
#6 lore raw

PATCH v4 1/1 frob-patch-rank: A little script to batch renaming patch files

The "usage" text should explain it all. I found, in my quilt series handling endeavours, that I wanted to be able to shift the prefix numbers of a patch series.

v2: Use heredoc for usage string, fix second example, use mv -i (Jani)
v3: Don't use a fancy read for usage() (Jani)
Collect the files to rename in a first pass, or the renaming process can interfere with listing the next files to rename
v4: Require bash (Jani)

Looks-good-to: Jani Nikula <[email protected]>

---
 frob-patch-rank | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100755 frob-patch-rank
frob-patch-rank new file +59 -0
new file mode 100755
index 0000000..0239c76
@@ -0,0 +1,59 @@
+#!/bin/bash
+set -e
+
+script=$(basename $0)
+
+function usage() {
+	cat << EOU
+Usage: $script start end expr
+
+  Frob patches.
+
+  This tiny script renames "git format-patch" patches by executing 'expr'
+  on the number that prefix the patch file, but only if the patch file name
+  starts with a number in ['start','end'].
+
+Examples:
+  $ ls *patch
+  0008-Super-patch.patch
+  0009-Mega-patch.patch
+  $ $script 8 9 -7
+  $ ls *patch
+  0001-Super-patch.patch
+  0002-Mega-patch.patch
+
+  $ ls *patch
+  0117-Super-patch.patch
+  0118-Mega-patch.patch
+  $ $script 117 118 +900 -17
+  $ ls *patch
+  1000-Super-patch.patch
+  1001-Mega-patch.patch
+EOU
+}
+
+[ $# -ge 3 ] || {
+	usage
+	exit 1
+}
+
+start=$1
+end=$2
+shift 2
+op=$*
+
+for i in $(seq $start $end); do
+	prefix=$(printf "%04d" $i)
+	files="$files $(ls $prefix-*.patch)"
+done
+
+for f in $files; do
+	prefix=${f:0:4}
+	base=${f#$prefix-}
+
+	rank=$((10#$prefix))	# don't interpret the leading 0 as base 8
+	((n=$rank $op))
+
+	new_prefix=$(printf "%04d" $n)
+	mv $prefix-$base $new_prefix-$base
+done
Signature · 1 line
1.8.3.1