summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@theqtcompany.com>2016-03-23 12:53:44 +0100
committerOswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>2016-04-12 15:36:54 +0000
commit49d25c47a5e5615269785d50e24593ec1f1abf48 (patch)
tree0c11a35733d4472ecc007cd4aaf8c816dcadfe2d
parent7d46cc64e159da36241aba6bde1b34c057202772 (diff)
Object to adding defective PNGs (usually bad sRGB chunks).
Some tools warn about them and they are (usually) superfluous. Only tests if you have the ImageMagic package's identify command. Ossi assures me this is adequately widely installed for Gerrit. Change-Id: Icd6f47fb0695e287f7de9d45b3521c82cc85cecd Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
-rwxr-xr-xgit-hooks/sanitize-commit31
1 files changed, 31 insertions, 0 deletions
diff --git a/git-hooks/sanitize-commit b/git-hooks/sanitize-commit
index f449551..48dd1d0 100755
--- a/git-hooks/sanitize-commit
+++ b/git-hooks/sanitize-commit
@@ -9,8 +9,11 @@
use strict;
use warnings;
+use Config;
use Cwd;
use Encode;
+use File::Spec qw(path);
+use List::Util qw(any);
if ($#ARGV < 0 or $#ARGV > 2 or ($#ARGV >= 1 && $ARGV[1] !~ /^(easy|strict|gerrit(-rest)?)$/)) {
print STDERR "Usage: $0 <sha1> [{easy|strict|gerrit|gerrit-rest} [instance]]\n";
@@ -177,6 +180,27 @@ sub check_spelling()
}
}
+my $seenIdentify; # Cached result of PATH check
+sub haveIdentify()
+{
+ $seenIdentify = any { $_ && -x "$_/identify$Config{_exe}" } File::Spec->path()
+ unless defined($seenIdentify);
+ return $seenIdentify;
+}
+
+sub dodgyPng($$)
+{
+ # Not uncommonly, PNGs get generated with a bogus sRGB chunk; this
+ # can readily be removed using pngcrush, eliminating the warning
+ # from identify. This check may find other kinds of errors; we'll
+ # have to learn how to fix those when we meet them. The identify
+ # program is part of the ImageMagick package.
+ my ($commit, $file) = @_;
+ my $err = `git cat-file blob "$commit:$file" 2>/dev/null | \
+ identify - 2>&1 1>/dev/null`;
+ return $err =~ m/\bMagickPNGWarningHandler\b/;
+}
+
my @style_fails = ();
sub styleFail($)
@@ -653,6 +677,13 @@ while (<DIFF>) {
complain("Changing huge binary file (".formatSize($size)." > 2MiB)", "giant", 1);
}
}
+ if ($file =~ /\.png$/i
+ # If identify is available, check for faults:
+ && haveIdentify() && dodgyPng($sha1, $file)
+ # Only complain if the issue is new, of course:
+ && ($new_file || !dodgyPng("${sha1}^", $file))) {
+ complain("Defect in PNG format, see: identify $file", "cruft");
+ }
next;
}
if ($_ eq "new file mode 160000\n" || $_ eq "new file mode 120000\n") {