From: Damien Lespiau Subject: [PATCH v4 maintainer-tools] frob-patch-rank: A little script to batch renaming patch files Date: Tue, 17 Jun 2014 11:23:16 +0100 Message-ID: <1403000596-14775-1-git-send-email-damien.lespiau@intel.com> References: <87bntrrgo3.fsf@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTP id D81F46E47A for ; Tue, 17 Jun 2014 03:23:18 -0700 (PDT) In-Reply-To: <87bntrrgo3.fsf@intel.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" To: intel-gfx@lists.freedesktop.org List-Id: intel-gfx@lists.freedesktop.org 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 Signed-off-by: Damien Lespiau --- frob-patch-rank | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 frob-patch-rank diff --git a/frob-patch-rank b/frob-patch-rank new file mode 100755 index 0000000..0239c76 --- /dev/null +++ b/frob-patch-rank @@ -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 -- 1.8.3.1