Skip to contentSkip to conversation

patchtest: warn if Upstream-Status is after patch scissors

PATCH Superseded Aditya GS 2 participants 3 messages Jun 9 – Jun 11

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Aditya GS

author
#0 lore raw

PATCH 1/1 patchtest: warn if Upstream-Status is after patch scissors

Detect cases where Upstream-Status is placed after the patch scissors ("---") and emit a warning instead of failing.

Such placement may be intentional in some workflows to avoid including the tag in upstream commits.

---
 meta/lib/patchtest/tests/test_patch.py | 187 ++++++++++++-------------
 1 file changed, 89 insertions(+), 98 deletions(-)
meta/lib/patchtest/tests/test_patch.py +89 -98
index f427b7a8b0..79aa8f100c 100644
@@ -40,116 +40,107 @@ class TestPatch(base.Base):
             self.skip('No new CVE patches introduced')
 
     def test_upstream_status_presence_format(self):
-        if not TestPatch.newpatches:
-            self.skip("There are no new software patches, no reason to test Upstream-Status presence/format")
+    if not TestPatch.newpatches:
+        self.skip("There are no new software patches, no reason to test Upstream-Status presence/format")
 
-        for newpatch in TestPatch.newpatches:
-            payload = newpatch.__str__()
-            lines = payload.splitlines()
+    for newpatch in TestPatch.newpatches:
+        payload = newpatch.__str__()
+        lines = payload.splitlines()
 
-            scissors_index = None
-            for idx, line in enumerate(lines):
-                if line.lstrip("+") == "---":
-                    scissors_index = idx
-                    break
+        scissors_index = None
+        for idx, line in enumerate(lines):
+            if line.lstrip("+") == "---":
+                scissors_index = idx
+                break
 
-            header_has_upstream = False
-            body_has_upstream = False
+        header_has_upstream = False
+        body_has_upstream = False
 
-            for idx, line in enumerate(lines):
-                if not patchtest_patterns.upstream_status_regex.search_string(line):
-                    continue
+        for idx, line in enumerate(lines):
+            if not patchtest_patterns.upstream_status_regex.search_string(line):
+                continue
 
-                if scissors_index is not None and idx > scissors_index:
-                    body_has_upstream = True
-                else:
-                    header_has_upstream = True
-
-            if not header_has_upstream:
-    if body_has_upstream:
-        self.skip(
-            'Upstream-Status is present only after the patch scissors. '
-            'It may be ignored by git and lost during patch refresh. '
-            'Consider placing it before the scissors line.',
-            data=[
-                ("Standard format", self.standard_format),
-                ("Valid status", self.valid_status),
-            ],
-        )
-                else:
+            if scissors_index is not None and idx > scissors_index:
+                body_has_upstream = True
+            else:
+                header_has_upstream = True
+
+        if not header_has_upstream:
+            if body_has_upstream:
+                print(
+                    'WARNING: Upstream-Status is present only after the patch scissors. '
+                    'It may be ignored by git and lost during patch refresh. '
+                    'Consider placing it before the scissors line.'
+                )
+            else:
+                self.fail(
+                    "Added patch file is missing Upstream-Status: <Valid status> in the commit message",
+                    data=[
+                        ("Standard format", self.standard_format),
+                        ("Valid status", self.valid_status),
+                    ],
+                )
+
+        for idx, line in enumerate(lines):
+            if patchtest_patterns.patchmetadata_regex.match(line):
+                continue
+
+            if not patchtest_patterns.upstream_status_regex.search_string(line):
+                continue
+
+            if scissors_index is not None and idx > scissors_index:
+                print(
+                    'WARNING: Upstream-Status found after patch scissors. '
+                    'It may be ignored by git and lost during patch refresh. '
+                    'Consider placing it before the scissors line.'
+                )
+                continue
+
+            if patchtest_patterns.inappropriate.searchString(line):
+                try:
+                    patchtest_patterns.upstream_status_inappropriate_info.parseString(
+                        line.lstrip("+")
+                    )
+                except pyparsing.ParseException as pe:
+                    self.fail(
+                        "Upstream-Status is Inappropriate, but no reason was provided",
+                        data=[
+                            ("Current", pe.pstr),
+                            (
+                                "Standard format",
+                                "Upstream-Status: Inappropriate [reason]",
+                            ),
+                        ],
+                    )
+            elif patchtest_patterns.submitted.searchString(line):
+                try:
+                    patchtest_patterns.upstream_status_submitted_info.parseString(
+                        line.lstrip("+")
+                    )
+                except pyparsing.ParseException as pe:
+                    self.fail(
+                        "Upstream-Status is Submitted, but it is not mentioned where",
+                        data=[
+                            ("Current", pe.pstr),
+                            (
+                                "Standard format",
+                                "Upstream-Status: Submitted [where]",
+                            ),
+                        ],
+                    )
+            else:
+                try:
+                    patchtest_patterns.upstream_status.parseString(line.lstrip("+"))
+                except pyparsing.ParseException as pe:
                     self.fail(
-                        "Added patch file is missing Upstream-Status: <Valid status> in the commit message",
+                        "Upstream-Status is in incorrect format",
                         data=[
+                            ("Current", pe.pstr),
                             ("Standard format", self.standard_format),
                             ("Valid status", self.valid_status),
                         ],
                     )
 
