diff options
author | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2020-04-20 12:04:14 -0400 |
---|---|---|
committer | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2020-04-20 12:06:26 -0400 |
commit | a857294bf5f40b1ca364a3901763429ff1bba926 (patch) | |
tree | 76ffee5fbaafdcd8927f6e0b70847ea4b188f6bd | |
parent | d77b3df240768c6d2ede4b99dbe09fb661327ff8 (diff) | |
download | b4-a857294bf5f40b1ca364a3901763429ff1bba926.tar.gz |
Support file delete patches and binary patches
Git's file delete patches don't contain hunks, so we weren't properly
processing them for attestation (and for b4 am). While fixing that, I
also added attestation support for binary patches.
Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rw-r--r-- | b4/__init__.py | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/b4/__init__.py b/b4/__init__.py index f509204..0a250ef 100644 --- a/b4/__init__.py +++ b/b4/__init__.py @@ -653,7 +653,7 @@ class LoreMessage: self.date = email.utils.parsedate_to_datetime(str(self.msg['Date'])) - diffre = re.compile(r'^(---.*\n\+\+\+|GIT binary patch)', re.M | re.I) + diffre = re.compile(r'^(---.*\n\+\+\+|GIT binary patch|diff --git \w/\S+ \w/\S+)', re.M | re.I) diffstatre = re.compile(r'^\s*\d+ file.*\d+ (insertion|deletion)', re.M | re.I) # walk until we find the first text/plain part @@ -872,8 +872,31 @@ class LoreMessage: # Used for counting where we are in the patch pp = mm = 0 + inside_binary_chunk = False for line in diff.split('\n'): if not len(line): + if inside_binary_chunk: + inside_binary_chunk = False + # add all buflines to difflines + difflines += '\n'.join(buflines) + '\n\n' + buflines = list() + continue + buflines.append(line) + continue + elif inside_binary_chunk: + buflines.append(line) + continue + # If line starts with 'index ' and previous line starts with 'deleted ', then + # it's a file delete and therefore doesn't have a regular hunk. + if line.find('index ') == 0 and len(buflines) > 1 and buflines[-1].find('deleted ') == 0: + # add this and 2 preceding lines to difflines and reset buflines + buflines.append(line) + difflines += '\n'.join(buflines[-3:]) + '\n' + buflines = list() + continue + if line.find('delta ') == 0 or line.find('literal ') == 0: + # we are inside a binary patch + inside_binary_chunk = True buflines.append(line) continue hunk_match = HUNK_RE.match(line) @@ -920,7 +943,6 @@ class LoreMessage: # # This subroutine removes anything at the beginning of diff data, like # diffstat or any other auxiliary data, and anything trailing at the end - # XXX: This currently doesn't work for git binary patches # diff = LoreMessage.get_clean_diff(diff) phasher = hashlib.sha256() |