From patchwork Thu Mar 14 10:57:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 19717 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 41A39BD160 for ; Thu, 14 Mar 2024 10:57:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3218E62C99; Thu, 14 Mar 2024 11:57:52 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="o2v7Oq8y"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1DB7762C95 for ; Thu, 14 Mar 2024 11:57:50 +0100 (CET) Received: from jasper.fritz.box (unknown [IPv6:2a00:6020:448c:6c00:c467:7cd1:67a9:bc4c]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id BC4D36BE; Thu, 14 Mar 2024 11:57:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1710413846; bh=IgueFOjiLOtES9cdFLoEPfpm1f/crVXbPNTt6gawpU4=; h=From:To:Cc:Subject:Date:From; b=o2v7Oq8ylbS3VoOSzb3qk9lc9smC4zu9C9JT2q2oQeKOaNsDfIdVwyLYc12oFIPEI wPs5wIJeXL3UoYUbHMADh50HKn0s63ZYpUjbYezIF1+vQXdo7vae282+yRT/g8Hmee 4DAlgMJK7rUuRHk8JRu9L8m+Yo6YrLmvC65BWfW4= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Subject: [PATCH] checkstyle: Work around bug in difflib Date: Thu, 14 Mar 2024 11:57:36 +0100 Message-Id: <20240314105736.109201-1-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stefan Klug Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" If a file misses the newline at the end it gets detected by checkstyle, but the resulting patch is incorrect and does not apply. It took me a while to understand that it wasn't me using checkstyle incorrectly, but that the patch was faulty. The bug itself is in difflib and dates back to 2008. To reproduce: - Remove trailing newline from a file - git add the file - run ./utils/checkstyle.py -s | patch -p0 Signed-off-by: Stefan Klug Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- utils/checkstyle.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/utils/checkstyle.py b/utils/checkstyle.py index db5a550d..20a5a592 100755 --- a/utils/checkstyle.py +++ b/utils/checkstyle.py @@ -168,6 +168,12 @@ def parse_diff(diff): hunk = DiffHunk(line) elif hunk is not None: + # Work around https://github.com/python/cpython/issues/46395 + # See https://www.gnu.org/software/diffutils/manual/html_node/Incomplete-Lines.html + if line[-1] != '\n': + hunk.append(line + '\n') + line = "\\ No newline at end of file\n" + hunk.append(line) if hunk: