From: Damien Lespiau Subject: [PATCH maintainer-tools] frob-patch-rank: A little script to batch renaming patch files Date: Tue, 10 Jun 2014 12:45:19 +0100 Message-ID: <1402400719-21641-1-git-send-email-damien.lespiau@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTP id 1A0F96E67D for ; Tue, 10 Jun 2014 04:45:36 -0700 (PDT) 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. Signed-off-by: Damien Lespiau --- frob-patch-rank | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 frob-patch-rank diff --git a/frob-patch-rank b/frob-patch-rank new file mode 100755 index 0000000..4be42e5 --- /dev/null +++ b/frob-patch-rank @@ -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 -- 1.8.3.1