Fix syntax error in SmokeTest.java
[xapian.git] / xapian-maintainer-tools / xapian-check-patch
blob128a6c2cc64c8192c0af4ceafd4cadb4893f6a7f
1 #! /usr/bin/perl -w
2 # Copyright (c) 2007-2015 Olly Betts
4 # Permission is hereby granted, free of charge, to any person obtaining a copy
5 # of this software and associated documentation files (the "Software"), to
6 # deal in the Software without restriction, including without limitation the
7 # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 # sell copies of the Software, and to permit persons to whom the Software is
9 # furnished to do so, subject to the following conditions:
11 # The above copyright notice and this permission notice shall be included in
12 # all copies or substantial portions of the Software.
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 # IN THE SOFTWARE.
22 require 5.000;
23 use strict;
24 use POSIX;
26 if (defined $ARGV[0] && $ARGV[0] eq '--help') {
27 print <<END;
28 Syntax: $0 [PATCH]...
30 Nit-pick Xapian patches.
32 A patch can be supplied on stdin, or one or more patch files listed on the
33 command line.
35 Produces output suitable for use with vim's quick-fix mode, and similar
36 features in other editors.
38 Example usage:
40 git diff master.. | xapian-check-patch > tmp.qf
41 vim -q tmp.qf
42 END
43 exit 0;
46 my ($fnm, $lineno);
47 my $add_lines = 0;
48 my $del_lines = 0;
49 my $files = 0;
50 # SVN property changes don't have an "Index: [...]" line.
51 my $want_tabs = -1;
52 while (<>) {
53 if (/^Index: (.+)/ || m!^diff --git a/.+ b/(.+)!) {
54 ++$files;
55 $fnm = $1;
56 $lineno = undef;
57 if ($fnm =~ /\.cc$/) {
58 $want_tabs = 1;
59 } elsif ($fnm =~ /\.[ch]$/) {
60 $want_tabs = ($fnm !~ m!\blanguages/compiler/!);
61 } elsif ($fnm =~ /\.py(?:\.in)?$/) {
62 $want_tabs = 0;
63 } else {
64 # Don't know!
65 $want_tabs = -1;
67 next;
69 if (/^\@\@ -\d+,\d+ \+(\d+),\d+\b/) {
70 $lineno = $1;
71 next;
73 my $msg;
74 if (/^\+.*[ \t]$/) {
75 $msg = "added/changed line has trailing whitespace:";
76 } elsif (/^\+.* \t/) {
77 $msg = "added/changed line has space before tab:";
78 } elsif ($want_tabs == 1 and /^\+\t* {8}/) {
79 $msg = "added/changed line uses spaces for indentation rather than tab:";
80 } elsif (!$want_tabs and /^\+ *\t/) {
81 $msg = "added/changed line uses tab for indentation rather than spaces:";
82 } elsif (/^-.*\bFIX(?:ME)\b/) {
83 $msg = "FIX"."ME removed:";
84 } elsif (/^\+.*\bFIX(?:ME)\b/) {
85 $msg = "FIX"."ME added:";
86 } elsif (/^\+.*\\([abcefp]|brief|code|deprecated|endcode|exception|file|internal|li|param|private|return|todo)\b/) {
87 $msg = "Doxygen command '\\$1' introduced by '\\' not '\@':";
88 } elsif (m!(?:^|[;{])\s*/[/*]{1,2}\w!) {
89 $msg = "added/changed line has comment without whitespace before the text:";
91 if (defined $msg) {
92 print "$fnm:$lineno: $msg";
93 if ($msg =~ /:$/) {
94 print " $_";
95 } else {
96 print "\n";
99 my $first_char = substr($_, 0, 1);
100 if ($first_char eq ' ') {
101 ++$lineno;
102 } elsif ($first_char eq '+') {
103 ++$lineno;
104 ++$add_lines;
105 } elsif ($first_char eq '-') {
106 ++$del_lines;
109 print STDERR <<"__END__";
110 Files patched:\t$files
111 Lines added:\t$add_lines
112 Lines removed:\t$del_lines
113 __END__