50ebb75e1e0753bd98c209b445199260fea35601 — Denis Laxalde 6 months ago efa0c30 0.38.1
Add a trailing "\n" to email body before parsing diff

Emails from Mercurial apparently do not have a line ending; this is
problematic when trying to parse them with pygit2.Diff.parse_diff()
because there is no "signature" ("-- \n<git version>") and the body ends
with the last hunk which hence fails to parse with "invalid patch
instruction at line NN" error:

1 files changed, 6 insertions(+), 1 deletions(-)

M listssrht/types/email.py
M listssrht/types/email.py => listssrht/types/email.py +6 -1
@@ 102,8 102,13 @@ class Email(Base):
    # libgit2 Diff object parsed from message body (if it exists)
    def patch(self):
        if not hasattr(self, "_patch"):
            body = self.body.replace("\r\n", "\n")
            # mercurial/patchbomb emails' body may not end with a EOL; this
            # makes pygit2 fail to parse diff hunks
            if not body.endswith("\n"):
                body += "\n"
                self._patch = pygit2.Diff.parse_diff(self.body.replace("\r\n", "\n"))
                self._patch = pygit2.Diff.parse_diff(body)
                self.is_patch = len(self._patch) > 0
                self.is_patch = False