aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-04-15 15:24:51 -0400
committerKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-04-15 15:34:39 -0400
commit626a2aedb1b1446274f0bde0323c483d16aaf7fd (patch)
tree9bef02052e4aad7cfd4262052bfc31b988cea5f2
parentda8f89b60109c7ebd9595bd7422692c341df191e (diff)
downloadb4-626a2aedb1b1446274f0bde0323c483d16aaf7fd.tar.gz
Properly deal with diffs that delete all lines
We weren't properly handling special diffs that deleted entire file contents (e.g. by deleting a file). Reported-by: Mark Brown <broonie@kernel.org> Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rw-r--r--b4/__init__.py25
1 files changed, 18 insertions, 7 deletions
diff --git a/b4/__init__.py b/b4/__init__.py
index 9039280..2d2e730 100644
--- a/b4/__init__.py
+++ b/b4/__init__.py
@@ -21,7 +21,7 @@ from email import charset
charset.add_charset('utf-8', None)
emlpolicy = email.policy.EmailPolicy(utf8=True, cte_type='8bit', max_line_length=None)
-__VERSION__ = '0.3.7'
+__VERSION__ = '0.3.8-dev'
ATTESTATION_FORMAT_VER = '0.1'
logger = logging.getLogger('b4')
@@ -717,13 +717,23 @@ class LoreMessage:
phasher = hashlib.sha256()
# Used for counting where we are in the patch
- pp = 0
+ pp = mm = 0
for line in diff.split('\n'):
+ if not len(line):
+ buflines.append(line)
+ continue
hunk_match = HUNK_RE.match(line)
if hunk_match:
# logger.debug('Crunching %s', line)
mlines, plines = hunk_match.groups()
- pp = int(plines)
+ try:
+ pp = int(plines)
+ except TypeError:
+ pp = 1
+ try:
+ mm = int(mlines)
+ except TypeError:
+ mm = 1
addlines = list()
for bline in reversed(buflines):
# Go backward and add lines until we get to the start
@@ -737,12 +747,13 @@ class LoreMessage:
# Feed this line to the hasher
phasher.update((line + '\n').encode('utf-8'))
continue
- if pp > 0:
+ if pp > 0 or mm > 0:
# Inside the patch
phasher.update((line + '\n').encode('utf-8'))
- if len(line) and line[0] == '-':
- continue
- pp -= 1
+ if line[0] in (' ', '-'):
+ mm -= 1
+ if line[0] in (' ', '+'):
+ pp -= 1
continue
# Not anything we recognize, so stick into buflines
buflines.append(line)