cppcheck: add a -o option to check modified or staged changes

Change-Id: I336400441302549967db048bedc70980b04c5030
Reviewed-on: https://code.wireshark.org/review/37613
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Martin Mathieson 2020-06-29 23:52:56 +01:00 committed by Anders Broman
parent d000ff3e6c
commit 5258ceadb3
1 changed files with 9 additions and 1 deletions

View File

@ -13,6 +13,7 @@
# -x xml output (default is gcc)
# -j n threads (default: 4)
# -l n check files from the last [n] commits
# -o check modified files
# -v quiet mode
# If argument file is omitted then checking all files in the current directory.
#
@ -39,6 +40,7 @@ SUPPRESSIONS="--suppressions-list=$CPPCHECK_DIR/suppressions"
INCLUDES="--includes-file=$CPPCHECK_DIR/includes"
MODE="gcc"
COLORIZE_HTML_MODE="no"
OPEN_FILES="no"
XML_ARG=""
colorize_worker()
@ -56,7 +58,7 @@ colorize()
[ -z "$1" ] && colorize_worker || colorize_worker <<< "$1"
}
while getopts "achxj:l:v" OPTCHAR ; do
while getopts "achxj:l:ov" OPTCHAR ; do
case $OPTCHAR in
a) SUPPRESSIONS=" " ;;
c) COLORIZE_HTML_MODE="yes" ;;
@ -64,6 +66,7 @@ while getopts "achxj:l:v" OPTCHAR ; do
x) MODE="xml" ;;
j) THREADS="$OPTARG" ;;
l) LAST_COMMITS="$OPTARG" ;;
o) OPEN_FILES="yes" ;;
v) QUIET=" " ;;
*) printf "Unknown option %s" "$OPTCHAR"
esac
@ -86,6 +89,11 @@ if [ "$LAST_COMMITS" -gt 0 ] ; then
TARGET=$( git diff --name-only HEAD~"$LAST_COMMITS".. | grep -E '\.(c|cpp)$' )
fi
if [ "$OPEN_FILES" = "yes" ] ; then
TARGET=$(git diff --name-only | grep -E '\.(c|cpp)$' )
TARGET="$TARGET $(git diff --staged --name-only | grep -E '\.(c|cpp)$' )"
fi
if [ $# -gt 0 ]; then
TARGET="$TARGET $*"
fi