linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* diffs in changelogs
@ 2015-06-11 20:40 Andrew Morton
  2015-06-12  3:12 ` Joe Perches
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2015-06-11 20:40 UTC (permalink / raw)
  To: Joe Perches; +Cc: linux-kernel


People often put diff snippets in changelogs.  This causes problems
when one tries to apply a file containing both the changelog and the
diff because patch(1) tries to apply the diff which it found in the
changelog.

eg, something like

	git show d24a6e1087030b6da | patch -p1

will go haywire.

So can we please have a checkpatch test warning people away from doing
this?


patch(1) seems to be really promiscuous in its detection of a patch.  I
haven't had much success searching for "^--- " and similar.  What works
best for me is searching for "^[whitespace]@@ -".

Thanks.

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

* Re: diffs in changelogs
  2015-06-11 20:40 diffs in changelogs Andrew Morton
@ 2015-06-12  3:12 ` Joe Perches
  2015-06-12  3:21   ` Andrew Morton
  0 siblings, 1 reply; 5+ messages in thread
From: Joe Perches @ 2015-06-12  3:12 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, Kent Overstreet

On Thu, 2015-06-11 at 13:40 -0700, Andrew Morton wrote:
> People often put diff snippets in changelogs.  This causes problems
> when one tries to apply a file containing both the changelog and the
> diff because patch(1) tries to apply the diff which it found in the
> changelog.
That 
> eg, something like
> 
> 	git show d24a6e1087030b6da | patch -p1
> 
> will go haywire.
> 
> So can we please have a checkpatch test warning people away from doing
> this?
> 
> 
> patch(1) seems to be really promiscuous in its detection of a patch.  I
> haven't had much success searching for "^--- " and similar.  What works
> best for me is searching for "^[whitespace]@@ -".

I don't think that's a good test.
Coccinelle uses @@

And how did that commit actually get applied?

I tried applying it to a new branch checked out at
ce2b3f595e1c56639085645e0130426e443008c0, it fails.

Anyway, maybe:
---
 scripts/checkpatch.pl | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 69c4716..2d87e37 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2399,6 +2399,18 @@ sub process {
 			$in_commit_log = 1;
 		}
 
+# Check if the commit log has a diff which confuse patch
+
+		print("icl: <$in_commit_log> line: <$line>\n");
+		if ($in_commit_log &&
+		    (($line =~ m@^\s+diff\b.*a/[\w/]+@ &&
+		      $line =~ m@^\s+diff\b.*a/([\w/]+)\s+b/$1\b@) ||
+		     $line =~ m@^\s*(?:\-\-\-\s+a/|\+\+\+\s+b/)@ ||
+		     $line =~ m/^\s*\@\@ \-\d+,\d+ \+\d+,\d+ \@\@/)) {
+			ERROR("DIFF_IN_COMMIT_MSG",
+			      "It seems a diff exists in the commit message. This can confuse patch\n" . $herecurr);
+		}
+
 # Check if there is UTF-8 in a commit log when a mail header has explicitly
 # declined it, i.e defined some charset where it is missing.
 		if ($in_header_lines &&



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

* Re: diffs in changelogs
  2015-06-12  3:12 ` Joe Perches
@ 2015-06-12  3:21   ` Andrew Morton
  2015-06-12  3:54     ` Joe Perches
  2015-06-12 17:51     ` [PATCH] checkpatch: Emit an error when there's a diff in a changelog Joe Perches
  0 siblings, 2 replies; 5+ messages in thread
From: Andrew Morton @ 2015-06-12  3:21 UTC (permalink / raw)
  To: Joe Perches; +Cc: linux-kernel, Kent Overstreet

On Thu, 11 Jun 2015 20:12:59 -0700 Joe Perches <joe@perches.com> wrote:

> On Thu, 2015-06-11 at 13:40 -0700, Andrew Morton wrote:
> > People often put diff snippets in changelogs.  This causes problems
> > when one tries to apply a file containing both the changelog and the
> > diff because patch(1) tries to apply the diff which it found in the
> > changelog.
> That 
> > eg, something like
> > 
> > 	git show d24a6e1087030b6da | patch -p1
> > 
> > will go haywire.
> > 
> > So can we please have a checkpatch test warning people away from doing
> > this?
> > 
> > 
> > patch(1) seems to be really promiscuous in its detection of a patch.  I
> > haven't had much success searching for "^--- " and similar.  What works
> > best for me is searching for "^[whitespace]@@ -".
> 
> I don't think that's a good test.
> Coccinelle uses @@
> 
> And how did that commit actually get applied?

Good question.  Maybe `git apply' is smarter about this than patch(1)?

> I tried applying it to a new branch checked out at
> ce2b3f595e1c56639085645e0130426e443008c0, it fails.

There are tons of them:

z:/usr/src/git26> git log | grep "^[    ]*@@ -"  | wc -l
120

> Anyway, maybe:

Looks good, thanks.  -ENOCHANGELOG.  Please send it for real when convenient.



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

