Skip to contentSkip to conversation

tools: patman: Fixes to improve handling of various wrong usage

PATCH New Bin Meng 2 participants 14 messages Jun 27, 2016 – Jul 3, 2016

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

v2 cover tools: patman: Fixes to improve handling of various wrong usage

This fixes several issues when abnormal tags are given to patman. For example, when we forget to put an 'END' after 'Cover-letter', patman does not handle such cases very well. This adds several additional checking to let patman be a little more tolerant on handling such exceptional paths.

This series is available at u-boot-x86/patman-working for testing.

Changes in v2:
- New patch to use cover_match for 'Cover-letter'
- Update commit message to explain when such scenario is hit
- Add cover_match to the test logic
- Generate warning for missing 'END' case
- Update commit message to explain when such case is hit
- Reset in_section, skip_blank and section variables too
- Geneate warning when blank line is not found in 'Series-changes'
- New patch to handle missing 'END' in non-last commit of a series

Bin Meng (5):
tools: patman: Use cover_match for 'Cover-letter'
tools: patman: Handle tag sections without an 'END'
tools: patman: Generate cover letter correctly when 'END' is missing
tools: patman: Handle missing blank line for 'Series-changes'
tools: patman: Handle missing 'END' in non-last commit of a series

 tools/patman/patchstream.py | 38 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH v2 1/5 tools: patman: Use cover_match for 'Cover-letter'

Like other patman tags, use a new variable cover_match to indicate a match for 'Cover-letter'.

---

Changes in v2:
- New patch to use cover_match for 'Cover-letter'

 tools/patman/patchstream.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/patman/patchstream.py +2 -1
index 27d031e..2c4efc5 100644
@@ -150,6 +150,7 @@ class PatchStream:
         # Handle state transition and skipping blank lines
         series_tag_match = re_series_tag.match(line)
         commit_tag_match = re_commit_tag.match(line)
+        cover_match = re_cover.match(line)
         cover_cc_match = re_cover_cc.match(line)
         signoff_match = re_signoff.match(line)
         tag_match = None
@@ -203,7 +204,7 @@ class PatchStream:
             self.skip_blank = False
 
         # Detect the start of a cover letter section
-        elif re_cover.match(line):
+        elif cover_match:
             self.in_section = 'cover'
             self.skip_blank = False
 
Signature · 1 line
2.7.4
author
#4 lore raw

PATCH v2 2/5 tools: patman: Handle tag sections without an 'END'

In reply to Bin Meng

'Cover-letter', 'Series-notes' and 'Commit-notes' tags require an 'END' to be put at the end of its section. If we forget to put an 'END' in those sections, and these sections are followed by another patman tag, patman generates incorrect patches. This adds codes to handle such scenario.

---

Changes in v2:
- Update commit message to explain when such scenario is hit
- Add cover_match to the test logic
- Generate warning for missing 'END' case

 tools/patman/patchstream.py | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
tools/patman/patchstream.py +20 -0
index 2c4efc5..ce8ffb8 100644
@@ -169,6 +169,26 @@ class PatchStream:
         elif commit_match:
             self.state = STATE_MSG_HEADER
 
+        # If a tag is detected, but we are already in a section,
+        # this means 'END' is missing for that section, fix it up.
+        if series_tag_match or commit_tag_match or \
+           cover_match or cover_cc_match or signoff_match:
+            if self.in_section:
+                self.warn.append("Missing 'END' in section '%s'" % self.in_section)
+                if self.in_section == 'cover':
+                    self.series.cover = self.section
+                elif self.in_section == 'notes':
+                    if self.is_log:
+                        self.series.notes += self.section
+                elif self.in_section == 'commit-notes':
+                    if self.is_log:
+                        self.commit.notes += self.section
+                else:
+                    self.warn.append("Unknown section '%s'" % self.in_section)
+                self.in_section = None
+                self.skip_blank = True
+                self.section = []
+
         # If we are in a section, keep collecting lines until we see END
         if self.in_section:
             if line == 'END':
Signature · 1 line
2.7.4
author
#6 lore raw

PATCH v2 3/5 tools: patman: Generate cover letter correctly when 'END' is missing

In reply to Bin Meng

