From: "flichtenheld (Code Review)" Date: Mon, 26 May 2025 11:27:55 +0000 In-Reply-To: References: Reply-To: frank@...2641..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, gert@...1296... Message-ID: <98bdda39b52fa85faa12f12b686f47b365770575-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="Dz7Rvk91Le4="; charset=UTF-8 Subject: [Openvpn-devel] [L] Change in openvpn[master]: Remove uncrustify config and scripts, switch GHA List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: openvpn-devel --Dz7Rvk91Le4= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: cron2, flichtenheld, plaisthos. Hello cron2, plaisthos, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/830?usp=3Demail to look at the new patch set (#10). The following approvals got outdated and were removed: Code-Review-1 by cron2 Change subject: Remove uncrustify config and scripts, switch GHA ...................................................................... Remove uncrustify config and scripts, switch GHA Replaced with clang-format and pre-commit. Add a README file that explains how to use pre-commit and how to combine this with the old hook. Change-Id: I15d4946800cbfaead67a73450ff3b12193814e54 Signed-off-by: Frank Lichtenheld --- M .github/workflows/build.yaml A dev-tools/README.precommit.md D dev-tools/git-pre-commit-uncrustify.sh D dev-tools/reformat-all.sh D dev-tools/special-files.lst D dev-tools/uncrustify.conf 6 files changed, 42 insertions(+), 402 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/30/830/10 diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index d4fdc9d..37c09fe 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -5,35 +5,26 @@ pull_request: jobs: - checkuncrustify: - name: "Check code style with Uncrustify" - # Ubuntu 22.04 has uncrustify 0.72_f - runs-on: ubuntu-22.04 + clang-format: + name: Check code style with clang-format + runs-on: ubuntu-24.04 steps: - name: Install dependencies - run: sudo apt update && sudo apt install -y uncrustify + run: | + sudo apt update && sudo apt install -y python3-pip + pip3 install pre-commit - name: Checkout OpenVPN uses: actions/checkout@...2844... # v4.2.2 - with: - path: openvpn - - name: Show uncrustify version - run: uncrustify --version - - name: Run uncrustify - run: ./dev-tools/reformat-all.sh - working-directory: openvpn + - name: Run clang-format + run: pre-commit run -a --show-diff-on-failure || true - name: Check for changes - run: git diff --output=3Duncrustify-changes.patch - working-directory: openvpn - - name: Show changes on standard output - run: git diff - working-directory: openvpn + run: git diff --output=3Dformat-changes.patch - uses: actions/upload-artifact@...2868... # v4.6.2 with: - name: uncrustify-changes.patch - path: 'openvpn/uncrustify-changes.patch' + name: format-changes.patch + path: format-changes.patch - name: Set job status - run: test ! -s uncrustify-changes.patch - working-directory: openvpn + run: test ! -s format-changes.patch android: strategy: diff --git a/dev-tools/README.precommit.md b/dev-tools/README.precommit.md new file mode 100644 index 0000000..fe01058 --- /dev/null +++ b/dev-tools/README.precommit.md @@ -0,0 +1,30 @@ +How to use pre-commit hooks in openvpn repository +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +openvpn comes with a .pre-commit-config.yaml which can be used +with https://pre-commit.com/ + +To install the pre-commit hook you can just use + + pip install pre-commit + pre-commit install + +This will enable the pre-commit checks which currently only +consists of a clang-format formatting check. + +**However**, in older branches, up to and including release/2.6 +we had a different pre-commit hook +`dev-tools/git-pre-commit-uncrustify.sh` that implemented a +formatting check based on the uncrustify tool. + +If you want to use both pre-commit hooks you can use the following +installation: + + rm .git/hooks/pre-commit # make sure to start fresh + git checkout release/2.6 + ./dev-tools/git-pre-commit-uncrustify.sh install + git checkout master + pre-commit install --allow-missing-config + +This will run both hooks every time you commit but the "wrong" hook +will be skipped. diff --git a/dev-tools/git-pre-commit-uncrustify.sh b/dev-tools/git-pre-com= mit-uncrustify.sh deleted file mode 100755 index 9851c21..0000000 --- a/dev-tools/git-pre-commit-uncrustify.sh +++ /dev/null @@ -1,161 +0,0 @@ -#!/bin/sh - -# Copyright (c) 2015, David Martin -# 2022, Heiko Hund -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are m= et: -# -# * Redistributions of source code must retain the above copyright notice,= this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright noti= ce, -# this list of conditions and the following disclaimer in the documentat= ion -# and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS = IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPO= SE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LI= ABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTI= AL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS = OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEV= ER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABI= LITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF TH= E USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -# git pre-commit hook that runs an Uncrustify stylecheck. -# Features: -# - abort commit when commit does not comply with the style guidelines -# - create a patch of the proposed style changes -# -# More info on Uncrustify: http://uncrustify.sourceforge.net/ - -# This file was taken from a set of unofficial pre-commit hooks available -# at https://github.com/ddddavidmartin/Pre-commit-hooks and modified to -# fit the openvpn project's needs - -# exit on error -set -e - - -# If called so, install this script as pre-commit hook -if [ "$1" =3D "install" ] ; then - TARGET=3D"$(git rev-parse --git-path hooks)/pre-commit" - - if [ -e "$TARGET" ] ; then - printf "$TARGET file exists. Won't overwrite.\n" - printf "Aborting installation.\n" - exit 1 - fi - - read -p "Install as $TARGET? [y/N] " INPUT - [ "$INPUT" =3D "y" ] || exit 0 - cp "$0" "$TARGET" - chmod +x $TARGET - exit 0 -fi - -# check whether the given file matches any of the set extensions -matches_extension() { - local filename=3D"$(basename -- "$1")" - local extension=3D".${filename##*.}" - local ext - - for ext in .c .h ; do [ "$ext" =3D "$extension" ] && return 0; done - - return 1 -} - -# necessary check for initial commit -if git rev-parse --verify HEAD >/dev/null 2>&1 ; then - against=3DHEAD -else - # Initial commit: diff against an empty tree object - against=3D4b825dc642cb6eb9a060e54bf8d69288fbee4904 -fi - -UNCRUSTIFY=3D$(command -v uncrustify) -UNCRUST_CONFIG=3D"$(git rev-parse --show-toplevel)/dev-tools/uncrustify.co= nf" - -# 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 -fi - -if [ -z "$UNCRUSTIFY" ] ; then - printf "Error: uncrustify 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) - -# create one patch containing all changes to the files -# sed to remove quotes around the filename, if inserted by the system -# (done sometimes, if the filename contains special characters, like the q= uote itself) -git diff-index --cached --diff-filter=3DACMR --name-only $against -- | \ -sed -e 's/^"\(.*\)"$/\1/' | \ -while read file -do - # ignore file if we do check for file extensions and the file - # does not match the extensions .c or .h - if ! matches_extension "$file"; then - continue; - fi - - # escape special characters in the target filename: - # phase 1 (characters escaped in the output diff): - # - '\': backslash needs to be escaped in the output diff - # - '"': quote needs to be escaped in the output diff if present i= nside - # of the filename, as it used to bracket the entire filenam= e part - # phase 2 (characters escaped in the match replacement): - # - '\': backslash needs to be escaped again for sed itself - # (i.e. double escaping after phase 1) - # - '&': would expand to matched string - # - '|': used as sed split char instead of '/' - # printf %s particularly important if the filename contains the % char= acter - file_escaped_target=3D$(printf "%s" "$file" | sed -e 's/[\"]/\\&/g' -e= 's/[\&|]/\\&/g') - - # uncrustify our sourcefile, create a patch with diff and append it to= our $patch - # The sed call is necessary to transform the patch from - # --- - 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'. - git show ":$file" | "$UNCRUSTIFY" -q -l C -c "$UNCRUST_CONFIG" -o "$tm= pout" - git show ":$file" | diff -u -- - "$tmpout" | \ - sed -e "1s|--- -|--- \"b/$file_escaped_target\"|" -e "2s|+++ $tmpo= ut|+++ \"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" - exit 0 -fi - -# a patch has been created, notify the user and exit -printf "Formatting of some code does not follow the project guidelines.\n" - -if [ $(wc -l < $patch) -gt 80 ] ; then - printf "The file $patch contains the necessary fixes.\n" -else - printf "Here's the patch that fixes the formatting:\n\n" - cat $patch -fi - -printf "\nYou can apply these changes with:\n git apply $patch\n" -printf "(from the root directory of the repository) and then commit again.= \n" -printf "\nAborting commit.\n" - -exit 1 diff --git a/dev-tools/reformat-all.sh b/dev-tools/reformat-all.sh deleted file mode 100755 index 42d7368..0000000 --- a/dev-tools/reformat-all.sh +++ /dev/null @@ -1,136 +0,0 @@ -#!/bin/sh -# reformat-all.sh - Reformat all git files in the checked out -# git branch using uncrustify. -# -# Copyright (C) 2016-2024 - David Sommerseth -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130= 1, USA. -# - -tstamp=3D"$(date +%Y%m%d-%H%M%S)" -files=3D"$(pwd)/reformat-all_files-$tstamp.lst" -log=3D"$(pwd)/reformat-all_log-$tstamp.txt" - -srcroot=3D"$(git rev-parse --show-toplevel)" -cfg=3D"$srcroot/dev-tools/uncrustify.conf" -specialfiles=3D"$srcroot/dev-tools/special-files.lst" - -export gitfiles=3D0 -export procfiles=3D0 - -# Go to the root of the source tree -cd "$srcroot" - -{ - echo -n "** Starting $0: " - date - - # Find all C source/header files - git ls-files | grep -E ".*\.[ch](\.in$|$)" > "${files}.git" - - # Manage files which needs special treatment - awk -F\# '{gsub("\n| ", "", $1); print $1}' "$specialfiles" > "${files= }.sp" - while read srcfile - do - res=3D$(grep "$srcfile" "${files}.sp" 2>/dev/null) - if [ $? -ne 0 ]; then - # If grep didn't find the file among special files, - # process it normally - echo "$srcfile" >> "$files" - else - mode=3D$(echo "$res" | cut -d: -f1) - case "$mode" in - E) - echo "** INFO ** Excluding '$srcfile'" - ;; - P) - echo "** INFO ** Pre-patching '$srcfile'" - patchfile=3D"${srcroot}"/dev-tools/reformat-patches/be= fore_$(echo "$srcfile" | tr "/" "_").patch - if [ -r "$patchfile" ]; then - git apply "$patchfile" - if [ $? -ne 0 ]; then - echo "** ERROR ** Failed to apply pre-patch f= ile: $patchfile" - exit 2 - fi - else - echo "** WARN ** Pre-patch file for $srcfile is mi= ssing: $patchfile" - fi - echo "$srcfile" >> "${files}.postpatch" - echo "$srcfile" >> "$files" - ;; - *) - echo "** WARN ** Unknown mode '$mode' for file '$srcfi= le'" - ;; - esac - fi - done < "${files}.git" - rm -f "${files}.git" "${files}.sp" - - # Kick off uncrustify - echo - echo "** INFO ** Running: uncrustify -c $cfg --no-backup -l C -F $file= s" - uncrustify -c "$cfg" --no-backup -l C -F "$files" 2>&1 - res=3D$? - echo "** INFO ** Uncrustify completed (exit code $res)" -} | tee "${log}-1" # Log needs to be closed here, to be processed in next= block - -{ - # Check the results - gitfiles=3D$(wc -l "$files" | cut -d\ -f1) - procfiles=3D$(grep "Parsing: " "${log}-1" | wc -l) - echo - echo "C source/header files checked into git: $gitfiles" - echo "Files processed by uncrustify: $procfiles" - echo - - # Post-Patch files modified after we uncrustify have adjusted them - if [ -r "${files}.postpatch" ]; then - while read srcfile; - do - patchfile=3D"${srcroot}"/dev-tools/reformat-patches/after_$(ec= ho "$srcfile" | tr "/" "_").patch - if [ -r "$patchfile" ]; then - echo "** INFO ** Post-patching '$srcfile'" - git apply "$patchfile" - if [ $? -ne 0 ]; then - echo "** WARN ** Failed to apply $patchfile" - fi - else - echo "** WARN ** Post-patch file for $srcfile is missing: = $patchfile" - fi - done < "${files}.postpatch" - rm -f "${files}.postpatch" - fi -} | tee "${log}-2" # Log needs to be closed here, to be processed in next = block - -cat "${log}-1" "${log}-2" > "$log" - -{ - ec=3D1 - echo - if [ "$gitfiles" -eq "$procfiles" ]; then - echo "Reformatting completed successfully" - ec=3D0 - else - last=3D$(tail -n1 "${log}-1") - echo "** ERROR ** Reformating failed to process all files." - echo " uncrustify exit code: $res" - echo " Last log line: $last" - echo - fi - rm -f "${log}-1" "${log}-2" -} | tee -a "$log" -rm -f "${files}" - -exit $ec diff --git a/dev-tools/special-files.lst b/dev-tools/special-files.lst deleted file mode 100644 index e5f2fc2..0000000 --- a/dev-tools/special-files.lst +++ /dev/null @@ -1,5 +0,0 @@ -E:doc/doxygen/doc_key_generation.h # @verbatim section gets mistreated= , exclude it -E:src/compat/compat-lz4.c # Preserve LZ4 upstream formatting -E:src/compat/compat-lz4.h # Preserve LZ4 upstream formatting -E:src/openvpn/ovpn_dco_linux.h # Preserve ovpn-dco upstream format= ting -E:src/openvpn/ovpn_dco_win.h # Preserve ovpn-dco-win upstream fo= rmatting diff --git a/dev-tools/uncrustify.conf b/dev-tools/uncrustify.conf deleted file mode 100644 index 325f310..0000000 --- a/dev-tools/uncrustify.conf +++ /dev/null @@ -1,79 +0,0 @@ -# Use Allman-style -indent_columns=3D4 -indent_braces=3Dfalse -indent_else_if=3Dfalse -indent_switch_case=3D4 -indent_label=3D1 -nl_if_brace=3Dadd -nl_brace_else=3Dadd -nl_elseif_brace=3Dadd -nl_else_brace=3Dadd -nl_else_if=3Dremove -nl_for_brace=3Dadd -nl_while_brace=3Dadd -nl_switch_brace=3Dadd -nl_fdef_brace=3Dadd -nl_do_brace=3Dadd -sp_func_proto_paren=3DRemove -sp_func_def_paren=3DRemove -sp_func_call_paren=3DRemove -sp_sizeof_paren=3DRemove - -# No tabs, spaces only -indent_with_tabs=3D0 -align_with_tabs=3Dfalse -cmt_convert_tab_to_spaces=3Dtrue - -# Do not put spaces between the # and preprocessor statements -pp_space=3Dremove - -# Various whitespace fiddling -sp_assign=3Dadd -sp_before_sparen=3Dadd -sp_inside_sparen=3Dremove -sp_cond_colon=3Dadd -sp_cond_question=3Dadd -sp_bool=3Dadd -sp_else_brace=3Dadd -sp_brace_else=3Dadd -sp_after_comma=3Dadd -pos_arith=3DLead -pos_bool=3DLead -nl_func_type_name=3Dadd -nl_before_case=3Dtrue -nl_assign_leave_one_liners=3Dtrue -nl_enum_leave_one_liners=3Dtrue -nl_brace_fparen=3Dadd -nl_max=3D4 -nl_after_func_proto=3D2 -nl_end_of_file_min=3D1 -nl_end_of_file=3Dforce - -# Always use scoping braces for conditionals -mod_full_brace_if=3Dadd -mod_full_brace_if_chain=3Dfalse -mod_full_brace_while=3Dadd -mod_full_brace_for=3Dadd -mod_full_brace_do=3Dadd - -# Annotate #else and #endif statements -mod_add_long_ifdef_endif_comment=3D20 -mod_add_long_ifdef_else_comment=3D5 - -# Misc cleanup -mod_remove_extra_semicolon=3Dtrue - -# leave blank at end of empty for() statements -sp_after_semi_for_empty=3DAdd - -# Use C-style comments (/* .. */) -cmt_c_nl_end=3Dtrue -cmt_star_cont=3Dtrue -cmt_cpp_to_c=3Dtrue - -# Use "char **a"-style pointer stars/dereferences -sp_before_ptr_star=3DAdd -sp_between_ptr_star=3DRemove -sp_after_ptr_star=3DRemove -sp_before_byref=3DAdd -sp_after_byref=3DRemove -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/830?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: I15d4946800cbfaead67a73450ff3b12193814e54 Gerrit-Change-Number: 830 Gerrit-PatchSet: 10 Gerrit-Owner: flichtenheld Gerrit-Reviewer: cron2 Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: cron2 Gerrit-Attention: flichtenheld Gerrit-MessageType: newpatchset --Dz7Rvk91Le4= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: cron2, flichtenheld, plaisthos. <= /p>

flichtenheld uploaded patch set #10 to this change.

=

View C= hange

The following approvals got outdated and were removed: Code-Review-1 by cron2

Remove uncrustify config and scripts, switch GHA
=
Replaced with clang-format and pre-commit.

Add a README file tha= t explains how to use pre-commit
and how to combine this with the old ho= ok.

Change-Id: I15d4946800cbfaead67a73450ff3b12193814e54
Signed-o= ff-by: Frank Lichtenheld <frank@...2641...>
---
M .github/workf= lows/build.yaml
A dev-tools/README.precommit.md
D dev-tools/git-pre-c= ommit-uncrustify.sh
D dev-tools/reformat-all.sh
D dev-tools/special-f= iles.lst
D dev-tools/uncrustify.conf
6 files changed, 42 insertions(+= ), 402 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openv=
pn refs/changes/30/830/10
diff --git a/.github/workflows/build.yaml=
 b/.github/workflows/build.yaml
index d4fdc9d..37c09fe 1006= 44
--- a/.github/workflows/build.yaml
+++ b= /.github/workflows/build.yaml
@@ -5,35 +5,26 @@
<= span> pull_request:

jobs:
- checkuncrustify:
- name: "Check code style with= Uncrustify"
- = # Ubuntu 22.04 has uncrustify 0.72_f
- runs-on: ubuntu-22.04
+ clang-format:
+ name: Check code style with clang-format
+ runs-on: ubuntu-24.04<= br> steps:
- name: Install dependencies

- run: sudo apt up= date && sudo apt install -y uncrustify
+ run: |
+ sudo apt update && sudo apt install= -y python3-pip
+ = pip3 install pre-commit
- name: Checkout OpenV= PN
uses: actions/checkout@...2844... # v4.2.2
- with:
- path: openvpn

= - - name: Show uncrustify ve= rsion
- run: unc= rustify --version
- = - name: Run uncrustify
- working-directory: openvpn
+ - name: Run clang-format<= br>+ run: pre-commit run= -a --show-diff-on-failure || true
- name: Check for= changes
- run: = git diff --output=3Duncrustify-changes.patch
- working-directory: openvpn
- - name: Show changes on standard = output
- run: gi= t diff
- working= -directory: openvpn
+= run: git diff --output=3Dformat-changes.patch
= - uses: actions/upload-artifact@...2868... # v4.6.2
= with:
- na= me: uncrustify-changes.patch
- path: 'openvpn/uncrustify-changes.patch'+ name: format-change= s.patch
+ pa= th: format-changes.patch
- name: Set job status
- run: test ! -s unc= rustify-changes.patch
-= working-directory: openvpn
+ run: test ! -s format-changes.patch
=
android:
strategy:
diff --git a/dev-tools/README.precommit.md b/dev-tools/README.precommit.m= d

new file mode 100644
index 0000000..fe010= 58
--- /dev/null
+++ b/dev-tools/README.pre= commit.md
@@ -0,0 +1,30 @@
+How to use pre-commit hooks in openvpn repository
+=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
+
+openvpn comes with a .pre-commit-config.yaml which can be us= ed
+with https://pre-= commit.com/
+<= br>+To install the pre-commit h= ook you can just use
= +
+ pip install pr= e-commit
+ pre-com= mit install
+<= br>+This will enable the pre-co= mmit checks which currently only
+consists of a clang-format formatting check.
+
+**However**, in older branches, up to and including rele= ase/2.6
+we had a dif= ferent pre-commit hook
+formatting check based on the un= crustify tool.
+
+If you want to use both = pre-commit hooks you can use the following
+installation:
+
+ = rm .git/hooks/pre-commit # make sure to start fresh
+ git checkout release/2.6
+ ./dev-tools/git-pre-commit-u= ncrustify.sh install

= + git checkout master
+ pre-commit install --allow-missing-config
+
+This will run both hooks every time you commit but the "wr= ong" hook
+will = be skipped.
diff --git a/dev-tools/git-pre-commit-uncrustif= y.sh b/dev-tools/git-pre-commit-uncrustify.sh
deleted file = mode 100755
index 9851c21..0000000
--- a/de= v-tools/git-pre-commit-uncrustify.sh
+++ /dev/null@@ -1,161 +0,0 @@
-#!/bin/sh
-<= br>-# Copyright (c) 2015, David M= artin
-# = 2022, Heiko Hund
-# All= rights reserved.
-#
-# Redistribution and use= in source and binary forms, with or without
-# modification, are permitted provided that the foll= owing conditions are met:
-#
-# * Redistributi= ons of source code must retain the above copyright notice, this
<= span style=3D"color: hsl(0, 100%, 40%);">-# list of conditions and the fo= llowing disclaimer.

-#<= /span>
-# * Redistributions in= binary form must reproduce the above copyright notice,
-# this list of conditions and the follo= wing disclaimer in the documentation
-# and/or other materials provided with the distribution.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGH= T HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, = BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURP= OSE ARE
-# DISCLAIMED. = IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
= -# FOR ANY DIRECT, INDIRECT, INCI= DENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMEN= T OF SUBSTITUTE GOODS OR
-# CAUSED AND ON A= NY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-# OR TORT (INCLUDING NEGLIGENCE OR= OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBIL= ITY OF SUCH DAMAGE.
-
-
-# git pre-commit hook that runs an Uncrusti= fy stylecheck.
-# Featu= res:
-# - abort commit= when commit does not comply with the style guidelines
-# - create a patch of the proposed style = changes
-#
-# More info on Uncrustify: http://= uncrustify.sourceforge.net/

-
-# This file was= taken from a set of unofficial pre-commit hooks available
-# at https://github.com/ddddavidmartin= /Pre-commit-hooks and modified to
-# fit the openvpn project's needs
-
-# exit on error
= -set -e
-
-

-# If called so, install this script as pre-commit hook
-if [ "$1" =3D= "install" ] ; then
- TARGET=3D"$(git rev-parse --git-path hooks)/pre-commit&quo= t;
-
- if [ -e "$TARGET" ] ; then=
- printf "= $TARGET file exists. Won't overwrite.\n"
- printf "Aborting installation.\n&q= uot;
- exit 1
- fi
-
- read -p "Install as $TARGET? [y/N] " INPUT
- [ "$INPUT" = =3D "y" ] || exit 0
- cp "$0" "$TARGET"
- chmod +x $TARGET
- exit 0
-fi
-
-# check whether the give= n file matches any of the set extensions
-matches_extension() {
- local filename=3D"$(basename -- "$1")= "
- local exten= sion=3D".${filename##*.}"
- local ext
-
- for ext in = .c .h ; do [ "$ext" =3D "$extension" ] && retur= n 0; done
-
<= span style=3D"color: hsl(0, 100%, 40%);">- return 1

-}
-
-# necess= ary check for initial commit
-if git rev-parse --verify HEAD >/dev/null 2>&1 ; then
- against=3DHEAD<= br>-else
- # Initial commit: diff against an empty tr= ee object
- against= =3D4b825dc642cb6eb9a060e54bf8d69288fbee4904
-fi
-UNCRUSTIFY=3D$(com= mand -v uncrustify)
-UN= CRUST_CONFIG=3D"$(git rev-parse --show-toplevel)/dev-tools/uncrustify.= conf"
-
= -# 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>
-fi
-
-if [ -z "$UNCRUSTIFY" ] ; then
- printf "Error: uncrustify executab= le not found.\n"
-= printf "Is it installed and in your \$PATH?\n"
- printf "Aborting commit.\n&= quot;

- exit 1
-fi
-
-# create a filename to store our generated patch
-patch=3D$(mktemp /tmp/ovpn-fmt-XXXXXX)
-tmpout=3D$(mktemp /tmp/= uncrustify-XXXXXX)
-
-# create one patch conta= ining all changes to the files
-# sed to remove quotes around the filename, if inserted by the sys= tem
-# (done sometimes,= if the filename contains special characters, like the quote itself)=
-git diff-index --cached --di= ff-filter=3DACMR --name-only $against -- | \
-sed -e 's/^"\(.*\)"$/\1/' | \
-while read file
= -do
- # ignore file if we do check for file extension= s and the file
- # d= oes not match the extensions .c or .h
- if ! matches_extension "$file"; then- continue;
- fi

-
- # escape special characters in the target filename:
- # phase 1 (characters escaped in= the output diff):

- = # - '\': backslash needs to be escaped in the output diff
- # - '"= 9;: quote needs to be escaped in the output diff if present inside- # of the filena= me, as it used to bracket the entire filename part
- # phase 2 (characters escaped in the match= replacement):
- # = - '\': backslash needs to be escaped again for sed itself=
- # (i.e. doubl= e escaping after phase 1)
- # - '&': would expand to matched string
<= span style=3D"color: hsl(0, 100%, 40%);">- # - '|': used as = sed split char instead of '/'

- # printf %s particularly important if the filename cont= ains the % character
- = file_escaped_target=3D$(printf "%s" "$file" | sed -e= 's/[\"]/\\&/g' -e 's/[\&|]/\\&/g')=
-
- # uncrustify our sourcefile, create a patch w= ith diff and append it to our $patch
- # The sed call is necessary to transform the patch from<= /span>
- # --- - timesta= mp
- # +++ $tmpou= t timestamp
- # to b= oth lines working on the same file and having a a/ and b/ prefix.- # Else it can not be applie= d with 'git apply'.
- git show ":$file" | "$UNCRUSTIFY" -q -l C -c = "$UNCRUST_CONFIG" -o "$tmpout"
- git show ":$file" | diff -u -- -= "$tmpout" | \
-done
-<= br>-rm -f "$tmpout"
-
-# if no patch has been generated all is ok, cl= ean up the file stub and exit
-if [ ! -s "$patch" ] ; then
- rm -f "$patch"
- exit 0
-fi
-
-# a patch has been = created, notify the user and exit
-printf "Formatting of some code does not follow the projec= t guidelines.\n"
-=
-if [ $(wc -l < $pa= tch) -gt 80 ] ; then
- = printf "The file $patch contains the necessary fixes.\n"
-else
- printf "Here's the patch that = fixes the formatting:\n\n"
- cat $patch
-
-printf "\nYou can apply these ch= anges with:\n git apply $patch\n"

-printf "(from the root directory of the repository) a= nd then commit again.\n"
-printf "\nAborting commit.\n"
-
-exit 1
diff --git a/dev-tools/reformat-all.sh b/dev-to= ols/reformat-all.sh
deleted file mode 100755
index 42d7368..0000000

--- a/dev-tools/reformat-all.sh
+++ /dev/null
@@ -1,136 +0,0 @@
-#!/bin/sh

-# reformat-all.sh - Reformat all git files in t= he checked out
-# = git branch using uncrustify.
-#
-= # Copyright (C) 2016-2024 - David Sommerseth <davids@...515...>
-#
-# This program is free software; you can redist= ribute it and/or
-# mod= ify it under the terms of the GNU General Public License
-# as published by the Free Software Foun= dation; either version 2
-#=
-# This program is dis= tributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied= warranty of
-# MERCHAN= TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more deta= ils.
-#
-# You should have received a copy of = the GNU General Public License

-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Fra= nklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-
-tstamp= =3D"$(date +%Y%m%d-%H%M%S)"
-files=3D"$(pwd)/reformat-all_files-$tstamp.lst"
-log=3D"$(pwd)/refo= rmat-all_log-$tstamp.txt"
-
-srcroot=3D&q= uot;$(git rev-parse --show-toplevel)"
-cfg=3D"$srcroot/dev-tools/uncrustify.conf"
-specialfiles=3D"$s= rcroot/dev-tools/special-files.lst"
-
-ex= port gitfiles=3D0
-expo= rt procfiles=3D0
-
-# Go to the root of the so= urce tree
-cd "$sr= croot"
--{
- echo -n "** Starting $0: "
= - date
-
- # Find all C source/header files
- git ls-files | grep -E ".*\.[ch](\.in$|$= )" > "${files}.git"
-
- #= Manage files which needs special treatment
- awk -F\# '{gsub("\n| ", ""= ;, $1); print $1}' "$specialfiles" > "${files}.sp&quo= t;
- while read srcf= ile
- do
<= span style=3D"color: hsl(0, 100%, 40%);">- res=3D$(grep "$srcfi= le" "${files}.sp" 2>/dev/null)

- if [ $? -ne 0 ]; then
- # If grep didn't find th= e file among special files,
- # process it normally
- echo "$srcfile" >> "$fil= es"
- else<= /span>
- mode=3D$(e= cho "$res" | cut -d: -f1)
- case "$mode" in
- E)
- echo "** INFO ** Exc= luding '$srcfile'"
- ;;
- P)
- echo "** INFO ** Pre-patching '$srcfi= le'"
- = patchfile=3D"${srcroot}"/dev-tools/reformat-patches/b= efore_$(echo "$srcfile" | tr "/" "_").patch
- if = [ -r "$patchfile" ]; then
- git apply "$patchfile"
- if= [ $? -ne 0 ]; then
- = echo "** ERROR ** Failed to apply pre-patch= file: $patchfile"
- exit 2
- fi
- else
- echo "** WARN ** Pre-pa= tch file for $srcfile is missing: $patchfile"
- fi
- echo "$srcfile&quo= t; >> "${files}.postpatch"
- echo "$srcfile" >>= "$files"
- = ;;
- = *)
- = echo "** WARN ** Unknown mode '$mode' for file= '$srcfile'"
- ;;
- esac
-= fi
- done &l= t; "${files}.git"
- rm -f "${files}.git" "${files}.sp"
= -
- # Kick off uncrustify
- echo
- echo "** INFO ** Running: uncrustify -c $cfg --no-bac= kup -l C -F $files"
- res= =3D$?
- echo "*= * INFO ** Uncrustify completed (exit code $res)"
-} | tee "${log}-1" # Log needs t= o be closed here, to be processed in next block
-
-{
- # Check the= results
- gitfiles= =3D$(wc -l "$files" | cut -d\ -f1)
- procfiles=3D$(grep "Parsing: " "= ${log}-1" | wc -l)
- echo
- echo &q= uot;C source/header files checked into git: $gitfiles"
- echo "Files processed by unc= rustify: $procfiles"

- echo
-=
- # Post-Patch file= s modified after we uncrustify have adjusted them
- if [ -r "${files}.postpatch" ]; t= hen
- while read= srcfile;
- do
- patchfile= =3D"${srcroot}"/dev-tools/reformat-patches/after_$(echo "$sr= cfile" | tr "/" "_").patch
- if [ -r "$patchfile" = ]; then
- = echo "** INFO ** Post-patching '$srcfile'"
<= span style=3D"color: hsl(0, 100%, 40%);">- git apply "$= patchfile"

- = if [ $? -ne 0 ]; then
- echo "** WARN ** Failed to apply $patchf= ile"
- = fi
- els= e
- echo= "** WARN ** Post-patch file for $srcfile is missing: $patchfile"=
- fi=
- done < "${fi= les}.postpatch"
- = rm -f "${files}.postpatch"
- fi
-} | tee "${log}-2" # Log needs to be closed here, to be pr= ocessed in next block
-=
-cat "${log}-1&qu= ot; "${log}-2" > "$log"
-
-{
- ec=3D1
- echo
- if [ "$gitfiles" -eq "= ;$procfiles" ]; then
- echo "Reformatting completed successfully"
= - ec=3D0
- else
- last=3D$(tail -n1 "${log}-1")
- echo "** ERRO= R ** Reformating failed to process all files."
- echo " uncrustify e= xit code: $res"
- = echo " Last log line: $last"
- echo
- fi
- rm -f "${log}-1" "${log}-2"
-} | tee -a "$log"
=
-rm -f "${files}"
-
-exit $ec
diff --git a/dev-t= ools/special-files.lst b/dev-tools/special-files.lst
delete= d file mode 100644
index e5f2fc2..0000000
-= -- a/dev-tools/special-files.lst
+++ /dev/null
@@ -1,5 +0,0 @@