-            for idx, line in enumerate(lines):
-                if patchtest_patterns.patchmetadata_regex.match(line):
-                    continue
-
-                if not patchtest_patterns.upstream_status_regex.search_string(line):
-                    continue
-
-                if scissors_index is not None and idx > scissors_index:
-    self.skip(
-        'Upstream-Status found after patch scissors. '
-        'It may be ignored by git and lost during patch refresh. '
-        'Consider placing it before the scissors line.',
-        data=[
-            ("Current", line.lstrip("+")),
-            ("Standard format", self.standard_format),
-            ("Valid status", self.valid_status),
-        ],
-    )
-
-
-                if patchtest_patterns.inappropriate.searchString(line):
-                    try:
-                        patchtest_patterns.upstream_status_inappropriate_info.parseString(
-                            line.lstrip("+")
-                        )
-                    except pyparsing.ParseException as pe:
-                        self.fail(
-                            "Upstream-Status is Inappropriate, but no reason was provided",
-                            data=[
-                                ("Current", pe.pstr),
-                                (
-                                    "Standard format",
-                                    "Upstream-Status: Inappropriate [reason]",
-                                ),
-                            ],
-                        )
-                elif patchtest_patterns.submitted.searchString(line):
-                    try:
-                        patchtest_patterns.upstream_status_submitted_info.parseString(
-                            line.lstrip("+")
-                        )
-                    except pyparsing.ParseException as pe:
-                        self.fail(
-                            "Upstream-Status is Submitted, but it is not mentioned where",
-                            data=[
-                                ("Current", pe.pstr),
-                                (
-                                    "Standard format",
-                                    "Upstream-Status: Submitted [where]",
-                                ),
-                            ],
-                        )
-                else:
-                    try:
-                        patchtest_patterns.upstream_status.parseString(line.lstrip("+"))
-                    except pyparsing.ParseException as pe:
-                        self.fail(
-                            "Upstream-Status is in incorrect format",
-                            data=[
-                                ("Current", pe.pstr),
-                                ("Standard format", self.standard_format),
-                                ("Valid status", self.valid_status),
-                            ],
-                        )
-
     def test_signed_off_by_presence(self):
         if not TestPatch.newpatches:
             self.skip("There are no new software patches, no reason to test %s presence" % PatchSignedOffBy.mark)
Signature · 1 line
2.34.1
#1 lore raw
Quoted 16 lines · Aditya GS via lists.openembedded.org

Detect cases where Upstream-Status is placed after the patch scissors ("---") and emit a warning instead of failing.

Such placement may be intentional in some workflows to avoid including the tag in upstream commits.

---
 meta/lib/patchtest/tests/test_patch.py | 187 ++++++++++++-------------
 1 file changed, 89 insertions(+), 98 deletions(-)
meta/lib/patchtest/tests/test_patch.py +0 -0
index f427b7a8b0..79aa8f100c 100644

meta/lib/patchtest/tests/test_patch.py class TestPatch(base.Base): · line 44

Quoted 7 lines
meta/lib/patchtest/tests/test_patch.py +2 -2
@@ -40,116 +40,107 @@ class TestPatch(base.Base):
             self.skip('No new CVE patches introduced')
 
     def test_upstream_status_presence_format(self):
-        if not TestPatch.newpatches:
-            self.skip("There are no new software patches, no reason to test Upstream-Status presence/format")
+    if not TestPatch.newpatches:
+        self.skip("There are no new software patches, no reason to test Upstream-Status presence/format")

Hi Aditya,

Thanks for your patch.

Maybe I'm missing something, but the whole re-indentation of the file looks wrong. Particularly here, the "if" block is at the same level as the function definition. Can you confirm this is intended?

Thanks,
Mathieu

Signature · 3 lines
Mathieu Dubois-Briand, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
author
#2 lore raw

Hi Mathieu,

Thanks for reviewing the patch.

This change is for Bug 15940 ("Detect tags like Upstream-Status after the scissors in patches").

You are right to point this out. On re-checking, the current patch includes unintended indentation changes, and the if block appearing at the same level as the function definition is not intentional.

The goal of the patch is only to introduce the warning logic, and the indentation changes are not required for that.

I'll prepare and resend a cleaned-up version with proper indentation and a minimal diff so the functional change can be reviewed clearly.

Thanks for catching this.

Best regards,
Aditya

Quoted 47 lines · Mathieu Dubois-Briand
Quoted 6 lines · Aditya GS via lists.openembedded.org

Detect cases where Upstream-Status is placed after the patch scissors ("---") and emit a warning instead of failing.

Such placement may be intentional in some workflows to avoid including the tag in upstream commits.

Review

Quoted 6 lines
---
 meta/lib/patchtest/tests/test_patch.py | 187 ++++++++++++-------------
 1 file changed, 89 insertions(+), 98 deletions(-)
(quoted diff) +0 -0

b/meta/lib/patchtest/tests/test_patch.py

meta/lib/patchtest/tests/test_patch.py class TestPatch(base.Base): · line 44

Quoted 9 lines

index f427b7a8b0..79aa8f100c 100644

meta/lib/patchtest/tests/test_patch.py +0 -2
@@ -40,116 +40,107 @@ class TestPatch(base.Base):
             self.skip('No new CVE patches introduced')
 
     def test_upstream_status_presence_format(self):
-        if not TestPatch.newpatches:
-            self.skip("There are no new software patches, no reason to

test Upstream-Status presence/format")

meta/lib/patchtest/tests/test_patch.py class TestPatch(base.Base): · line 44

Quoted 2 lines
meta/lib/patchtest/tests/test_patch.py +2 -0
+    if not TestPatch.newpatches:
+        self.skip("There are no new software patches, no reason to test

Upstream-Status presence/format")

Hi Aditya,

Thanks for your patch.

Maybe I'm missing something, but the whole re-indentation of the file looks wrong. Particularly here, the "if" block is at the same level as the function definition. Can you confirm this is intended?

Thanks,
Mathieu

--
Mathieu Dubois-Briand, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com