forked from zhenyw/gvt-maintainer-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
frob-patch-rank
executable file
·59 lines (47 loc) · 1018 Bytes
/
frob-patch-rank
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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