Source

Target

Commits (8)
Showing with 52 additions and 32 deletions
......@@ -11,14 +11,15 @@ use strict;
use warnings;
use Cwd;
if ($#ARGV < 0 or $#ARGV > 1 || ($#ARGV == 1 && $ARGV[1] !~ /^(strict|gerrit(-rest)?)$/)) {
print STDERR "Usage: $0 <sha1> [strict]\n";
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";
exit 2;
}
my $sha1 = $ARGV[0];
my $gerrit_rest = ($#ARGV == 1 && $ARGV[1] eq "gerrit-rest");
my $gerrit = $gerrit_rest || ($#ARGV == 1 && $ARGV[1] eq "gerrit");
my $strict = $gerrit || ($#ARGV == 1 && $ARGV[1] eq "strict");
my $gerrit_rest = ($#ARGV >= 1 && $ARGV[1] eq "gerrit-rest");
my $gerrit = $gerrit_rest || ($#ARGV >= 1 && $ARGV[1] eq "gerrit");
my $strict = $gerrit || ($#ARGV >= 1 && $ARGV[1] eq "strict");
my $instance = ($#ARGV == 2) ? $ARGV[2] : "default";
my $repo = getcwd();
$repo =~ s,/?\.git$,,;
......@@ -27,6 +28,8 @@ my %config = ();
for (`git config --list`) {
if (/^sanity\.\Q$repo\E\.([^=]+)=(.*$)/) {
$config{$1} = $2;
} elsif (/^sanity\.\Q$instance\E\.([^=]+)=(.*$)/) {
$config{$1} = $2;
}
}
......@@ -41,10 +44,10 @@ if (defined $config{flags}) {
$cfg{$c} = 1;
}
}
my (%watch_files, %watch_people);
my (%watch_files, %watch_messages);
for my $key (keys %config) {
$watch_files{$1} = $config{$key} if ($key =~ /^watches\.([^.]+)\.files/);
$watch_people{$1} = $config{$key} if ($key =~ /^watches\.([^.]+)\.people/);
$watch_messages{$1} = $config{$key} if ($key =~ /^watches\.([^.]+)\.message/);
}
my $fail = 0;
my $file = "";
......@@ -99,7 +102,8 @@ my $iswip = defined($cfg{wip});
my $badrev = 0;
my $badsign = 0;
my $badid = defined($cfg{changeid});
my $badurl = defined($cfg{url});
my $badurl_rx = $config{badurl};
my $badurl = !defined($badurl_rx) || defined($cfg{url});
my $badlog = defined($cfg{log});
my $spell_check = !defined($cfg{spell});
my $parents = 0;
......@@ -133,6 +137,8 @@ sub complain_spelling()
# Given a line of text, searches for likely spelling errors.
sub check_spelling()
{
return if (!%MISTAKES_BASE);
my %seen;
my (@words) = split(/\b/);
foreach my $word (@words) {
......@@ -154,6 +160,26 @@ sub check_spelling()
}
}
my @style_fails = ();
sub styleFail($)
{
my $why = shift;
if ($gerrit_rest) {
complain_ln("$why", "style", -1);
} else {
push @style_fails, " $lineno: ".$why;
}
}
sub complain_style()
{
if (@style_fails) {
do_complain(1e9, "Style issues", "style", -1, @style_fails);
@style_fails = ();
}
}
sub check_apple_terminology()
{
if ($clike) {
......@@ -261,7 +287,7 @@ while (<MSG>) {
if (!$badid && /\bI[0-9a-f]{40}\b/ && !/^Change-Id: /) {
complain_ln("Gerrit change id outside Change-Id footer", "changeid");
}
if (!$badurl && /\bhttps?:\/\/(bugreports\.qt-project\.org\/browse\/|codereview\.qt-project\.org\/(\#change,|\#\/c\/)?\d+)/) {
if (!$badurl && /$badurl_rx/o) {
complain_ln("URL pointing to Gerrit or JIRA", "url");
}
my $ftr = 0;
......@@ -304,6 +330,9 @@ while (<MSG>) {
check_spelling() if ($spell_check);
check_apple_terminology();
styleFail("Trailing whitespace") if (s/[ \t]+\r?\n$//);
styleFail("Space indent followed by a TAB character") if (/^ +\t/);
styleFail("TAB character in non-leading whitespace") if (/\S *\t/);
}
close MSG;
printerr;
......@@ -322,6 +351,7 @@ if ($footer > 0 && !defined($cfg{footer})) {
}
complain_spelling();
complain_style();
my $chunk = 0;
my @addi = ();
......@@ -415,18 +445,6 @@ sub isExe($)
return $type =~ /^(ELF|PE32) /;
}
my @style_fails = ();
sub styleFail($)
{
my $why = shift;
if ($gerrit_rest) {
complain_ln("$why", "style", -1);
} else {
push @style_fails, " $lineno: ".$why;
}
}
my $no_copyright = 0;
sub flushFile()
......@@ -435,14 +453,12 @@ sub flushFile()
complain("Missing copyright header", "copyright");
}
complain_spelling();
if (@style_fails) {
do_complain(1e9, "Style issues", "style", -1, @style_fails);
@style_fails = ();
}
complain_style();
}
my $merge;
my $new_file;
my $is_bin;
my $maybe_bin;
my $is_special;
my $size;
......@@ -455,7 +471,8 @@ my $ws_check;
my $tsv_check;
my $eof_check;
my $ctlkw_check;
open DIFF, "git diff-tree --patience --no-commit-id --diff-filter=ACMR --src-prefix=\@old\@/ --dst-prefix=\@new\@/ --full-index -r -U100000 --cc -C -l1000 --root ".$sha1." |" or die "cannot run git: $!";
my $apple_check;
open DIFF, "git diff-tree --patience --no-commit-id --diff-filter=ACMR --ignore-submodules --src-prefix=\@old\@/ --dst-prefix=\@new\@/ --full-index -r -U100000 --cc -C -l1000 --root ".$sha1." |" or die "cannot run git: $!";
while (<DIFF>) {
if (/^-/) {
if ($mixws_check) {
......@@ -492,6 +509,7 @@ while (<DIFF>) {
}
next;
}
next if ($is_bin);
$lineno++;
if ($merge) {
# Consider only lines which are new relative to both parents, i.e., were added during the merge.
......@@ -535,7 +553,7 @@ while (<DIFF>) {
}
}
check_spelling() if ($spell_check);
check_apple_terminology();
check_apple_terminology() if ($apple_check);
} else {
flushChunk() if ($chunk);
if (/^ /) {
......@@ -569,24 +587,26 @@ while (<DIFF>) {
$qmake = ($file =~ /\.pr[filo]$/i);
for my $key (keys %watch_files) {
if ($file =~ /^$watch_files{$key}$/) {
complain("Changing this file is risky. Please add $watch_people{$key} as reviewer(s).", "", -1);
complain($watch_messages{$key}, "", -1);
}
}
my $foreign = ($file =~ /(^|\/)3rdparty\//);
$is_bin = ($file =~ /\.(ps|pdf)$/);
my $foreign = $is_bin || ($file =~ /(^|\/)3rdparty\//);
$new_file = 0;
$maybe_bin = 0;
$is_special = 0;
$crlf_fail = defined($cfg{crlf});
$crlf_fail = $is_bin || defined($cfg{crlf});
$in_plus = 0;
$mixws_check = !$merge && !$foreign && $clike && !defined($cfg{mixws});
$ws_check = !defined($cfg{style}) && !$foreign && ($file !~ /\.(ts|diff|patch)$|^\.gitmodules$/);
$tsv_check = $ws_check && ($file =~ /((^|\/)objects\.map$|\.tsv$)/);
$tabs_check = $ws_check && !$tsv_check && !defined($cfg{tabs}) && ($file !~ /((^|\/)Makefile\b|debian[.\/]rules|\.(plist(\.[^.\/]+)?|def|spec|changes|[xn]ib|storyboardc?)$)/);
$ctlkw_check = $tabs_check && $clike;
$eof_check = ($file !~ /\.plist(\.[^.\/]+)?$/); # Xcode consistently forgets the trailing newline
$eof_check = !$is_bin && ($file !~ /\.plist(\.[^.\/]+)?$/); # Xcode consistently forgets the trailing newline
# .ts files usually contain languages other than English
$spell_check = !defined($cfg{spell}) && !$foreign && ($file !~ /\.ts$/i);
$conflict_fail = defined($cfg{conflict});
$apple_check = !$foreign && ($file !~ /\.ts$/i);
$conflict_fail = $is_bin || defined($cfg{conflict});
$braces = 0;
$check_gen = 0;
$no_copyright = 0;
......