[{"id":28957,"web_url":"https://patchwork.libcamera.org/comment/28957/","msgid":"<171041875834.252503.9677733863716691877@ping.linuxembedded.co.uk>","date":"2024-03-14T12:19:18","subject":"Re: [PATCH] checkstyle: Work around bug in difflib","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Stefan Klug (2024-03-14 10:57:36)\n> If a file misses the newline at the end it gets detected by checkstyle,\n> but the resulting patch is incorrect and does not apply. It took me a\n> while to understand that it wasn't me using checkstyle incorrectly, but\n> that the patch was faulty. The bug itself is in difflib and dates back to\n> 2008.\n\nOpen source speeds!\n\n> To reproduce:\n> - Remove trailing newline from a file\n> - git add the file\n> - run ./utils/checkstyle.py -s | patch -p0\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> ---\n>  utils/checkstyle.py | 6 ++++++\n>  1 file changed, 6 insertions(+)\n> \n> diff --git a/utils/checkstyle.py b/utils/checkstyle.py\n> index db5a550d..20a5a592 100755\n> --- a/utils/checkstyle.py\n> +++ b/utils/checkstyle.py\n> @@ -168,6 +168,12 @@ def parse_diff(diff):\n>              hunk = DiffHunk(line)\n>  \n>          elif hunk is not None:\n> +            # Work around https://github.com/python/cpython/issues/46395\n> +            # See https://www.gnu.org/software/diffutils/manual/html_node/Incomplete-Lines.html\n> +            if line[-1] != '\\n':\n> +                hunk.append(line + '\\n')\n> +                line = \"\\\\ No newline at end of file\\n\"\n\nThis looks reasonable, but at a glance I can't tell if the \\\\ is an\nescaped \\ or a double \\\\ ?\n\nBased on the text at \nhttps://www.gnu.org/software/diffutils/manual/html_node/Incomplete-Lines.html\n\n```\n For example, suppose F and G are one-byte files that contain just ‘f’\n and ‘g’, respectively. Then ‘diff F G’ outputs\n \n 1c1\n < f\n \\ No newline at end of file\n ---\n > g\n \\ No newline at end of file\n```\nI assume it's an escape, and only a single line is printed, and based on\nthat assumption:\n\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> +\n>              hunk.append(line)\n>  \n>      if hunk:\n> -- \n> 2.40.1\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 42208BD808\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 14 Mar 2024 12:19:24 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4653A62C9F;\n\tThu, 14 Mar 2024 13:19:23 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 44DE262C94\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 14 Mar 2024 13:19:21 +0100 (CET)","from pendragon.ideasonboard.com\n\t(aztw-30-b2-v4wan-166917-cust845.vm26.cable.virginm.net\n\t[82.37.23.78])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C92F0E4;\n\tThu, 14 Mar 2024 13:18:57 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"DWQ5iUrd\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1710418737;\n\tbh=AwBvD5FsbzaF12eSt/My5FB79VeeKeV20Gh2g6Lb33Q=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=DWQ5iUrdfqyMvAcKpdh3VoH+4aMjmWBZqjuBA6OBO0tIqjkzuH/peFEeW08eeqFUw\n\te/nHgSWxZIpDP9p++00+FEsRBUWy6h/clMtcE2Js/NCOJcjArlyfdSkLSJAMA7rtPv\n\t7O/aegpe6NIexXNx/J6ybVhzTjwtJLBMZf+bxQNE=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20240314105736.109201-1-stefan.klug@ideasonboard.com>","References":"<20240314105736.109201-1-stefan.klug@ideasonboard.com>","Subject":"Re: [PATCH] checkstyle: Work around bug in difflib","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Thu, 14 Mar 2024 12:19:18 +0000","Message-ID":"<171041875834.252503.9677733863716691877@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":28958,"web_url":"https://patchwork.libcamera.org/comment/28958/","msgid":"<20240314125006.dlk747eoe6mfvqch@jasper>","date":"2024-03-14T12:50:06","subject":"Re: [PATCH] checkstyle: Work around bug in difflib","submitter":{"id":184,"url":"https://patchwork.libcamera.org/api/people/184/","name":"Stefan Klug","email":"stefan.klug@ideasonboard.com"},"content":"Hi Kieran,\n\nthanks for the review.\n\nOn Thu, Mar 14, 2024 at 12:19:18PM +0000, Kieran Bingham wrote:\n> Quoting Stefan Klug (2024-03-14 10:57:36)\n> > If a file misses the newline at the end it gets detected by checkstyle,\n> > but the resulting patch is incorrect and does not apply. It took me a\n> > while to understand that it wasn't me using checkstyle incorrectly, but\n> > that the patch was faulty. The bug itself is in difflib and dates back to\n> > 2008.\n> \n> Open source speeds!\n> \n> > To reproduce:\n> > - Remove trailing newline from a file\n> > - git add the file\n> > - run ./utils/checkstyle.py -s | patch -p0\n> > \n> > Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> > ---\n> >  utils/checkstyle.py | 6 ++++++\n> >  1 file changed, 6 insertions(+)\n> > \n> > diff --git a/utils/checkstyle.py b/utils/checkstyle.py\n> > index db5a550d..20a5a592 100755\n> > --- a/utils/checkstyle.py\n> > +++ b/utils/checkstyle.py\n> > @@ -168,6 +168,12 @@ def parse_diff(diff):\n> >              hunk = DiffHunk(line)\n> >  \n> >          elif hunk is not None:\n> > +            # Work around https://github.com/python/cpython/issues/46395\n> > +            # See https://www.gnu.org/software/diffutils/manual/html_node/Incomplete-Lines.html\n> > +            if line[-1] != '\\n':\n> > +                hunk.append(line + '\\n')\n> > +                line = \"\\\\ No newline at end of file\\n\"\n> \n> This looks reasonable, but at a glance I can't tell if the \\\\ is an\n> escaped \\ or a double \\\\ ?\n\nYes, it's an escaped backslash.\n\nCheers\nStefan\n\n> \n> Based on the text at \n> https://www.gnu.org/software/diffutils/manual/html_node/Incomplete-Lines.html\n> \n> ```\n>  For example, suppose F and G are one-byte files that contain just ‘f’\n>  and ‘g’, respectively. Then ‘diff F G’ outputs\n>  \n>  1c1\n>  < f\n>  \\ No newline at end of file\n>  ---\n>  > g\n>  \\ No newline at end of file\n> ```\n> I assume it's an escape, and only a single line is printed, and based on\n> that assumption:\n> \n> \n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> > +\n> >              hunk.append(line)\n> >  \n> >      if hunk:\n> > -- \n> > 2.40.1\n> >","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 73E75BD160\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 14 Mar 2024 12:50:12 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A58BF62C9C;\n\tThu, 14 Mar 2024 13:50:11 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D40CF62C98\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 14 Mar 2024 13:50:09 +0100 (CET)","from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:c467:7cd1:67a9:bc4c])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 57E3B675;\n\tThu, 14 Mar 2024 13:49:46 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"co/Byzk2\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1710420586;\n\tbh=5AsTTFOPJokJyDJ4KpI/lsMGf0liE34GWeg1k/I20jk=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=co/Byzk2ICRNYy40wy1yd701uEbEcp444waIho1GzDYSnqQg82wFNSMJGhVk4jvNw\n\tNwVaRDTK56TAetXD5ZMZMQyUy0j+bQL91Dqpk41oChL023/HUALSPj95DyRkjf92qQ\n\tq2pYs2AN9RVAVkXTioltlmkrzu6v1lvzu9q7p6rI=","Date":"Thu, 14 Mar 2024 13:50:06 +0100","From":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Subject":"Re: [PATCH] checkstyle: Work around bug in difflib","Message-ID":"<20240314125006.dlk747eoe6mfvqch@jasper>","References":"<20240314105736.109201-1-stefan.klug@ideasonboard.com>\n\t<171041875834.252503.9677733863716691877@ping.linuxembedded.co.uk>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<171041875834.252503.9677733863716691877@ping.linuxembedded.co.uk>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":28982,"web_url":"https://patchwork.libcamera.org/comment/28982/","msgid":"<20240315124524.GI2441@pendragon.ideasonboard.com>","date":"2024-03-15T12:45:24","subject":"Re: [PATCH] checkstyle: Work around bug in difflib","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Stefan,\n\nThank you for the patch.\n\nOn Thu, Mar 14, 2024 at 11:57:36AM +0100, Stefan Klug wrote:\n> If a file misses the newline at the end it gets detected by checkstyle,\n> but the resulting patch is incorrect and does not apply. It took me a\n> while to understand that it wasn't me using checkstyle incorrectly, but\n> that the patch was faulty. The bug itself is in difflib and dates back to\n> 2008.\n> \n> To reproduce:\n> - Remove trailing newline from a file\n> - git add the file\n> - run ./utils/checkstyle.py -s | patch -p0\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> ---\n>  utils/checkstyle.py | 6 ++++++\n>  1 file changed, 6 insertions(+)\n> \n> diff --git a/utils/checkstyle.py b/utils/checkstyle.py\n> index db5a550d..20a5a592 100755\n> --- a/utils/checkstyle.py\n> +++ b/utils/checkstyle.py\n> @@ -168,6 +168,12 @@ def parse_diff(diff):\n>              hunk = DiffHunk(line)\n>  \n>          elif hunk is not None:\n> +            # Work around https://github.com/python/cpython/issues/46395\n> +            # See https://www.gnu.org/software/diffutils/manual/html_node/Incomplete-Lines.html\n> +            if line[-1] != '\\n':\n> +                hunk.append(line + '\\n')\n> +                line = \"\\\\ No newline at end of file\\n\"\n\ns/\"/'/g\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> +\n>              hunk.append(line)\n>  \n>      if hunk:","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 52D69BD808\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 15 Mar 2024 12:45:31 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3E74062C8C;\n\tFri, 15 Mar 2024 13:45:30 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id AC50361C65\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 15 Mar 2024 13:45:28 +0100 (CET)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 562A1899;\n\tFri, 15 Mar 2024 13:45:04 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"wTk04K7i\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1710506704;\n\tbh=DehBgGCYZ/xvr90HssYqnRWnkkhpclqYsxkMKVanMtA=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=wTk04K7i9s14M/JocPQz6uZ9gl/ebvih1BqUTFPmPenAJcCCyns1afif5H+L2JkBa\n\tgy2oS6Iq3po/0EHCuWyhUKj6wezPYoFO/2OBpNX+9XpePWLS/M3SGG7L7XgIlRwcC2\n\t/9XI7JmYiKhGypR51nmgVe3fV6ynPXk7bfsLw+0c=","Date":"Fri, 15 Mar 2024 14:45:24 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>","Subject":"Re: [PATCH] checkstyle: Work around bug in difflib","Message-ID":"<20240315124524.GI2441@pendragon.ideasonboard.com>","References":"<20240314105736.109201-1-stefan.klug@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20240314105736.109201-1-stefan.klug@ideasonboard.com>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]