-E:= doc/doxygen/doc_key_generation.h # @verbatim section gets mistreated, e= xclude it
-E:src/compat= /compat-lz4.c # Preserve LZ4 upstream formatting
-E:src/compat/compat-lz4.h = # Preserve LZ4 upstream formatting

-E:src/openvpn/ovpn_dco_linux.h # Preserve ovpn-dco= upstream formatting
-E= :src/openvpn/ovpn_dco_win.h # Preserve ovpn-dco-win upstream form= atting
diff --git a/dev-tools/uncrustify.conf b/dev-tools/u= ncrustify.conf
deleted file mode 100644
ind= ex 325f310..0000000
--- a/dev-tools/uncrustify.conf<= br>+++ /dev/null
@@ -1,79 +0,0 @@
-# Use Allman-style
-indent_columns=3D4
-indent_braces=3Dfalse
-indent_else_if=3Dfalse
-indent_switch_case=3D4
-indent_label=3D1
-nl_if_brace=3Dadd
-nl_brace_else=3Dadd
-nl_elseif_brace=3Dadd
-nl_else_brace=3Dadd
-nl_else_if=3Dremove
-nl_for_brace=3Dadd
-nl_while_brace=3Dadd
-nl_switch_brace=3Dadd
-nl_fdef_brace=3Dadd
-nl_do_brace=3Dadd
-sp_func_proto_paren=3DRemove
-sp_func_def_paren=3DRemove
-sp_func_call_paren=3DRemove
-sp_sizeof_paren=3DRemove
-
-# No tabs, spaces only
-indent_with_tabs=3D0
-align_with_tabs=3Dfalse
-cmt_convert_tab_to_spaces=3Dtrue
-
-= # Do not put spaces between the # and preprocessor statements
-pp_space=3Dremove

