From 352322c0c1cc5591ec326d3325364b2087b39b69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?= Date: Sat, 28 Dec 2019 11:50:24 +0700 Subject: [PATCH] hook: python-shebang: check for shebang in the first line only - Grepping whole files is inefficient - git-instaweb (in git package) has the code to generate python file in a here doc in the middle of its code, old hook generates false positive with this package --- common/hooks/pre-pkg/03-rewrite-python-shebang.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/common/hooks/pre-pkg/03-rewrite-python-shebang.sh b/common/hooks/pre-pkg/03-rewrite-python-shebang.sh index 81e45b9821f..4de75da2a76 100644 --- a/common/hooks/pre-pkg/03-rewrite-python-shebang.sh +++ b/common/hooks/pre-pkg/03-rewrite-python-shebang.sh @@ -20,9 +20,10 @@ hook() { shebang="#!/usr/bin/python${pyver%.*}" find "${PKGDESTDIR}" -type f -print0 | \ - xargs -0 grep -H -b -m 1 "^#!.*\([[:space:]]\|/\)python\([0-9]\.[0-9]\)\?\([[:space:]]\+\|$\)" -- | while IFS=: read -r f off _; do - [ -z "$off" ] && continue - echo " Shebang converted to '$shebang': ${f#$PKGDESTDIR}" - sed -i "1s@.*python.*@${shebang}@" -- "$f" - done + while IFS= read -r -d '' file; do + [ ! -s "$file" ] && continue + [ -z "$(sed -n -E -e 2q -e '/^#!.*([[:space:]]|\/)python([0-9]\.[0-9])?([[:space:]]+|$)/p' "$file")" ] && continue + echo " Shebang converted to '$shebang': ${file#$PKGDESTDIR}" + sed -i "1s@.*python.*@${shebang}@" -- "$file" + done }