From: "cron2 (Code Review)" Date: Mon, 4 Aug 2025 09:34:51 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <9cabba7d662d711e03c1954bc4a8b8e6e4d991ee-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="JckIZDPL1UE="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Update git-pre-commit-uncrustify.sh to handle clang-format List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld , plaisthos Cc: openvpn-devel --JckIZDPL1UE= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#4) to the change originally created by= flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1070?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by cron2 Change subject: Update git-pre-commit-uncrustify.sh to handle clang-format ...................................................................... Update git-pre-commit-uncrustify.sh to handle clang-format Rename it as well, since it is not specific to uncrustify anymore. Change-Id: I03195c21807cdef0a2f903f424982ec29a555103 Signed-off-by: Frank Lichtenheld Acked-by: Gert Doering Message-Id: <20250804092739.16410-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg32= 497.html Signed-off-by: Gert Doering --- R dev-tools/git-pre-commit-format.sh 1 file changed, 32 insertions(+), 14 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/70/1070/4 diff --git a/dev-tools/git-pre-commit-uncrustify.sh b/dev-tools/git-pre-com= mit-format.sh similarity index 81% rename from dev-tools/git-pre-commit-uncrustify.sh rename to dev-tools/git-pre-commit-format.sh index 9851c21..6e1ac71 100755 --- a/dev-tools/git-pre-commit-uncrustify.sh +++ b/dev-tools/git-pre-commit-format.sh @@ -2,6 +2,7 @@ # Copyright (c) 2015, David Martin # 2022, Heiko Hund +# 2025, Frank Lichtenheld # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -26,10 +27,12 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# git pre-commit hook that runs an Uncrustify stylecheck. +# git pre-commit hook that runs a stylecheck. # Features: # - abort commit when commit does not comply with the style guidelines # - create a patch of the proposed style changes +# - use clang-format or uncrustify depending on presence of .clang-format +# config file # # More info on Uncrustify: http://uncrustify.sourceforge.net/ @@ -77,27 +80,42 @@ against=3D4b825dc642cb6eb9a060e54bf8d69288fbee4904 fi -UNCRUSTIFY=3D$(command -v uncrustify) -UNCRUST_CONFIG=3D"$(git rev-parse --show-toplevel)/dev-tools/uncrustify.co= nf" +TOPDIR=3D"$(git rev-parse --show-toplevel)" +if [ -e "${TOPDIR}/.clang-format" ]; then + TOOL=3Dclang-format + TOOL_BIN=3D$(command -v clang-format) + TOOL_CMD=3D"$TOOL_BIN" -# make sure the config file and executable are correctly set -if [ ! -f "$UNCRUST_CONFIG" ] ; then - printf "Error: uncrustify config file not found.\n" - printf "Expected to find it at $UNCRUST_CONFIG.\n" - printf "Aborting commit.\n" - exit 1 + # Allow to use in parallel with pre-commit + if [ $(basename "$0") =3D "pre-commit.legacy" ]; then + echo "Skipping clang-format check in favor of pre-commit" + exit 0 + fi +else + TOOL=3Duncrustify + TOOL_BIN=3D$(command -v uncrustify) + UNCRUST_CONFIG=3D"${TOPDIR}/dev-tools/uncrustify.conf" + TOOL_CMD=3D"$TOOL_BIN -q -l C -c $UNCRUST_CONFIG" + + # make sure the config file is correctly set + if [ ! -f "$UNCRUST_CONFIG" ] ; then + printf "Error: uncrustify config file not found.\n" + printf "Expected to find it at $UNCRUST_CONFIG.\n" + printf "Aborting commit.\n" + exit 1 + fi fi -if [ -z "$UNCRUSTIFY" ] ; then - printf "Error: uncrustify executable not found.\n" +if [ -z "$TOOL_BIN" ] ; then + printf "Error: $TOOL executable not found.\n" printf "Is it installed and in your \$PATH?\n" printf "Aborting commit.\n" exit 1 fi # create a filename to store our generated patch -patch=3D$(mktemp /tmp/ovpn-fmt-XXXXXX) -tmpout=3D$(mktemp /tmp/uncrustify-XXXXXX) +patch=3D$(mktemp /tmp/ovpn-fmt-patch-XXXXXX) +tmpout=3D$(mktemp /tmp/ovpn-fmt-tmp-XXXXXX) # create one patch containing all changes to the files # sed to remove quotes around the filename, if inserted by the system @@ -131,7 +149,7 @@ # +++ $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'. - git show ":$file" | "$UNCRUSTIFY" -q -l C -c "$UNCRUST_CONFIG" -o "$tm= pout" + git show ":$file" | $TOOL_CMD > "$tmpout" git show ":$file" | diff -u -- - "$tmpout" | \ sed -e "1s|--- -|--- \"b/$file_escaped_target\"|" -e "2s|+++ $tmpo= ut|+++ \"a/$file_escaped_target\"|" >> "$patch" done -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1070?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I03195c21807cdef0a2f903f424982ec29a555103 Gerrit-Change-Number: 1070 Gerrit-PatchSet: 4 Gerrit-Owner: flichtenheld Gerrit-Reviewer: cron2 Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-MessageType: newpatchset --JckIZDPL1UE= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 uploaded patch set #4 to the change originally cr= eated by flichtenheld.

View Change

The following approvals got outd= ated and were removed: Code-Review+2 by cron2

Update git-pre-commit-uncrustify.sh to handle clang-=
format

Rename it as well, since it is not specific to
uncrustify = anymore.

