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
26 if (defined $ARGV[0] && $ARGV[0] eq '--help') {
30 Nit-pick Xapian patches.
32 A patch can be supplied on stdin, or one or more patch files listed on the
35 Produces output suitable for use with vim's quick-fix mode, and similar
36 features in other editors.
40 git diff master.. | xapian-check-patch > tmp.qf
50 # SVN property changes don't have an "Index: [...]" line.
53 if (/^Index: (.+)/ || m!^diff --git a/.+ b/(.+)!) {
57 if ($fnm =~ /\.cc$/) {
59 } elsif ($fnm =~ /\.[ch]$/) {
60 $want_tabs = ($fnm !~ m!\blanguages/compiler/!);
61 } elsif ($fnm =~ /\.py(?:\.in)?$/) {
69 if (/^\@\@ -\d+,\d+ \+(\d+),\d+\b/) {
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:";
92 print "$fnm:$lineno: $msg";
99 my $first_char = substr($_, 0, 1);
100 if ($first_char eq ' ') {
102 } elsif ($first_char eq '+') {
105 } elsif ($first_char eq '-') {
109 print STDERR
<<"__END__";
110 Files patched
:\t$files
111 Lines added
:\t$add_lines
112 Lines removed
:\t$del_lines