From patchwork Thu Aug 6 00:10:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Olivari X-Patchwork-Id: 504450 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 31E251402B9 for ; Thu, 6 Aug 2015 10:11:31 +1000 (AEST) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id A9149280163; Thu, 6 Aug 2015 02:10:46 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00, T_RP_MATCHES_RCVD autolearn=unavailable version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 6C110280163 for ; Thu, 6 Aug 2015 02:10:25 +0200 (CEST) X-policyd-weight: using cached result; rate:hard: -7.6 Received: from smtp.codeaurora.org (smtp.codeaurora.org [198.145.29.96]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Thu, 6 Aug 2015 02:10:24 +0200 (CEST) Received: from smtp.codeaurora.org (localhost [127.0.0.1]) by smtp.codeaurora.org (Postfix) with ESMTP id DC31113FA79; Thu, 6 Aug 2015 00:11:00 +0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 486) id CD6E613FA83; Thu, 6 Aug 2015 00:11:00 +0000 (UTC) Received: from mathieu-linux.qualcomm.com (qf-scl1nat.qualcomm.com [207.114.132.30]) (using TLSv1.2 with cipher AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: mathieu@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 4FA4613FA6D; Thu, 6 Aug 2015 00:11:00 +0000 (UTC) From: Mathieu Olivari To: nbd@openwrt.org Date: Wed, 5 Aug 2015 17:10:56 -0700 Message-Id: <1438819856-5788-1-git-send-email-mathieu@codeaurora.org> X-Mailer: git-send-email 2.1.4 X-Virus-Scanned: ClamAV using ClamSMTP Cc: openwrt-devel@lists.openwrt.org Subject: [OpenWrt-Devel] [PATCH] scripts: add a new patch-rename.sh script X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" 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 --- 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