* Re: diffs in changelogs
  2015-06-12  3:21   ` Andrew Morton
@ 2015-06-12  3:54     ` Joe Perches
  2015-06-12 17:51     ` [PATCH] checkpatch: Emit an error when there's a diff in a changelog Joe Perches
  1 sibling, 0 replies; 5+ messages in thread
From: Joe Perches @ 2015-06-12  3:54 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, Kent Overstreet

On Thu, 2015-06-11 at 20:21 -0700, Andrew Morton wrote:
> On Thu, 11 Jun 2015 20:12:59 -0700 Joe Perches <joe@perches.com> wrote:
> 
> > On Thu, 2015-06-11 at 13:40 -0700, Andrew Morton wrote:
> > > People often put diff snippets in changelogs.  This causes problems
> > > when one tries to apply a file containing both the changelog and the
> > > diff because patch(1) tries to apply the diff which it found in the
> > > changelog.
> > That 
> > > eg, something like
> > > 
> > > 	git show d24a6e1087030b6da | patch -p1
> > > 
> > > will go haywire.
> > > 
> > > So can we please have a checkpatch test warning people away from doing
> > > this?
> > > 
> > > 
> > > patch(1) seems to be really promiscuous in its detection of a patch.  I
> > > haven't had much success searching for "^--- " and similar.  What works
> > > best for me is searching for "^[whitespace]@@ -".
> > 
> > I don't think that's a good test.
> > Coccinelle uses @@
> > 
> > And how did that commit actually get applied?
> 
> Good question.  Maybe `git apply' is smarter about this than patch(1)?

Dunno.  git am failed.
My guess is it was applied normally and then
git commit --amend added the other diff content

> > I tried applying it to a new branch checked out at
> > ce2b3f595e1c56639085645e0130426e443008c0, it fails.
> 
> There are tons of them:
> 
> z:/usr/src/git26> git log | grep "^[    ]*@@ -"  | wc -l
> 120
> 
> > Anyway, maybe:
> 
> Looks good, thanks.  -ENOCHANGELOG.  Please send it for real when convenient.

RFCPATCH





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

* [PATCH] checkpatch: Emit an error when there's a diff in a changelog
  2015-06-12  3:21   ` Andrew Morton
  2015-06-12  3:54     ` Joe Perches
@ 2015-06-12 17:51     ` Joe Perches
  1 sibling, 0 replies; 5+ messages in thread
From: Joe Perches @ 2015-06-12 17:51 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, Andy Whitcroft

People often put diff snippets in changelogs.  This causes problems
when one tries to apply a file containing both the changelog and the
diff because patch(1) tries to apply the diff which it found in the
changelog.

Warn once when what seems to be a diff snippet in the changelog exists.

Suggested-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Joe Perches <joe@perches.com>
---
 scripts/checkpatch.pl | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 69c4716..86e4fb1 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1954,6 +1954,7 @@ sub process {
 	my $in_header_lines = $file ? 0 : 1;
 	my $in_commit_log = 0;		#Scanning lines before patch
 	my $commit_log_long_line = 0;
+	my $commit_log_has_diff = 0;
 	my $reported_maintainer_file = 0;
 	my $non_utf8_charset = 0;
 
@@ -2087,7 +2088,8 @@ sub process {
 		my $rawline = $rawlines[$linenr - 1];
 
 #extract the line range in the file after the patch is applied
-		if ($line=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
+		if (!$in_commit_log &&
+		    $line =~ /^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
 			$is_patch = 1;
 			$first_line = $linenr + 1;
 			$realline=$1-1;
@@ -2181,6 +2183,17 @@ sub process {
 
 		$cnt_lines++ if ($realcnt != 0);
 
+# Check if the commit log has what seems like a diff which can confuse patch
+		if ($in_commit_log && !$commit_log_has_diff &&
+		    (($line =~ m@^\s+diff\b.*a/[\w/]+@ &&
+		      $line =~ m@^\s+diff\b.*a/([\w/]+)\s+b/$1\b@) ||
+		     $line =~ m@^\s*(?:\-\-\-\s+a/|\+\+\+\s+b/)@ ||
+		     $line =~ m/^\s*\@\@ \-\d+,\d+ \+\d+,\d+ \@\@/)) {
+			ERROR("DIFF_IN_COMMIT_MSG",
+			      "Avoid using diff content in the commit message - patch(1) might not work\n" . $herecurr);
+			$commit_log_has_diff = 1;
+		}
+
 # Check for incorrect file permissions
 		if ($line =~ /^new (file )?mode.*[7531]\d{0,2}$/) {
 			my $permhere = $here . "FILE: $realfile\n";



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

end of thread, other threads:[~2015-06-12 17:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-11 20:40 diffs in changelogs Andrew Morton
2015-06-12  3:12 ` Joe Perches
2015-06-12  3:21   ` Andrew Morton
2015-06-12  3:54     ` Joe Perches
2015-06-12 17:51     ` [PATCH] checkpatch: Emit an error when there's a diff in a changelog Joe Perches

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).