From 4b017e7ccadfe95f88fdd5c6834960eb4c6b0a11 Mon Sep 17 00:00:00 2001 From: Konstantin Ryabitsev Date: Wed, 15 Apr 2020 15:24:51 -0400 Subject: 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 Signed-off-by: Konstantin Ryabitsev --- b4/__init__.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/b4/__init__.py b/b4/__init__.py index d42051d..f509204 100644 --- a/b4/__init__.py +++ b/b4/__init__.py @@ -871,8 +871,11 @@ class LoreMessage: difflines = '' # 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) @@ -881,6 +884,10 @@ class LoreMessage: 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 @@ -894,12 +901,13 @@ class LoreMessage: # Feed this line to the hasher difflines += line + '\n' continue - if pp > 0: + if pp > 0 or mm > 0: # Inside the patch difflines += line + '\n' - 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) -- cgit v1.2.3