diff options
author | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2020-04-15 15:24:51 -0400 |
---|---|---|
committer | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2020-04-15 15:24:51 -0400 |
commit | 4b017e7ccadfe95f88fdd5c6834960eb4c6b0a11 (patch) | |
tree | 96dc75d123ad4dac2be126ecc01586d679b15659 | |
parent | 71fe12b6d68d95cb72dcfe769ed79760e3a1efed (diff) | |
download | b4-4b017e7ccadfe95f88fdd5c6834960eb4c6b0a11.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__.py | 18 |
1 files 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) |