Change-Id: I03195c21807cdef0a2f903f424982ec29a555103
Sig= ned-off-by: Frank Lichtenheld <frank@...2641...>
Acked-by: Gert Do= ering <gert@...1296...>
Message-Id: <20250804092739.16410-1-ger= t@...1296...>
URL: https://www.mail-archive.com/openvpn-devel@...1096...= ourceforge.net/msg32497.html
Signed-off-by: Gert Doering <gert@...1826...= 6...>
---
R dev-tools/git-pre-commit-format.sh
1 file changed, = 32 insertions(+), 14 deletions(-)

git pull ssh://gerrit.openvpn.n=
et:29418/openvpn refs/changes/70/1070/4
diff --git a/dev-tools/git-=
pre-commit-uncrustify.sh b/dev-tools/git-pre-commit-format.sh
similarity index 81%
rename from dev-tools/git-pre-commi= t-uncrustify.sh
rename to dev-tools/git-pre-commit-format.s= h
index 9851c21..6e1ac71 100755
--- a/dev-t= ools/git-pre-commit-uncrustify.sh
+++ b/dev-tools/git-pre-c= ommit-format.sh
@@ -2,6 +2,7 @@
# Copyright (c) 2015, David Martin
# = 2022, Heiko Hund
+# = 2025, Frank Lichtenheld
# All rights reserve= d.
#
# Redistribution and use in source a= nd binary forms, with or without
@@ -26,10 +27,12 @@=
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH D= AMAGE.


-# git pre-commit hook that runs an Uncrustify styleche= ck.
+# git pre-commit= hook that runs a stylecheck.
# Features:
= # - abort commit when commit does not comply with the style guidelines
# - create a patch of the proposed style changes
= +# - use clang-format or uncru= stify depending on presence of .clang-format
+# config file
#
# More info on Uncrustify: http://uncrustify.sourceforge.net/

=
@@ -77,27 +80,42 @@
against=3D= 4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi

-UNCRUSTIFY=3D$(com= mand -v uncrustify)
-UN= CRUST_CONFIG=3D"$(git rev-parse --show-toplevel)/dev-tools/uncrustify.= conf"
+TOPDIR=3D= "$(git rev-parse --show-toplevel)"
+if [ -e "${TOPDIR}/.clang-format" ]; the= n
+ TOOL=3Dclang-f= ormat
+ TOOL_BIN= =3D$(command -v clang-format)
+ TOOL_CMD=3D"$TOOL_BIN"

= -# make sure the config file and = executable are correctly set
-if [ ! -f "$UNCRUST_CONFIG" ] ; then
- printf "Error: uncrustify config f= ile not found.\n"
= - printf "Expected to find it at $UNCRUST_CONFIG.\n"- printf "Aborting commi= t.\n"
- exit 1<= /span>
+ # Allow to use i= n parallel with pre-commit
+ if [ $(basename "$0") =3D "pre-commit.legacy"= ; ]; then
+ ech= o "Skipping clang-format check in favor of pre-commit"
= + exit 0
+ fi
+else
+ TOOL=3Duncrustify
+ TOOL_BIN=3D$(command -v uncrustify)
+ UNCRUST_CONFIG=3D"${TOPDIR}/dev-= tools/uncrustify.conf"
+ TOOL_CMD=3D"$TOOL_BIN -q -l C -c $UNCRUST_CONFIG"

+
+ # make sure the config file is correc= tly set
+ if [ ! -= f "$UNCRUST_CONFIG" ] ; then
+ printf "Error: uncrustify config file not f= ound.\n"
+ = printf "Expected to find it at $UNCRUST_CONFIG.\n"
+ printf "Aborting co= mmit.\n"
+ = exit 1
+ fi
fi

-if [ -z "$UNCRUSTIFY" ] ; then
- printf "Error: uncrustify executab= le not found.\n"
+if [ -z "$TOOL_BIN" ] ; then
+ printf "Error: $TOOL executable not found.\n&= quot;
printf "Is it installed and in your \$PATH?= \n"
printf "Aborting commit.\n"<= br> exit 1
fi

= # create a filename to store our generated patch
-patch=3D$(mktemp /tmp/ovpn-fmt-XXXXXX)-tmpout=3D$(mktemp /tmp/uncrust= ify-XXXXXX)
+patch=3D= $(mktemp /tmp/ovpn-fmt-patch-XXXXXX)
+tmpout=3D$(mktemp /tmp/ovpn-fmt-tmp-XXXXXX)

# create one patch containing all changes to the files=
# sed to remove quotes around the filename, if inserted b= y the system
@@ -131,7 +149,7 @@
# = +++ $tmpout timestamp
# to both lines working on the s= ame file and having a a/ and b/ prefix.
# Else it can = not be applied with 'git apply'.
- git show ":$file" | "$UNCRUSTIFY"= ; -q -l C -c "$UNCRUST_CONFIG" -o "$tmpout"
<= span style=3D"color: hsl(120, 100%, 40%);">+ git show ":$file"= | $TOOL_CMD > "$tmpout"
git show ":= $file" | diff -u -- - "$tmpout" | \
= sed -e "1s|--- -|--- \"b/$file_escaped_target\"|" -e &= quot;2s|+++ $tmpout|+++ \"a/$file_escaped_target\"|" >>= ; "$patch"
done

To view, visit change 1070. To unsubscribe, or for help writing mail filter= s, visit settings.

<= meta itemprop=3D"name" content=3D"View Change"/>
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I03195c21807cdef0a2f903f4249= 82ec29a555103
Gerrit-Change-Number: 1070
Gerrit-PatchSet: 4
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-MessageType: newpatchset
--JckIZDPL1UE=--