checkpatch: Fix check for embedded filename
PATCH 1/1 checkpatch: Fix check for embedded filename
When checkpatch is run on file contents piped through stdin, it may generate false EMBEDDED_FILENAME warnings if the --file flag is used.
Consider the following test file:
$cat test.c
int x = a - b;
$cat test.c | ./scripts/checkpatch.pl -f
WARNING: It's generally not useful to have the filename in the file +int x = a - b;
So any instance of "-" in the file contents will trigger an EMBEDDED_FILENAME warning.
Fix it by checking if $realfile is not "-".
--- scripts/checkpatch.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/checkpatch.pl +1 -1
@@ -3619,7 +3619,7 @@ sub process { } # check for embedded filenames - if ($rawline =~ /^\+.*\Q$realfile\E/) { + if ($realfile ne "-" && $rawline =~ /^\+.*\Q$realfile\E/) { WARN("EMBEDDED_FILENAME", "It's generally not useful to have the filename in the file\n" . $herecurr); }
Signature · 1 line
2.28.0
Joe Perches
maintainerQuoted 3 lines · Dwaipayan Ray
When checkpatch is run on file contents piped through stdin, it may generate false
EMBEDDED_FILENAMEwarnings if the --file flag is used.
I think this is a "don't do that" scenario and this change is not necessary.
Quoted 9 lines · Joe Perches
Quoted 3 lines · Dwaipayan Ray
When checkpatch is run on file contents piped through stdin, it may generate false
EMBEDDED_FILENAMEwarnings if the --file flag is used.I think this is a "don't do that" scenario and this change is not necessary.
Okay then. I will drop this.
Sorry for the noise.
Thanks & Regards,
Dwaipayan.
Joe Perches
maintainerQuoted 7 lines · Dwaipayan Ray
Quoted 6 lines · Joe Perches
Quoted 3 lines · Dwaipayan Ray
When checkpatch is run on file contents piped through stdin, it may generate false
EMBEDDED_FILENAMEwarnings if the --file flag is used.
Quoted 6 lines
Quoted 3 lines
I think this is a "don't do that" scenario and this change is not necessary.
Okay then. I will drop this.
Sorry for the noise.
I think you want something like this:
--- scripts/checkpatch.pl | 1 + 1 file changed, 1 insertion(+)
scripts/checkpatch.pl +1 -0
@@ -331,6 +331,7 @@ help(0) if ($help); die "$P: --git cannot be used with --file or --fix\n" if ($git && ($file || $fix)); die "$P: --verbose cannot be used with --terse\n" if ($verbose && $terse); +die "$P: -f/--file requires at least one filename\n" if ($file && $#ARGV < 0); if ($color =~ /^[01]$/) { $color = !$color;
Quoted 27 lines · Joe Perches
Quoted 7 lines · Dwaipayan Ray
Quoted 6 lines · Joe Perches
Quoted 3 lines · Dwaipayan Ray
When checkpatch is run on file contents piped through stdin, it may generate false
EMBEDDED_FILENAMEwarnings if the --file flag is used.Quoted 6 lines
Quoted 3 lines
I think this is a "don't do that" scenario and this change is not necessary.
Okay then. I will drop this.
Sorry for the noise.I think you want something like this:
--- scripts/checkpatch.pl | 1 + 1 file changed, 1 insertion(+)scripts/checkpatch.pl +0
-0
scripts/checkpatch.pl help(0) if ($help); · line 337
Quoted 7 lines
scripts/checkpatch.pl +1
-0@@ -331,6 +331,7 @@ help(0) if ($help); die "$P: --git cannot be used with --file or --fix\n" if ($git && ($file || $fix)); die "$P: --verbose cannot be used with --terse\n" if ($verbose && $terse); +die "$P: -f/--file requires at least one filename\n" if ($file && $#ARGV < 0); if ($color =~ /^[01]$/) { $color = !$color;
Yes, that's nice.
Most of the checks don't work with piped input when --file is specified. So disabling it will avoid any confusion.
I can send in a patch if it's okay with you.
Thanks,
Dwaipayan.
Joe Perches
maintainerQuoted 12 lines · Dwaipayan Ray
Quoted 11 lines · Joe Perches
Quoted 10 lines · Dwaipayan Ray
Quoted 8 lines · Joe Perches
Quoted 3 lines · Dwaipayan Ray
When checkpatch is run on file contents piped through stdin, it may generate false
EMBEDDED_FILENAMEwarnings if the --file flag is used.I think this is a "don't do that" scenario and this change is not necessary.
Quoted 6 lines
scripts/checkpatch.pl
Quoted 6 lines
Quoted 2 lines
Okay then. I will drop this.
Sorry for the noise.I think you want something like this:
---scripts/checkpatch.pl +0
-0
[]
Quoted 14 lines
scripts/checkpatch.pl help(0) if ($help); · line 337
Quoted 9 lines
scripts/checkpatch.pl +1
-0@@ -331,6 +331,7 @@ help(0) if ($help); die "$P: --git cannot be used with --file or --fix\n" if ($git && ($file || $fix)); die "$P: --verbose cannot be used with --terse\n" if ($verbose && $terse); +die "$P: -f/--file requires at least one filename\n" if ($file && $#ARGV < 0); if ($color =~ /^[01]$/) { $color = !$color;Yes, that's nice.
Most of the checks don't work with piped input when --file is specified. So disabling it will avoid any confusion.
Quoted 1 line
I can send in a patch if it's okay with you.
Fine by me. You noticed, your patch...