-
-# Various whitespace fiddling
-sp_assign=3Dadd
-sp_before_sparen=3Dadd
-sp_inside_sparen=3Dremove
-sp_cond_colon=3Dadd
-sp_cond_question=3Dadd
-sp_bool=3Dadd
-sp_else_brace=3Dadd
-sp_brace_else=3Dadd
-sp_after_comma=3Dadd
-pos_arith=3DLead
-nl_= func_type_name=3Dadd
-n= l_before_case=3Dtrue
-n= l_assign_leave_one_liners=3Dtrue
-nl_enum_leave_one_liners=3Dtrue
-nl_brace_fparen=3Dadd
-nl_max=3D4
-nl_after_func_proto=3D2
-nl_end_of_file_min=3D1
-nl_end_of_file=3Dforce
-
-# Alway= s use scoping braces for conditionals
-mod_full_brace_if=3Dadd
-mod_full_brace_if_chain=3Dfalse
-mod_full_brace_while=3Dadd
-mod_full_brace_for=3Dadd
-mod_full_brace_do=3Dadd
-

-# Annotate #else and #endif statements
-mod_add_long_ifdef_endif_comment=3D20
-mod_add_long_ifdef_else_c= omment=3D5
-
= -# Misc cleanup
-mod_remove_extra_semicolon=3Dtrue
-
-# leave blank at end of empty for() statements
-sp_after_semi_for_empty= =3DAdd
-
-# Use C-style comments (/* .. */)
-cmt_c_nl_end=3Dtrue

-cmt_star_cont=3Dtrue
-cmt_cpp_to_c=3Dtrue<= br>-
-# Use "char **a"-style pointer stars/der= eferences
-sp_before_pt= r_star=3DAdd
-sp_betwee= n_ptr_star=3DRemove
-sp= _after_ptr_star=3DRemove
change= 830. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I15d4946800cbfaead67a73450ff= 3b12193814e54
Gerrit-Change-Number: 830
Gerrit-PatchSet: 10
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-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: cron2 <gert@...1296...>= ;
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newpatchset
--Dz7Rvk91Le4=--