From 364cd111e20b411c27ff558a1f8006c549b84287 Mon Sep 17 00:00:00 2001 From: Sebastian Lackner Date: Tue, 5 Jan 2016 23:30:20 +0100 Subject: [PATCH] patchutils.py: Fix a bug related to #ifdef patch generator. (cherry picked from commit f2fccc7342942ffe916c66a60d4972eb623184d9) --- staging/patchutils.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/staging/patchutils.py b/staging/patchutils.py index a2f5caaf..1ef4a5a7 100644 --- a/staging/patchutils.py +++ b/staging/patchutils.py @@ -2,7 +2,7 @@ # # Python functions to read, split and apply patches. # -# Copyright (C) 2014 Sebastian Lackner +# Copyright (C) 2014-2016 Sebastian Lackner # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -565,8 +565,10 @@ def generate_ifdef_patch(original, patched, ifdef): # If this is the first hunk, then check if we have to extend it at the beginning if len(hunks) == 0: + assert srcpos == dstpos while srcpos > 0 and srcpos not in split: srcpos -= 1 + dstpos -= 1 srcdata.insert(0, lines[srcpos]) dstdata.insert(0, lines[srcpos]) hunks.append((srcpos, dstpos, srcdata, dstdata)) @@ -601,8 +603,8 @@ def generate_ifdef_patch(original, patched, ifdef): prev_dstdata.append(lines[prev_endpos]) prev_endpos += 1 assert prev_dstpos + len(prev_dstdata) == dstpos - hunks[-1][2] += srcdata - hunks[-1][3] += dstdata + prev_srcdata.extend(srcdata) + prev_dstdata.extend(dstdata) # Ready with this hunk pass