qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scripts/checkpatch.pl: remove bogus patch prefix warning
@ 2025-10-30 20:13 Vladimir Sementsov-Ogievskiy
  2025-10-31 11:08 ` Daniel P. Berrangé
  2025-10-31 11:59 ` Paolo Bonzini
  0 siblings, 2 replies; 3+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2025-10-30 20:13 UTC (permalink / raw)
  To: peter.maydell; +Cc: berrange, qemu-devel, Vladimir Sementsov-Ogievskiy

Remove the 'patch prefix exists, appears to be a -p0 patch' warning
entirely as it is fundamentally flawed and can only produce false
positives.

Sometimes I create test files with names 'a' and 'b', and then get
surprised seeing this warning. It was not easy to understand where it
comes from.

How it works:
1. It extracts prefixes (a/, b/) from standard diff output
2. Checks if files/directories with these names exist in the project
   root
3. Warns if they exist, claiming it's a '-p0 patch' issue

This logic is wrong because:
- Standard diff/patch tools always use a/ and b/ prefixes by default
- The existence of files named 'a' or 'b' in the working directory is
  completely unrelated to patch format
- The working directory state may not correspond to the patch content
  (different commits, branches, etc.)
- In QEMU project, there are no single-letter files/directories in root,
  so this check can only generate false positives

The correct way to detect -p0 patches would be to analyze the path
format within the patch itself (e.g., absolute paths or paths without
prefixes), not check filesystem state.

So, let's finally drop it.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
 scripts/checkpatch.pl | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index d3d75f3f13..d0f4537f25 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1741,13 +1741,7 @@ sub process {
 			}
 		} elsif ($line =~ /^\+\+\+\s+(\S+)/) {
 			$realfile = $1;
-			$realfile =~ s@^([^/]*)/@@ if (!$file);
-
-			$p1_prefix = $1;
-			if (!$file && $tree && $p1_prefix ne '' &&
-			    -e "$root/$p1_prefix") {
-				WARN("patch prefix '$p1_prefix' exists, appears to be a -p0 patch\n");
-			}
+			$realfile =~ s@^[^/]*/@@  if (!$file);
 
 			if (defined $fileinfo && !$fileinfo->{isgit}) {
 				$fileinfo->{lineend} = $oldhere;
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] scripts/checkpatch.pl: remove bogus patch prefix warning
  2025-10-30 20:13 [PATCH] scripts/checkpatch.pl: remove bogus patch prefix warning Vladimir Sementsov-Ogievskiy
@ 2025-10-31 11:08 ` Daniel P. Berrangé
  2025-10-31 11:59 ` Paolo Bonzini
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel P. Berrangé @ 2025-10-31 11:08 UTC (permalink / raw)
  To: Vladimir Sementsov-Ogievskiy; +Cc: peter.maydell, qemu-devel

On Thu, Oct 30, 2025 at 11:13:19PM +0300, Vladimir Sementsov-Ogievskiy wrote:
> Remove the 'patch prefix exists, appears to be a -p0 patch' warning
> entirely as it is fundamentally flawed and can only produce false
> positives.
> 
> Sometimes I create test files with names 'a' and 'b', and then get
> surprised seeing this warning. It was not easy to understand where it
> comes from.
> 
> How it works:
> 1. It extracts prefixes (a/, b/) from standard diff output
> 2. Checks if files/directories with these names exist in the project
>    root
> 3. Warns if they exist, claiming it's a '-p0 patch' issue
> 
> This logic is wrong because:
> - Standard diff/patch tools always use a/ and b/ prefixes by default
> - The existence of files named 'a' or 'b' in the working directory is
>   completely unrelated to patch format
> - The working directory state may not correspond to the patch content
>   (different commits, branches, etc.)
> - In QEMU project, there are no single-letter files/directories in root,
>   so this check can only generate false positives
> 
> The correct way to detect -p0 patches would be to analyze the path
> format within the patch itself (e.g., absolute paths or paths without
> prefixes), not check filesystem state.
> 
> So, let's finally drop it.
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> ---
>  scripts/checkpatch.pl | 8 +-------
>  1 file changed, 1 insertion(+), 7 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] scripts/checkpatch.pl: remove bogus patch prefix warning
  2025-10-30 20:13 [PATCH] scripts/checkpatch.pl: remove bogus patch prefix warning Vladimir Sementsov-Ogievskiy
  2025-10-31 11:08 ` Daniel P. Berrangé
@ 2025-10-31 11:59 ` Paolo Bonzini
  1 sibling, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2025-10-31 11:59 UTC (permalink / raw)
  To: Vladimir Sementsov-Ogievskiy; +Cc: peter.maydell, berrange, qemu-devel

Queued, thanks.

Paolo



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-10-31 12:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-30 20:13 [PATCH] scripts/checkpatch.pl: remove bogus patch prefix warning Vladimir Sementsov-Ogievskiy
2025-10-31 11:08 ` Daniel P. Berrangé
2025-10-31 11:59 ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).