Skip to content

Commit b186cd4

Browse files
committed
Remove dependency on external tool for summary
Commit 1c6b5c4 used 'diffstat' to summarize insertions and deletions. Now, built-in git commands achieve the same result, allowing the removal of the 'diffstat' dependency. Change-Id: I7955b279a083d585d1a3d3bce26308d5ba4f899b
1 parent 2078cee commit b186cd4

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

scripts/pre-commit.hook

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,20 @@ for FILE in $C_FILES; do
207207
fi
208208
done
209209

210+
# Show insertion and deletion counts.
210211
if [ "${#FILES[@]}" -gt 0 ]; then
211212
echo "Following files were changed:"
212213
for file in "${FILES[@]}"; do
213-
if command -v diffstat >/dev/null 2>&1; then
214-
summary=$(git diff --cached "$file" | diffstat -s | sed -E 's/^[[:space:]]*[0-9]+ files? changed,?[[:space:]]*//')
215-
echo " - $file | $summary"
214+
summary=$(git diff --cached --numstat "$file" | awk '{
215+
if ($1 != "0" && $2 != "0")
216+
printf "%s insertions(+), %s deletions(-)", $1, $2;
217+
else if ($1 != "0")
218+
printf "%s insertions(+)", $1;
219+
else if ($2 != "0")
220+
printf "%s deletions(-)", $2;
221+
}')
222+
if [ -n "$summary" ]; then
223+
echo " - $file : $summary"
216224
else
217225
echo " - $file"
218226
fi

0 commit comments

Comments
 (0)