From owner-svn-ports-all@freebsd.org Sun Nov 22 09:18:08 2015 Return-Path: Delivered-To: svn-ports-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B613DA35805; Sun, 22 Nov 2015 09:18:08 +0000 (UTC) (envelope-from marino@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 82F421FE8; Sun, 22 Nov 2015 09:18:08 +0000 (UTC) (envelope-from marino@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tAM9I7ba036707; Sun, 22 Nov 2015 09:18:07 GMT (envelope-from marino@FreeBSD.org) Received: (from marino@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tAM9I71Z036706; Sun, 22 Nov 2015 09:18:07 GMT (envelope-from marino@FreeBSD.org) Message-Id: <201511220918.tAM9I71Z036706@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: marino set sender to marino@FreeBSD.org using -f From: John Marino Date: Sun, 22 Nov 2015 09:18:07 +0000 (UTC) To: ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org Subject: svn commit: r402220 - head/Mk/Scripts X-SVN-Group: ports-head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-ports-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the ports tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 22 Nov 2015 09:18:08 -0000 Author: marino Date: Sun Nov 22 09:18:07 2015 New Revision: 402220 URL: https://svnweb.freebsd.org/changeset/ports/402220 Log: Mk/Scripts/smart_makepatch.sh: Fix multi-patch file and locals bug There were two issues with the new smart_makepatch script. 1) use of "local" declaration All function variables were declared "local" during the review. This caused the script to break, at least on FreeBSD 9.2. Given that it's not being seen on 9.3R or later, it might be a bug in Bourne shell that has since been fixed. e.g. This resulted in stderr error on second iteration: local contains=$(grep "^+++ " ${existing_patch} | awk '{x++; print x}') however, this works fine: local contains contains=$(grep "^+++ " ${existing_patch} | awk '{x++; print x}') To be safe, all local variables are assigned with $() on separate lines now. 2) The comment extraction was flawed for files that contain multiple patches. It was not counting the hunk lines properly which caused some portion of a patch to be considered as a comment for the next patch. The hunk traversal algorithm has been fixed. Since 1) involved the introduction of local declarations that broke the script and since only Scripts/smart_makepatch.sh is touched, I will piggy-back on the original approval. The fix was tested with devel/nspr, the port listed in the PR, which uses multi-patch files. Approved by: portmgr Differential Revision: D4136 PR: 204725 Modified: head/Mk/Scripts/smart_makepatch.sh Modified: head/Mk/Scripts/smart_makepatch.sh ============================================================================== --- head/Mk/Scripts/smart_makepatch.sh Sun Nov 22 08:03:51 2015 (r402219) +++ head/Mk/Scripts/smart_makepatch.sh Sun Nov 22 09:18:07 2015 (r402220) @@ -58,8 +58,10 @@ strip_path() { } std_patch_filename() { - local sans_cwd=$(echo $1 | sed 's|^\.\/||') - local raw_name=$(strip_path ${sans_cwd}) + local sans_cwd + local raw_name + sans_cwd=$(echo $1 | sed 's|^\.\/||') + raw_name=$(strip_path ${sans_cwd}) echo patch-$(echo ${raw_name} | sed -e 's|_|&&|g; s|/|_|g') } @@ -74,10 +76,11 @@ patchdir_files_list() { valid_name() { local current_patch_name=$1 - local first_target=$(echo $2 | sed 's|^\.\/||') local result=$3 + local first_target local testres local lps + first_target=$(echo $2 | sed 's|^\.\/||') for lps in __ - + ; do testres=patch-$(echo ${first_target} | sed -e "s|/|${lps}|g") if [ "${testres}" = "${current_patch_name}" ]; then @@ -122,10 +125,11 @@ map_existing_patches() { extract_comment_from_patch() { local existing_patch=${PATCHDIR}/$1 - local contains=$(grep "^+++ " ${existing_patch} | awk '{x++; print x}') + local contains local rawname local fname local num + contains=$(grep "^+++ " ${existing_patch} | awk '{x++; print x}') for num in ${contains}; do rawname=$(grep "^+++ " ${existing_patch} | \ awk -v num=${num} '{x++; if (x==num) print $2}') @@ -135,13 +139,17 @@ extract_comment_from_patch() { { \ if (!done) { \ if ($1 == "@@") { \ - split ($3,a,","); \ - hc = a[2]; \ + split ($2,a,","); \ + split ($3,b,","); \ + hca = a[2]; + hcb = a[3]; hunk = 1; } else if (hunk) { \ first=substr($1,1,1); \ - if (first == "-") { hc++ } else { hc-- } \ - if (hc == 0) {hunk = 0} \ + if (first == "-") { hca-- } \ + else if (first == "+") { hcb-- } \ + else {hca--; hcb--} \ + if (hca == 0 && hcb == 0) {hunk = 0} \ } \ if ($1 == "---") { \ x++; \ @@ -175,7 +183,7 @@ regenerate_patches() { local NEW local OUT local ORIG - local new_list= + local new_list new_list=$(cd ${PATCH_WRKSRC} && \ find -s * -type f -name '*.orig' 2>/dev/null) (cd ${PATCH_WRKSRC} && for F in ${new_list}; do @@ -206,7 +214,8 @@ stage_patches() { rm -f ${DESTDIR}/* local P local name - local patch_list=$(cd ${REGENNED} && find * -name "patch-*" 2>/dev/null) + local patch_list + patch_list=$(cd ${REGENNED} && find * -name "patch-*" 2>/dev/null) for P in ${patch_list}; do name=$(get_patch_name ${P}) [ -e ${COMMENTS}/${P} ] && cat ${COMMENTS}/${P} \