[PATCH] checkpatch: Fix line number reporting

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Andy Whitcroft <apw@...>
Cc: <linux-kernel@...>, Erez Zadok <ezk@...>, Ingo Molnar <mingo@...>
Date: Friday, October 12, 2007 - 3:26 pm

Fix line number reporting when checking source files (as opposed to
patches)

Signed-off-by: Mike D. Day <ncmike@us.ibm.com>
---
checkpatch.pl-next (as of Oct. 12) reports lines incorrectly when
checking source files as opposed to checking patches.

A line number will show up twice in a normal message, 3 times when
using the --emacs option. Here is an example using the 10/12 version:

~/slp-devel/src/cmd-utils/slp_query/slp_query.c:9:
ERROR: trailing whitespace #13: FILE:
~/slp-devel/src/cmd-utils/slp_query/slp_query.c:10:

In the report above, checkpatch reports three different line numbers:
9, 13, and 10. When using the --file option, all numbers are supposed
to be the same. One of the errors is caused by initializing the prefix
too early. By moving that line from 606 to 675 there an improvement,
though still incorrect:

~/slp-devel/src/cmd-utils/slp_query/slp_query.c:10:
ERROR: trailing whitespace #13: FILE:
~/slp-devel/src/cmd-utils/slp_query/slp_query.c:10: 

To check a sourcefie, checkpatch diffs that file with /dev/null and
pipes the resulting patch into stdin. Checkpatch uses different
variables to keep track of a patch ($linenr) and the corresponding
line in the sourcefile ($realline). Since the sourcefile *is* a patch
in this case, the line number is reported incorrectly.

To fix this, checkpatch needs to alter the variable it uses for the
source line when the --file option is used, as below. 

$prefix = "$filename:$realline: " if ($emacs && $file);
$prefix = "$filename:$linenr: " if ($emacs && !$file);
 
--- checkpatch.pl-next-10-12	2007-10-12 13:39:21.000000000 -0400
+++ checkpatch.pl	2007-10-12 14:30:55.000000000 -0400
@@ -606,7 +606,6 @@
 
 		my $rawline = $line;
 
-		$prefix = "$filename:$realline: " if ($emacs);
 
 #extract the filename as it passes
 		if ($line=~/^\+\+\+\s+(\S+)/) {
@@ -665,13 +664,16 @@
 		}
 
 #make up the handle for any error we report on this line
-		$here = "#$linenr: ";
+		$here = "#$linenr: " if (!$file);
+		$here = "#$realline: " if ($file);
 		$here .= "FILE: $realfile:$realline:" if ($realcnt != 0);
 
 		my $hereline = "$here\n$line\n";
 		my $herecurr = "$here\n$line\n";
 		my $hereprev = "$here\n$prevline\n$line\n";
 
+		$prefix = "$filename:$realline: " if ($emacs && $file);
+		$prefix = "$filename:$linenr: " if ($emacs && !$file);
 		$cnt_lines++ if ($realcnt != 0);
 
 #check the patch for a signoff:

-- 
Mike D. Day
IBM LTC
Cell: 919 412-3900
Sametime: ncmike@us.ibm.com AIM: ncmikeday  Yahoo: ultra.runner
PGP key: http://www.ncultra.org/ncmike/pubkey.asc
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] checkpatch: Fix line number reporting, Mike D. Day, (Fri Oct 12, 3:26 pm)
Re: [PATCH] checkpatch: Fix line number reporting, Andy Whitcroft, (Fri Oct 12, 3:37 pm)
Re: [PATCH] checkpatch: Fix line number reporting , Erez Zadok, (Sat Oct 13, 2:35 pm)
Re: [PATCH] checkpatch: Fix line number reporting, Andy Whitcroft, (Mon Oct 15, 2:21 pm)
Re: [PATCH] checkpatch: Fix line number reporting , Erez Zadok, (Tue Oct 16, 1:59 pm)
Re: [PATCH] checkpatch: Fix line number reporting, Andy Whitcroft, (Wed Oct 17, 12:39 pm)
latest checkpatch, Ingo Molnar, (Thu Oct 18, 7:13 am)
Re: latest checkpatch, Andy Whitcroft, (Thu Oct 18, 3:25 pm)
Re: latest checkpatch, Andy Whitcroft, (Thu Oct 18, 3:43 pm)
Re: latest checkpatch, Ingo Molnar, (Thu Oct 18, 4:00 pm)
Re: latest checkpatch, Ingo Molnar, (Thu Oct 18, 3:39 pm)
Re: latest checkpatch, Ilpo Järvinen, (Fri Oct 19, 5:12 am)
Re: latest checkpatch, Avi Kivity, (Thu Oct 18, 4:02 pm)
Re: latest checkpatch, Andi Kleen, (Thu Oct 18, 7:16 pm)
Re: latest checkpatch, Ingo Molnar, (Thu Oct 18, 4:51 pm)
Re: latest checkpatch, Andy Whitcroft, (Fri Oct 19, 5:01 am)
Re: latest checkpatch, Jeff Garzik, (Thu Oct 18, 4:57 pm)
Re: latest checkpatch, Randy Dunlap, (Thu Oct 18, 6:25 pm)