Validate the Diameter XML files in the pre-commit script.

Validation requires xmllint but will pass (with a complaint) if the committer
does not have xmllint installed.

Change-Id: I336a1c8ad8e1f98805a284d8c4736810b1a9c54e
Reviewed-on: https://code.wireshark.org/review/18609
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Jeff Morriss 2016-11-01 21:29:11 -04:00 committed by Anders Broman
parent e1454337df
commit 8a376d4cd3
2 changed files with 17 additions and 7 deletions

View File

@ -53,6 +53,7 @@ fi
exit_status=0
COMMIT_FILES=`git diff-index --cached --name-status ${COMMIT_ID} | grep -v "^D" | cut -f2 | grep "\.[ch]$"`
DIAMETER_FILES=`git diff-index --cached --name-status ${COMMIT_ID} | grep -v "^D" | cut -f2 | grep diameter/`
# Path to filter script in the tools directory
filter_script=${PWD}/tools/pre-commit-ignore.py
@ -91,6 +92,11 @@ for FILE in $CHECK_FILES; do
done
if [ "x$DIAMETER_FILES" != x ]
then
./tools/validate-diameter-xml.sh > /dev/null || exit_status=1
fi
# If there are whitespace errors, print the offending file names and fail. (from git pre-commit.sample)
git diff-index --check --cached ${COMMIT_ID} || exit_status=1

View File

@ -24,24 +24,28 @@
if ! type -p sed > /dev/null
then
echo "Sorry, 'sed' is needed to run this program."
exit 1
echo "'sed' is needed to run $0." 1>&2
# Exit cleanly because we don't want pre-commit to fail just because
# someone doesn't have the tools...
exit 0
fi
if ! type -p xmllint > /dev/null
then
echo "Sorry, 'xmllint' is needed to run this program."
exit 1
echo "'xmllint' is needed to run $0." 1>&2
# Exit cleanly because we don't want pre-commit to fail just because
# someone doesn't have the tools...
exit 0
fi
# Ideally this would work regardless of our cwd
if [ ! -r diameter/dictionary.xml ]
then
echo "Couldn't find diameter/dictionary.xml"
echo "Couldn't find diameter/dictionary.xml" 1>&2
exit 1
fi
if [ ! -r diameter/dictionary.dtd ]
then
echo "Couldn't find diameter/dictionary.dtd"
echo "Couldn't find diameter/dictionary.dtd" 1>&2
exit 1
fi
@ -59,7 +63,7 @@ do
done
xmllint --noout --noent --postvalid /tmp/diameter/dictionary.xml &&
echo "Diameter dictionary is (mostly) valid XML!"
echo "Diameter dictionary is (mostly) valid XML."
rm -rf /tmp/diameter