Skip to contentSkip to conversation

Two fixes for LoreMessage.get_body_parts()

PATCH Applied [email protected] 2 participants 4 messages Jul 26, 2020 – Jul 27, 2020

lore
Share & tools
lore
#0 lore raw

cover Two fixes for LoreMessage.get_body_parts()

After using 'b4 am' to grab a series from public-inbox meta [0], I noticed that many of the commit message bodies were missing. It turns out that this happens when a message body consists of only a single, non-trailer paragraph.

The second patch fixes this. The first patch addresses another issue I spotted when debugging the dropped commit messages.

[0]: https://public-inbox.org/meta/[email protected]

[1/2] Fix basement detection for empty commit message bodies [2/2] Fix handling of single-paragraph commit message bodies

 b4/__init__.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

base-commit: 2737ccdd3dbf58e330ace3ec658511bfbd715059

Signature · 1 line
2.27.0
author
#1 lore raw

PATCH 1/2 Fix basement detection for empty commit message bodies

The get_body_parts() method added in ba6c790 (Parse body parts into usual chunks, 2020-04-27) splits the commit message body on "\n---\n" and takes the second half as the "basement" of the patch. The body is stripped of flanking new lines, though, so a delimiter beginning with a new line isn't appropriate for commit messages without a message body. Make the starting new line optional.

Note that this doesn't matter in the end in terms of the final applied patch. Before 31f33fd (Fix body part parsing when '---' is not used, 2020-06-08), the expected patch output was produced despite the diff lines being processed as the message body. After that commit, the information following the triple dash is a bit off, but it doesn't matter because git discards it anyway.

---
 b4/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
b4/__init__.py +1 -1
index de6a274..7e3134f 100644
@@ -1204,7 +1204,7 @@ def get_body_parts(body):
             signature = sparts[1]
             body = sparts[0].rstrip('\n')
 
-        parts = body.split('\n---\n', 1)
+        parts = re.split('^---\n', body, maxsplit=1, flags=re.M)
         if len(parts) == 2:
             basement = parts[1].rstrip('\n')
         elif body.find('\ndiff ') >= 0:
Signature · 1 line
2.27.0
author
#2 lore raw

PATCH 2/2 Fix handling of single-paragraph commit message bodies

In reply to [email protected]

The get_body_parts() method added in ba6c790 (Parse body parts into usual chunks, 2020-04-27) strips lines that look like trailers from the last paragraph, storing the other lines to add back to the message. However, if the commit message has only a single paragraph, get_body_parts() returns early, unconditionally returning an empty string for the message even if non-trailer lines were encountered.

Return the collected non-trailer lines, if any, as the message.

---
 b4/__init__.py | 2 ++
 1 file changed, 2 insertions(+)
b4/__init__.py +2 -0
index 7e3134f..b7b33f4 100644
@@ -1241,6 +1241,8 @@ def get_body_parts(body):
             if githeaders == trailers:
                 # This is a message that consists of just trailers?
                 githeaders = list()
+            if nlines:
+                message = '\n'.join(nlines)
             return githeaders, message, trailers, basement, signature
 
         # Add all parts between first and last to mparts
Signature · 1 line
2.27.0
#3 lore raw
In reply to [email protected]
Quoted 7 lines · Kyle Meyer

After using 'b4 am' to grab a series from public-inbox meta [0], I noticed that many of the commit message bodies were missing. It turns out that this happens when a message body consists of only a single, non-trailer paragraph.

The second patch fixes this. The first patch addresses another issue I spotted when debugging the dropped commit messages.

Thanks, applied both to master and stable-0.5.y. I guess I'm so used to trailers that I haven't considered cases where there are commits without them. :)

-K