checkpatch: Properly warn if Change-Id comes after first Signed-off-by line
RFC PATCH 1/1 checkpatch: Properly warn if Change-Id comes after first Signed-off-by line
Quite often, the Change-Id may be between Signed-off-by: lines or at the end of them. Unfortunately checkpatch won't catch these cases as it disables in_commit_log when it catches the first Signed-off-by line.
This has bitten me many many times.
I suspect this patch will break other use cases, so it probably shouldn't be merged, but I wanted to share it just to help illustrate the problem.
--- scripts/checkpatch.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +2 -1
@@ -2609,7 +2609,8 @@ sub process { # Check the patch for a signoff: if ($line =~ /^\s*signed-off-by:/i) { $signoff++; - $in_commit_log = 0; + #Disabling in_commit_log here breaks Change-Id checking in some cases + #$in_commit_log = 0; if ($author ne '') { my $l = $line; $l =~ s/"//g;
Signature · 1 line
2.17.1
Joe Perches
maintainerQuoted 6 lines · John Stultz
Quite often, the Change-Id may be between Signed-off-by: lines or at the end of them. Unfortunately checkpatch won't catch these cases as it disables
in_commit_logwhen it catches the first Signed-off-by line.This has bitten me many many times.
Hmm. When is change-id used in your workflow?
Quoted 7 lines
I suspect this patch will break other use cases, so it probably shouldn't be merged, but I wanted to share it just to help illustrate the problem.
Cc Andy Whitcroft <[email protected]>Cc Joe Perches <[email protected]>Signed-off-by John Stultz <[email protected]>
Yes, I expect this will break things.
And it's probably better to not add a Signed-off-by: when you intend this not to be merged.
Quoted 18 lines
--- scripts/checkpatch.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)scripts/checkpatch.pl +2
-1@@ -2609,7 +2609,8 @@ sub process { # Check the patch for a signoff: if ($line =~ /^\s*signed-off-by:/i) { $signoff++; - $in_commit_log = 0; + #Disabling in_commit_log here breaks Change-Id checking in some cases + #$in_commit_log = 0; if ($author ne '') { my $l = $line; $l =~ s/"//g;
Quoted 10 lines · Joe Perches
Quoted 6 lines · John Stultz
Quite often, the Change-Id may be between Signed-off-by: lines or at the end of them. Unfortunately checkpatch won't catch these cases as it disables
in_commit_logwhen it catches the first Signed-off-by line.This has bitten me many many times.
Hmm. When is change-id used in your workflow?
Since I have a few kernel repos that I use for both upstream work and work targeting AOSP trees, I usually have the gerrit commit hook enabled in my tree (its easier to strip with sed then it is to re-add after submitting to gerrit), and at least the commit-msg hook I have will usually append a Change-Id: line at the end of the commit message, usually after the signed-off-by line.
Even in the example in the README from:
https://android.googlesource.com/kernel/common/+/android-mainline
shows how one might have the change-id and other AOSP tags added after the existing sob-chain. So it doesn't seem to be that rare.
Some other examples from the android-mainline tree:
https://android.googlesource.com/kernel/common/+/5fba1b18cfc72e264e5f3ce49020ed322aa6ac9f
https://android.googlesource.com/kernel/common/+/6ea0a439a15ba42b6c5f81618e53d5c61f89e4ac
https://android.googlesource.com/kernel/common/+/99f4553ab4a6b008b37e878f7046a2202cdb2ec4
Quoted 9 lines
Quoted 7 lines
I suspect this patch will break other use cases, so it probably shouldn't be merged, but I wanted to share it just to help illustrate the problem.
Cc Andy Whitcroft <[email protected]>Cc Joe Perches <[email protected]>Signed-off-by John Stultz <[email protected]>Yes, I expect this will break things.
Suggestions for a better approach? I can't say I'm very familiar with checkpatch's code.
Quoted 2 lines
And it's probably better to not add a Signed-off-by: when you intend this not to be merged.
So, I try to add Sign-off-by to all the patches I send as it certifies that I wrote it or otherwise have the right to pass it on as an open-source patch - not as "ok to merge" criteria.
More vendor code then I'd like is usually not intended to be merged upstream, but it's still important that folks sign off their patches. :)
thanks
-john
Joe Perches
maintainerQuoted 9 lines · John Stultz
Quoted 8 lines · Joe Perches
Quoted 6 lines · John Stultz
Quite often, the Change-Id may be between Signed-off-by: lines or at the end of them. Unfortunately checkpatch won't catch these cases as it disables
in_commit_logwhen it catches the first Signed-off-by line.This has bitten me many many times.
Quoted 8 lines
Quoted 1 line
Hmm. When is change-id used in your workflow?
Since I have a few kernel repos that I use for both upstream work and work targeting AOSP trees, I usually have the gerrit commit hook enabled in my tree (its easier to strip with sed then it is to re-add after submitting to gerrit), and at least the commit-msg hook I have will usually append a Change-Id: line at the end of the commit message, usually after the signed-off-by line.
Perhaps this is better:
--- scripts/checkpatch.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/checkpatch.pl +2 -2
@@ -2721,9 +2721,9 @@ sub process { } # Check for unwanted Gerrit info - if ($in_commit_log && $line =~ /^\s*change-id:/i) { + if ($realfile eq '' && $line =~ /^\s*change-id:/i) { ERROR("GERRIT_CHANGE_ID", - "Remove Gerrit Change-Id's before submitting upstream.\n" . $herecurr); + "Remove Gerrit Change-Id's before submitting upstream\n" . $herecurr); } # Check if the commit log is in a possible stack dump
John Stultz
Tested-byQuoted 19 lines · Joe Perches
Quoted 6 lines
Since I have a few kernel repos that I use for both upstream work and work targeting AOSP trees, I usually have the gerrit commit hook enabled in my tree (its easier to strip with sed then it is to re-add after submitting to gerrit), and at least the commit-msg hook I have will usually append a Change-Id: line at the end of the commit message, usually after the signed-off-by line.
Perhaps this is better:
--- scripts/checkpatch.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)scripts/checkpatch.pl +0
-0@@ -2721,9 +2721,9 @@ sub process { }
scripts/checkpatch.pl sub process { · line 2729
Quoted 10 lines
scripts/checkpatch.pl +2
-2# Check for unwanted Gerrit info - if ($in_commit_log && $line =~ /^\s*change-id:/i) { + if ($realfile eq '' && $line =~ /^\s*change-id:/i) { ERROR("GERRIT_CHANGE_ID", - "Remove Gerrit Change-Id's before submitting upstream.\n" . $herecurr); + "Remove Gerrit Change-Id's before submitting upstream\n" . $herecurr); } # Check if the commit log is in a possible stack dump
Yep. This works well for me, catching Change-Id lines that are missed by the current code.
Thanks so much!
-john
Joe Perches
maintainerQuoted 8 lines · John Stultz
Quoted 7 lines · Joe Perches
Quoted 6 lines
Since I have a few kernel repos that I use for both upstream work and work targeting AOSP trees, I usually have the gerrit commit hook enabled in my tree (its easier to strip with sed then it is to re-add after submitting to gerrit), and at least the commit-msg hook I have will usually append a Change-Id: line at the end of the commit message, usually after the signed-off-by line.
Quoted 6 lines
scripts/checkpatch.pl
Quoted 6 lines
Perhaps this is better:
--- scripts/checkpatch.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)scripts/checkpatch.pl +0
-0
[]
Quoted 11 lines
Quoted 11 lines
scripts/checkpatch.pl +2
-2@@ -2721,9 +2721,9 @@ sub process { } # Check for unwanted Gerrit info - if ($in_commit_log && $line =~ /^\s*change-id:/i) { + if ($realfile eq '' && $line =~ /^\s*change-id:/i) { ERROR("GERRIT_CHANGE_ID", - "Remove Gerrit Change-Id's before submitting upstream.\n" . $herecurr); + "Remove Gerrit Change-Id's before submitting upstream\n" . $herecurr); }
Quoted 7 lines
scripts/checkpatch.pl sub process { · line 2729
Quoted 2 lines
scripts/checkpatch.pl +0
-0# Check if the commit log is in a possible stack dumpYep. This works well for me, catching Change-Id lines that are missed by the current code.
Tested-by John Stultz <[email protected]>
A negative approach to this is if the change-id is after the "---" separator line but before any file diff, then the "Remove Gerrit Change-Id" message will still be emitted.
Dunno if that's an issue.
Joe Perches
maintainerQuoted 7 lines · John Stultz
Quoted 6 lines · Joe Perches
Quoted 6 lines
Since I have a few kernel repos that I use for both upstream work and work targeting AOSP trees, I usually have the gerrit commit hook enabled in my tree (its easier to strip with sed then it is to re-add after submitting to gerrit), and at least the commit-msg hook I have will usually append a Change-Id: line at the end of the commit message, usually after the signed-off-by line.
I think this better still:
--- scripts/checkpatch.pl | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
scripts/checkpatch.pl +10 -3
@@ -2343,6 +2343,7 @@ sub process { my $is_binding_patch = -1; my $in_header_lines = $file ? 0 : 1; my $in_commit_log = 0; #Scanning lines before patch + my $has_patch_separator = 0; #Found a --- line my $has_commit_log = 0; #Encountered lines before patch my $commit_log_lines = 0; #Number of commit log lines my $commit_log_possible_stack_dump = 0;
@@ -2668,6 +2669,12 @@ sub process { } } +# Check for patch separator + if ($line =~ /^---$/) { + $has_patch_separator = 1; + $in_commit_log = 0; + } + # Check if MAINTAINERS is being updated. If so, there's probably no need to # emit the "does MAINTAINERS need updating?" message on file add/move/delete if ($line =~ /^\s*MAINTAINERS\s*\|/) {
@@ -2767,10 +2774,10 @@ sub process { "A patch subject line should describe the change not the tool that found it\n" . $herecurr); } -# Check for unwanted Gerrit info - if ($in_commit_log && $line =~ /^\s*change-id:/i) { +# Check for Gerrit Change-Ids not in any patch context + if ($realfile eq '' && !$has_patch_separator && $line =~ /^\s*change-id:/i) { ERROR("GERRIT_CHANGE_ID", - "Remove Gerrit Change-Id's before submitting upstream.\n" . $herecurr); + "Remove Gerrit Change-Id's before submitting upstream\n" . $herecurr); } # Check if the commit log is in a possible stack dump
John Stultz
Tested-byQuoted 44 lines · Joe Perches
Quoted 7 lines · John Stultz
Quoted 6 lines · Joe Perches
Quoted 6 lines
Since I have a few kernel repos that I use for both upstream work and work targeting AOSP trees, I usually have the gerrit commit hook enabled in my tree (its easier to strip with sed then it is to re-add after submitting to gerrit), and at least the commit-msg hook I have will usually append a Change-Id: line at the end of the commit message, usually after the signed-off-by line.
I think this better still:
--- scripts/checkpatch.pl | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)scripts/checkpatch.pl +7
-0@@ -2343,6 +2343,7 @@ sub process { my $is_binding_patch = -1; my $in_header_lines = $file ? 0 : 1; my $in_commit_log = 0; #Scanning lines before patch + my $has_patch_separator = 0; #Found a --- line my $has_commit_log = 0; #Encountered lines before patch my $commit_log_lines = 0; #Number of commit log lines my $commit_log_possible_stack_dump = 0;@@ -2668,6 +2669,12 @@ sub process { } } +# Check for patch separator + if ($line =~ /^---$/) { + $has_patch_separator = 1; + $in_commit_log = 0; + } + # Check if MAINTAINERS is being updated. If so, there's probably no need to # emit the "does MAINTAINERS need updating?" message on file add/move/delete if ($line =~ /^\s*MAINTAINERS\s*\|/) {@@ -2767,10 +2774,10 @@ sub process { "A patch subject line should describe the change not the tool that found it\n" . $herecurr); }
scripts/checkpatch.pl sub process { · line 2783
Quoted 10 lines
scripts/checkpatch.pl +3
-3-# Check for unwanted Gerrit info - if ($in_commit_log && $line =~ /^\s*change-id:/i) { +# Check for Gerrit Change-Ids not in any patch context + if ($realfile eq '' && !$has_patch_separator && $line =~ /^\s*change-id:/i) { ERROR("GERRIT_CHANGE_ID", - "Remove Gerrit Change-Id's before submitting upstream.\n" . $herecurr); + "Remove Gerrit Change-Id's before submitting upstream\n" . $herecurr); } # Check if the commit log is in a possible stack dump
This one works well for me too.
Thanks so much!
-john
Joe Perches
maintainerPATCH 1/1 checkpatch: Improve Gerrit Change-Id: test
In reply to John StultzThe Gerrit Change-Id: entry is sometimes placed after a Signed-off-by:
line. When this occurs, the Gerrit warning is not currently emitted as the first Signed-off-by: signature sets a flag to stop looking.
Change the test to add a test for the --- patch separator and emit the warning before any before the --- and also before any diff file name.
--- scripts/checkpatch.pl | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
scripts/checkpatch.pl +10 -3
@@ -2343,6 +2343,7 @@ sub process { my $is_binding_patch = -1; my $in_header_lines = $file ? 0 : 1; my $in_commit_log = 0; #Scanning lines before patch + my $has_patch_separator = 0; #Found a --- line my $has_commit_log = 0; #Encountered lines before patch my $commit_log_lines = 0; #Number of commit log lines my $commit_log_possible_stack_dump = 0;
@@ -2668,6 +2669,12 @@ sub process { } } +# Check for patch separator + if ($line =~ /^---$/) { + $has_patch_separator = 1; + $in_commit_log = 0; + } + # Check if MAINTAINERS is being updated. If so, there's probably no need to # emit the "does MAINTAINERS need updating?" message on file add/move/delete if ($line =~ /^\s*MAINTAINERS\s*\|/) {
@@ -2767,10 +2774,10 @@ sub process { "A patch subject line should describe the change not the tool that found it\n" . $herecurr); } -# Check for unwanted Gerrit info - if ($in_commit_log && $line =~ /^\s*change-id:/i) { +# Check for Gerrit Change-Ids not in any patch context + if ($realfile eq '' && !$has_patch_separator && $line =~ /^\s*change-id:/i) { ERROR("GERRIT_CHANGE_ID", - "Remove Gerrit Change-Id's before submitting upstream.\n" . $herecurr); + "Remove Gerrit Change-Id's before submitting upstream\n" . $herecurr); } # Check if the commit log is in a possible stack dump