Whamcloud - gitweb
LU-6142 contrib: git plugins 01/54101/2
authorTimothy Day <timday@amazon.com>
Tue, 20 Feb 2024 02:44:12 +0000 (02:44 +0000)
committerOleg Drokin <green@whamcloud.com>
Mon, 4 Mar 2024 19:58:31 +0000 (19:58 +0000)
Git plugins to quick see the progress towards
checkpatch cleanups in Lustre.

The original (git-tabcheck) was authored by
Andreas Dilger to help with space to tabs conversion.
The second (git-checkpatch) was modified from
the original script to help capture generic
checkpatch warnings.

Signed-off-by: Timothy Day <timday@amazon.com>
Change-Id: Iab7aaa70690d00f1b7dd5ebcd2412865dae34729
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/54101
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
contrib/git-cmds/git-checkpatch [new file with mode: 0755]
contrib/git-cmds/git-tabcheck [new file with mode: 0755]

diff --git a/contrib/git-cmds/git-checkpatch b/contrib/git-cmds/git-checkpatch
new file mode 100755 (executable)
index 0000000..3cfe04e
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-only
+
+#
+# This file is part of Lustre, http://www.lustre.org/
+#
+# contrib/git-cmds/git-checkpatch
+#
+# Check the progress of checkpatch.pl fixes in the
+# Lustre tree. Modified from git-tabcheck.
+#
+# Author: Andreas Dilger <adilger@whamcloud.com>
+# Modified by: Timothy Day <timday@amazon.com>
+#
+
+export CHECKPATCH=${CHECKPATCH:-"./contrib/scripts/checkpatch.pl"}
+
+DIRS="$*"
+[ -z "$DIRS" ] && DIRS="ls -d */"
+
+for D in $DIRS; do
+       [ ! -d "$D" ] && continue
+       FILES=$(find "$D" -name "*.[ch]")
+
+       [ -z "$FILES" ] && continue
+       TOT="$(echo "$FILES" | xargs cat | wc -l)"
+
+       [ -z "$TOT" ] && continue
+       CNT="$(echo "$FILES" | xargs -I{} bash -c '$CHECKPATCH --terse -f $1' _ {} | grep -v "total:" | wc -l)"
+
+       D=$(basename "$D")
+
+       printf "%-16s %-10s %-11s \n" \
+              "$D:" "loc=$TOT" "errors/warnings=$CNT"
+done
diff --git a/contrib/git-cmds/git-tabcheck b/contrib/git-cmds/git-tabcheck
new file mode 100755 (executable)
index 0000000..7075fe9
--- /dev/null
@@ -0,0 +1,37 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-only
+
+#
+# This file is part of Lustre, http://www.lustre.org/
+#
+# contrib/git-cmds/git-tabcheck
+#
+# Check the progress of space -> tab conversion in the
+# Lustre tree.
+#
+# Author: Andreas Dilger <adilger@whamcloud.com>
+#
+
+DIRS="$*"
+[ -z "$DIRS" ] && DIRS="ls -d */"
+
+for D in $DIRS; do
+       [ ! -d "$D" ] && continue
+       FILES=$(find "$D" -name "*.[ch]" -o -name "*.sh")
+
+       [ -z "$FILES" ] && continue
+       TOT="$(echo "$FILES" | xargs cat | wc -l)"
+
+       [ -z "$TOT" ] && continue
+       TAB="$(echo "$FILES" | xargs grep "\t" | wc -l)"
+       SPC="$(echo "$FILES" | xargs grep "^    " | wc -l)"
+
+       PCB=$(((TAB * 1000 + 5) / TOT / 10))
+       PCS=$(((SPC * 1000 + 5) / TOT / 10))
+       PCT=$(((TAB * 1000 + 5) / (TAB + SPC) / 10))
+
+       D=$(basename "$D")
+
+       printf "%-16s %-10s %-11s %6s %-11s %6s %-10s\n" \
+              "$D:" "loc=$TOT" "tabs=$TAB" "($PCB%)" "space=$SPC" "($PCS%)" "$PCT%"
+done