If 'END' is missing in a 'Cover-letter' section, and that section happens to show up at the very end of the commit message, and the commit is the last commit of the series, patman fails to generate cover letter for us. Handle this in CloseCommit of patchstream.

---

Changes in v2:
- Update commit message to explain when such case is hit
- Reset in_section, skip_blank and section variables too

 tools/patman/patchstream.py | 8 ++++++++
 1 file changed, 8 insertions(+)
tools/patman/patchstream.py +8 -0
index ce8ffb8..9ae977f 100644
@@ -112,6 +112,14 @@ class PatchStream:
         if self.commit and self.is_log:
             self.series.AddCommit(self.commit)
             self.commit = None
+        # If 'END' is missing in a 'Cover-letter' section, and that section
+        # happens to show up at the very end of the commit message, this is
+        # the chance for us to fix it up.
+        if self.in_section == 'cover' and self.is_log:
+            self.series.cover = self.section
+            self.in_section = None
+            self.skip_blank = True
+            self.section = []
 
     def ProcessLine(self, line):
         """Process a single line of a patch file or commit log
Signature · 1 line
2.7.4
author
#9 lore raw

PATCH v2 4/5 tools: patman: Handle missing blank line for 'Series-changes'

In reply to Bin Meng

'Series-changes' uses blank line to indicate its end. If that is missing, series internal state variable 'in_change' may be wrong. Correct its state.

---

Changes in v2:
- Geneate warning when blank line is not found in 'Series-changes'

 tools/patman/patchstream.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
tools/patman/patchstream.py +8 -2
index 9ae977f..0612612 100644
@@ -177,10 +177,11 @@ class PatchStream:
         elif commit_match:
             self.state = STATE_MSG_HEADER
 
-        # If a tag is detected, but we are already in a section,
-        # this means 'END' is missing for that section, fix it up.
+        # If a tag is detected
         if series_tag_match or commit_tag_match or \
            cover_match or cover_cc_match or signoff_match:
+            # but we are already in a section, this means 'END' is missing
+            # for that section, fix it up.
             if self.in_section:
                 self.warn.append("Missing 'END' in section '%s'" % self.in_section)
                 if self.in_section == 'cover':
@@ -196,6 +197,11 @@ class PatchStream:
                 self.in_section = None
                 self.skip_blank = True
                 self.section = []
+            # but we are already in a change list, that means a blank line
+            # is missing, fix it up.
+            if self.in_change:
+                self.warn.append("Missing 'blank line' in section 'Series-changes'")
+                self.in_change = 0
 
         # If we are in a section, keep collecting lines until we see END
         if self.in_section:
Signature · 1 line
2.7.4
author
#11 lore raw

PATCH v2 5/5 tools: patman: Handle missing 'END' in non-last commit of a series

In reply to Bin Meng

The following python error:

Traceback (most recent call last):
File "./tools/patman/patman", line 144, in <module>
series = patchstream.FixPatches(series, args)
File "./tools/patman/patchstream.py", line 477, in FixPatches
commit = series.commits[count]
IndexError: list index out of range

is seen when:

- 'END' is missing in those tags
- those tags are put in the last part in a commit message
- the commit is not the last commit of the series

Add testing logic to see if a new commit starts.

---

Changes in v2:
- New patch to handle missing 'END' in non-last commit of a series

 tools/patman/patchstream.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
tools/patman/patchstream.py +3 -2
index 0612612..69d5cfb 100644
@@ -177,9 +177,10 @@ class PatchStream:
         elif commit_match:
             self.state = STATE_MSG_HEADER
 
-        # If a tag is detected
+        # If a tag is detected, or a new commit starts
         if series_tag_match or commit_tag_match or \
-           cover_match or cover_cc_match or signoff_match:
+           cover_match or cover_cc_match or signoff_match or \
+           self.state == STATE_MSG_HEADER:
             # but we are already in a section, this means 'END' is missing
             # for that section, fix it up.
             if self.in_section:
Signature · 1 line
2.7.4
#7 lore raw

PATCH v2 3/5 tools: patman: Generate cover letter correctly when 'END' is missing

In reply to Bin Meng
Quoted 5 lines · Bin Meng

If 'END' is missing in a 'Cover-letter' section, and that section happens to show up at the very end of the commit message, and the commit is the last commit of the series, patman fails to generate cover letter for us. Handle this in CloseCommit of patchstream.

Quoted 7 lines

---

Changes in v2:
- Update commit message to explain when such case is hit
- Reset in_section, skip_blank and section variables too

#12 lore raw

PATCH v2 5/5 tools: patman: Handle missing 'END' in non-last commit of a series

In reply to Bin Meng
Quoted 19 lines · Bin Meng

The following python error:

Traceback (most recent call last):
File "./tools/patman/patman", line 144, in <module>
series = patchstream.FixPatches(series, args)
File "./tools/patman/patchstream.py", line 477, in FixPatches
commit = series.commits[count]
IndexError: list index out of range

is seen when:

- 'END' is missing in those tags
- those tags are put in the last part in a commit message
- the commit is not the last commit of the series

Add testing logic to see if a new commit starts.

Quoted 7 lines

---

Changes in v2:
- New patch to handle missing 'END' in non-last commit of a series

 tools/patman/patchstream.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
#3 lore raw

PATCH v2 1/5 tools: patman: Use cover_match for 'Cover-letter'

In reply to Simon Glass
Quoted 8 lines · Simon Glass
Quoted 7 lines · Bin Meng

Like other patman tags, use a new variable cover_match to indicate a match for 'Cover-letter'.

---

Quoted 7 lines
Quoted 5 lines

Changes in v2:
- New patch to use cover_match for 'Cover-letter'

 tools/patman/patchstream.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Applied to u-boot-dm/next, thanks!

#5 lore raw

PATCH v2 2/5 tools: patman: Handle tag sections without an 'END'

In reply to Bin Meng
Quoted 11 lines · Bin Meng

'Cover-letter', 'Series-notes' and 'Commit-notes' tags require an 'END' to be put at the end of its section. If we forget to put an 'END' in those sections, and these sections are followed by another patman tag, patman generates incorrect patches. This adds codes to handle such scenario.

---

Quoted 8 lines

Changes in v2:
- Update commit message to explain when such scenario is hit
- Add cover_match to the test logic
- Generate warning for missing 'END' case

 tools/patman/patchstream.py | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Applied to u-boot-dm/next, thanks!

#8 lore raw

PATCH v2 3/5 tools: patman: Generate cover letter correctly when 'END' is missing

In reply to Simon Glass
Quoted 8 lines · Simon Glass
Quoted 7 lines · Bin Meng

If 'END' is missing in a 'Cover-letter' section, and that section happens to show up at the very end of the commit message, and the commit is the last commit of the series, patman fails to generate cover letter for us. Handle this in CloseCommit of patchstream.

Quoted 7 lines
Quoted 5 lines

---

Changes in v2:
- Update commit message to explain when such case is hit
- Reset in_section, skip_blank and section variables too

Applied to u-boot-dm/next, thanks!

#10 lore raw

PATCH v2 4/5 tools: patman: Handle missing blank line for 'Series-changes'

In reply to Bin Meng
Quoted 7 lines · Bin Meng

'Series-changes' uses blank line to indicate its end. If that is missing, series internal state variable 'in_change' may be wrong. Correct its state.

Quoted 7 lines

---

Changes in v2:
- Geneate warning when blank line is not found in 'Series-changes'

 tools/patman/patchstream.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Applied to u-boot-dm/next, thanks!

#13 lore raw

PATCH v2 5/5 tools: patman: Handle missing 'END' in non-last commit of a series

In reply to Simon Glass
Quoted 22 lines · Simon Glass
Quoted 21 lines · Bin Meng

The following python error:

Traceback (most recent call last):
File "./tools/patman/patman", line 144, in <module>
series = patchstream.FixPatches(series, args)
File "./tools/patman/patchstream.py", line 477, in FixPatches
commit = series.commits[count]
IndexError: list index out of range

is seen when:

- 'END' is missing in those tags
- those tags are put in the last part in a commit message
- the commit is not the last commit of the series

Add testing logic to see if a new commit starts.

---

Quoted 7 lines
Quoted 5 lines

Changes in v2:
- New patch to handle missing 'END' in non-last commit of a series

 tools/patman/patchstream.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Applied to u-boot-dm/next, thanks!