From patchwork Tue May 17 11:01:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiko Hund X-Patchwork-Id: 2467 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director11.mail.ord1d.rsapps.net ([172.31.255.6]) by backend41.mail.ord1d.rsapps.net with LMTP id kDDyKYsNhGLxKgAAqwncew (envelope-from ) for ; Tue, 17 May 2022 17:03:07 -0400 Received: from proxy17.mail.iad3b.rsapps.net ([172.31.255.6]) by director11.mail.ord1d.rsapps.net with LMTP id IOm9M4sNhGKaRAAAvGGmqA (envelope-from ) for ; Tue, 17 May 2022 17:03:07 -0400 Received: from smtp16.gate.iad3b ([172.31.255.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy17.mail.iad3b.rsapps.net with LMTPS id gF1JLosNhGIBFQAA5ccGVQ (envelope-from ) for ; Tue, 17 May 2022 17:03:07 -0400 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-Orig-To: openvpnslackdevel@openvpn.net X-Originating-Ip: [216.105.38.7] Authentication-Results: smtp16.gate.iad3b.rsapps.net; iprev=pass policy.iprev="216.105.38.7"; spf=pass smtp.mailfrom="openvpn-devel-bounces@lists.sourceforge.net" smtp.helo="lists.sourceforge.net"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dmarc=none (p=nil; dis=none) header.from=ist.eigentlich.net X-Suspicious-Flag: YES X-Classification-ID: bf83812a-d624-11ec-a465-5254004ed364-1-1 Received: from [216.105.38.7] ([216.105.38.7:51614] helo=lists.sourceforge.net) by smtp16.gate.iad3b.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 35/EA-32148-A8D04826; Tue, 17 May 2022 17:03:06 -0400 Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.94.2) (envelope-from ) id 1nr4KO-0004fm-1K; Tue, 17 May 2022 21:01:58 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nr4KL-0004fc-P0 for openvpn-devel@lists.sourceforge.net; Tue, 17 May 2022 21:01:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:Message-Id: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=uVCQgYNJ4yyU8O92ZmSthE5nA2oKWiTLXzxcF/+GpDo=; b=ghxOz6qYCbip3IUf9lLRwPqPoN +AfIIsDC9KLUpQnGbU0WLTBVdBJlYmVmEYtzH07IEzHtQV31kbv2umFzRfNzWOkCxTvTUJ6O+ft21 CRYbu0kPJkt6Vhz1A3I4LQZ2SjM5qhtH81zHUSatlkMs2rb69YzrmWzhtUisFGdNvHoY=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject:To:From: Sender:Reply-To:Cc:Content-Type:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=uVCQgYNJ4yyU8O92ZmSthE5nA2oKWiTLXzxcF/+GpDo=; b=G lfQDYuMRKXlhbGIij6IGQzgea1Qxc72Fs81T3bXNNuVFG1cxXJBxMAzPEUDHTM3ZxrdyFMyfEhCfj PhDwUOeJsyUcPuX/au/okBUrK2gUKJD+JsPT1j11WkK9A0VLQ0oKYa+dUkuJOqkHcmbzMBvZobBAe kIG733zE45NYtilE=; Received: from exit0.net ([85.25.119.185]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.94.2) id 1nr4KF-0008Ew-2h for openvpn-devel@lists.sourceforge.net; Tue, 17 May 2022 21:01:56 +0000 Received: from coruscant.fritz.box (unknown [87.123.247.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by exit0.net (Postfix) with ESMTPSA id 1E4966480127 for ; Tue, 17 May 2022 23:01:34 +0200 (CEST) From: Heiko Hund To: openvpn-devel@lists.sourceforge.net Date: Tue, 17 May 2022 23:01:21 +0200 Message-Id: <20220517210121.1312072-1-heiko@ist.eigentlich.net> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-Spam-Report: Spam detection software, running on the system "util-spamd-1.v13.lw.sourceforge.com", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Previously the generated patch was based on the file(s) in the working directory. This is a problem if you have not to be commited changes there and these changes fix formatting issues that exist in t [...] Content analysis details: (0.2 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.2 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record X-Headers-End: 1nr4KF-0008Ew-2h Subject: [Openvpn-devel] [PATCH] pre-commit: uncrustify based on staged changes X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox Previously the generated patch was based on the file(s) in the working directory. This is a problem if you have not to be commited changes there and these changes fix formatting issues that exist in the staging area. This effectively circumventes the script from rejecting the commit. An example: git add file.c git commit ... pre-commit hooks complains about formatting ... ... you fix the file manually, forget to git add ... git commit ... succeeds, even though the commit still has issues ... Signed-off-by: Heiko Hund Acked-By: Frank Lichtenheld Acked-by: Antonio Quartulli --- dev-tools/git-pre-commit-uncrustify.sh | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/dev-tools/git-pre-commit-uncrustify.sh b/dev-tools/git-pre-commit-uncrustify.sh index a5cf3d41..9851c212 100755 --- a/dev-tools/git-pre-commit-uncrustify.sh +++ b/dev-tools/git-pre-commit-uncrustify.sh @@ -97,6 +97,7 @@ fi # create a filename to store our generated patch patch=$(mktemp /tmp/ovpn-fmt-XXXXXX) +tmpout=$(mktemp /tmp/uncrustify-XXXXXX) # create one patch containing all changes to the files # sed to remove quotes around the filename, if inserted by the system @@ -106,21 +107,11 @@ sed -e 's/^"\(.*\)"$/\1/' | \ while read file do # ignore file if we do check for file extensions and the file - # does not match any of the extensions specified in $FILE_EXTS + # does not match the extensions .c or .h if ! matches_extension "$file"; then continue; fi - # escape special characters in the source filename: - # - '\': backslash needs to be escaped - # - '*': used as matching string => '*' would mean expansion - # (curiously, '?' must not be escaped) - # - '[': used as matching string => '[' would mean start of set - # - '|': used as sed split char instead of '/', so it needs to be escaped - # in the filename - # printf %s particularly important if the filename contains the % character - file_escaped_source=$(printf "%s" "$file" | sed -e 's/[\*[|]/\\&/g') - # escape special characters in the target filename: # phase 1 (characters escaped in the output diff): # - '\': backslash needs to be escaped in the output diff @@ -136,15 +127,17 @@ do # uncrustify our sourcefile, create a patch with diff and append it to our $patch # The sed call is necessary to transform the patch from - # --- $file timestamp - # +++ - timestamp + # --- - timestamp + # +++ $tmpout timestamp # to both lines working on the same file and having a a/ and b/ prefix. # Else it can not be applied with 'git apply'. - "$UNCRUSTIFY" -q -c "$UNCRUST_CONFIG" -f "$file" | \ - diff -u -- "$file" - | \ - sed -e "1s|--- $file_escaped_source|--- \"a/$file_escaped_target\"|" -e "2s|+++ -|+++ \"b/$file_escaped_target\"|" >> "$patch" + git show ":$file" | "$UNCRUSTIFY" -q -l C -c "$UNCRUST_CONFIG" -o "$tmpout" + git show ":$file" | diff -u -- - "$tmpout" | \ + sed -e "1s|--- -|--- \"b/$file_escaped_target\"|" -e "2s|+++ $tmpout|+++ \"a/$file_escaped_target\"|" >> "$patch" done +rm -f "$tmpout" + # if no patch has been generated all is ok, clean up the file stub and exit if [ ! -s "$patch" ] ; then rm -f "$patch"