From unknown Fri Jun 20 07:12:17 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#25410 <25410@debbugs.gnu.org> To: bug#25410 <25410@debbugs.gnu.org> Subject: Status: 26.0.50; Refine an unified diff hunk only if adds lines Reply-To: bug#25410 <25410@debbugs.gnu.org> Date: Fri, 20 Jun 2025 14:12:17 +0000 retitle 25410 26.0.50; Refine an unified diff hunk only if adds lines reassign 25410 emacs submitter 25410 Tino Calancha severity 25410 normal tag 25410 fixed patch thanks From debbugs-submit-bounces@debbugs.gnu.org Tue Jan 10 05:08:42 2017 Received: (at submit) by debbugs.gnu.org; 10 Jan 2017 10:08:42 +0000 Received: from localhost ([127.0.0.1]:48399 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cQtMA-0002rL-Fl for submit@debbugs.gnu.org; Tue, 10 Jan 2017 05:08:42 -0500 Received: from eggs.gnu.org ([208.118.235.92]:57475) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cQtM8-0002r4-Ok for submit@debbugs.gnu.org; Tue, 10 Jan 2017 05:08:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cQtM2-0008Li-GW for submit@debbugs.gnu.org; Tue, 10 Jan 2017 05:08:35 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM, T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:58219) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cQtM2-0008Le-Da for submit@debbugs.gnu.org; Tue, 10 Jan 2017 05:08:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48444) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cQtM1-0005HY-3w for bug-gnu-emacs@gnu.org; Tue, 10 Jan 2017 05:08:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cQtLw-0008Jz-0P for bug-gnu-emacs@gnu.org; Tue, 10 Jan 2017 05:08:32 -0500 Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]:34974) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cQtLv-0008Jn-Qx for bug-gnu-emacs@gnu.org; Tue, 10 Jan 2017 05:08:27 -0500 Received: by mail-pf0-x244.google.com with SMTP id f144so9369328pfa.2 for ; Tue, 10 Jan 2017 02:08:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version; bh=wIegiNcfYhA52ufT8icyhjlOT9x22YzoFEqW7Ol1pic=; b=Cz45GMClZcYcPznWBQ4oCPPscmlyz/6WWJv2oGPsHCJ63QeiD10FaMjYpj0cLfWr9L eCoJNxeHjNa79GVDNvnqiZTNTqS1hZIVc+UuTVuaAclNWplOXKiQTFBVMvif+2rtnVwQ adevvWonPd89Z7WfIGFjsx3HhY/12JCy9JeqYWDOvPQNa1lkJHg+qXH+iuCYu0z+MN5b /4LJsslJ2kEUcPhYsPlq7Mj/HmuVJcX2Uqxmvvt/RUleWs7MA9YHFNk8PF079UQ7X7au fVKHrDwu40tbJUcYkXwJbNFPqHbw64hQAfkcLigQADZvD31ekB4WwfAQ2sm/X5xHAB0t DmOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=wIegiNcfYhA52ufT8icyhjlOT9x22YzoFEqW7Ol1pic=; b=A/kh1XL0R+bnzQ0QMOkJSc3wAFROmsVA+Uc1tQneFN1RDX+drJhBLEdn1ZkdJHVRoc m2PAtcd050yySsloHT4flRiDLxKEXVaXd1lTqdt0+6FiGz/1PfL2FqE0rtjUqXUhLmht aB0omazRfsduMwlzxvop850cDm47rfSuLPfSlZUhSxzYb5OgPv/0OMyn4q15Dwi/TDlB Vr8/p7Q1FUr/J9qYw07gDpVPaQoP3lICCIstukwwy4a/psDziEEpeSK3F6Cnh0S3tSps JSvSVCn80cNyGB7Ht31OjQsAXT4DUPZYURaMKi4PlpVwOuK+cIrRTzgbG0/n0GLvNpIG 4k0A== X-Gm-Message-State: AIkVDXKSNtPU3fcEENTvwC6It8fnqHH2+cZmZc8wB9B31UTKIefjJJgxJRPz0UyUPo3jEg== X-Received: by 10.98.93.152 with SMTP id n24mr2652094pfj.107.1484042905435; Tue, 10 Jan 2017 02:08:25 -0800 (PST) Received: from calancha-pc (217.225.128.101.dy.bbexcite.jp. [101.128.225.217]) by smtp.gmail.com with ESMTPSA id y62sm4191959pfk.52.2017.01.10.02.08.23 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Jan 2017 02:08:24 -0800 (PST) From: Tino Calancha To: bug-gnu-emacs@gnu.org Subject: 26.0.50; Refine an unified diff hunk only if adds lines Date: Tue, 10 Jan 2017 19:08:20 +0900 Message-ID: <8737grz0q3.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.0 (----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.0 (----) After deletion of a large file from CVS, a diff shows a very large hunk with just deleted lines. Then, for unified diffs, a call to `diff-refine-hunk' on that hunk takes a huge time. Instead, it's better to first check if the hunk adds new lines: only when this is true, then proceed with the hunk refinement. emacs -Q M-! git diff ef8c9f8^ ef8c9f8 RET C-x o M-x diff-mode RET C-c C-b ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; >From b3252092f8fdfc03c02d23022d901a625d183d89 Mon Sep 17 00:00:00 2001 From: Tino Calancha Date: Tue, 10 Jan 2017 18:46:00 +0900 Subject: [PATCH] Refine an unified diff hunk only if adds lines * lisp/vc/diff-mode.el (diff-refine-hunk): Refine the hunk only when adds some new lines (Bug#25410). --- lisp/vc/diff-mode.el | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index 9dfcd944bb..e045a5d974 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el @@ -2075,22 +2075,23 @@ diff-refine-hunk (props-c '((diff-mode . fine) (face diff-refine-changed))) (props-r '((diff-mode . fine) (face diff-refine-removed))) (props-a '((diff-mode . fine) (face diff-refine-added)))) - (remove-overlays beg end 'diff-mode 'fine) - (goto-char beg) (pcase style (`unified - (while (re-search-forward - (eval-when-compile - (let ((no-LF-at-eol-re "\\(?:\\\\.*\n\\)?")) - (concat "^\\(?:-.*\n\\)+" no-LF-at-eol-re - "\\(\\)" - "\\(?:\\+.*\n\\)+" no-LF-at-eol-re))) - end t) - (smerge-refine-subst (match-beginning 0) (match-end 1) - (match-end 1) (match-end 0) - nil 'diff-refine-preproc props-r props-a))) + ;; Refine hunk only when it adds lines (Bug#25410). + (when (re-search-forward "^\\(?:\\+.*\n\\)+" end t) + (goto-char beg) + (while (re-search-forward + (eval-when-compile + (let ((no-LF-at-eol-re "\\(?:\\\\.*\n\\)?")) + (concat "^\\(?:-.*\n\\)+" no-LF-at-eol-re + "\\(\\)" + "\\(?:\\+.*\n\\)+" no-LF-at-eol-re))) + end t) + (smerge-refine-subst (match-beginning 0) (match-end 1) + (match-end 1) (match-end 0) + nil 'diff-refine-preproc props-r props-a)))) (`context (let* ((middle (save-excursion (re-search-forward "^---"))) (other middle)) -- 2.11.0 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; In GNU Emacs 26.0.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.22.5) of 2017-01-09 Repository revision: ef8c9f8fc922b615aca91b47820d1f1900fddc96 From debbugs-submit-bounces@debbugs.gnu.org Tue Jan 10 09:21:41 2017 Received: (at 25410) by debbugs.gnu.org; 10 Jan 2017 14:21:41 +0000 Received: from localhost ([127.0.0.1]:48480 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cQxIy-0002gQ-TV for submit@debbugs.gnu.org; Tue, 10 Jan 2017 09:21:41 -0500 Received: from mail-it0-f50.google.com ([209.85.214.50]:35402) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cQxIx-0002gC-MO for 25410@debbugs.gnu.org; Tue, 10 Jan 2017 09:21:39 -0500 Received: by mail-it0-f50.google.com with SMTP id c20so75609657itb.0 for <25410@debbugs.gnu.org>; Tue, 10 Jan 2017 06:21:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=qq7F2HrD6g4aNkNmOrGS8wLwpVdv+8fmkcdAMlh1kJo=; b=QzmYa3GD8OaLMVK83mAqRuRqatW1f92EVK+IG2gTitaRLFB0F9EEPgWeNaI3q3umlJ ciJLVdTQeqlzyifNn0/hNPb44yC44TTgcwWGJp4jkcDcN/Sz6+EyBzBJahemTC5Tzu9D BbUeYjtmtQRbay4rKA/AxXr8sQ4aPkapzEod4JhbYxB666YBt5U2RphOjlqQLBRHmxJE ZJLLe1nWuWrp1zlnagouR1sG/+12FQkJ98Ck0ZB152lYXNpfvw7fR18EQUmUinjevW9h /UBD04QSbSqNDVsnc+sSwz0M1PIjc0J+wEMZtmf/NXtm5TYRtCm0QcASXrHFR5EBXjXr yEzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=qq7F2HrD6g4aNkNmOrGS8wLwpVdv+8fmkcdAMlh1kJo=; b=rkhNodFD08WXaBsdUnGyATK9TlAEc1PqLTS7xg5mZftYohOwksDERnMCUviTDJ32Rv k24tfHHQEWx1kNFTonMGsKcofdMuNctKgPseVAvKEcFjQchHbGQHqVcAebgkhljHEXh6 kk1rUikcUn1IxGT8H9VmKfZMjvU+Oth/BaxZSzKEVLBXyY3TVFaG7d6WEu7ZAK8K4JvU eCu20BvDKNBhRagnezsS5gMd1WJXSXe870YL5uV8h49sCo7ApQBidJpXrhVgB1laZEPK iwJWbPJ2BN7+xOrceE4odBZwXiEaT52Ht7AWCk54h2oHBWs2q/fuX0Odm8XzYF3bGay+ 3Zkg== X-Gm-Message-State: AIkVDXJ9DeIZ6ya2hKdJs7oCuCEJ8llN4vIyOXafil+DwPM3soRn9ycFdZZOFbNdzL7hzg== X-Received: by 10.36.66.143 with SMTP id i137mr185376itb.43.1484058094161; Tue, 10 Jan 2017 06:21:34 -0800 (PST) Received: from zony ([45.2.7.65]) by smtp.googlemail.com with ESMTPSA id j143sm10524815ita.1.2017.01.10.06.21.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Jan 2017 06:21:33 -0800 (PST) From: npostavs@users.sourceforge.net To: Tino Calancha Subject: Re: bug#25410: 26.0.50; Refine an unified diff hunk only if adds lines References: <8737grz0q3.fsf@gmail.com> Date: Tue, 10 Jan 2017 09:22:36 -0500 In-Reply-To: <8737grz0q3.fsf@gmail.com> (Tino Calancha's message of "Tue, 10 Jan 2017 19:08:20 +0900") Message-ID: <8737gr0zbn.fsf@users.sourceforge.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.2 (/) X-Debbugs-Envelope-To: 25410 Cc: 25410@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.2 (/) Tino Calancha writes: > After deletion of a large file from CVS, a diff shows > a very large hunk with just deleted lines. Then, for unified diffs, a call > to `diff-refine-hunk' on that hunk takes a huge time. > Instead, it's better to first check if the hunk adds new lines: only when > this is true, then proceed with the hunk refinement. What about a diff that adds a very large file? Perhaps we should only refine if there added lines *and* deleted lines? From debbugs-submit-bounces@debbugs.gnu.org Tue Jan 10 10:07:39 2017 Received: (at 25410) by debbugs.gnu.org; 10 Jan 2017 15:07:39 +0000 Received: from localhost ([127.0.0.1]:49044 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cQy1S-0003wN-4r for submit@debbugs.gnu.org; Tue, 10 Jan 2017 10:07:39 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:34183) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cQy1Q-0003w9-Rz for 25410@debbugs.gnu.org; Tue, 10 Jan 2017 10:07:37 -0500 Received: by mail-pf0-f194.google.com with SMTP id y143so8284828pfb.1 for <25410@debbugs.gnu.org>; Tue, 10 Jan 2017 07:07:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=TG5xc2b+9NhbDpg57tLpdYKPNIgAcbZeeou7Bh+A3v0=; b=iRcZmZojtpBzhIzeglSOL8L+1kyqJVcMV0eu2ERfoqHrbqz+UHtHnpQS5iPI1cBmm5 Y8KAschJddzSA9RrBkJXvayf4A8iYQtGYV3Ua3iaGg5Lq1VC7ZVV7bnztmtoTFUkcQA3 60wP6T/uyjEEAR8WTnGRKakLXoVRqnLYfDgNh3PYs+j6MmRWkfZvyoNs+NUTR9Uqf96F 5/6ejNFjW8fQ2X1laeW8hy2Y6QcVapbXvmA+0W5bwsdP4pMnBaXL6VF8eiKRE7lQycGb RUu89G76Z2Sq9nUhUCNtxTpkOerTORsIvDrj7cLvFoIiFpiDKtfUKmkojJqJN7WYkouC XZbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=TG5xc2b+9NhbDpg57tLpdYKPNIgAcbZeeou7Bh+A3v0=; b=VOBVwpgqS1PjxFfC8FCcgc8CX00vsrRouqXZN+8gb9kXJWhnK60iwraQy7g27csKLF WiW0Bv6fcPbq1758MVhbO8sCQtyw+cnTipR1UNltF78GFOUmY57mpOMGGMzjtAETS/sZ KnAo+UguxAOJ0WrPRKcXg+C4FDDmH1iRMnV4f1T2A2DSaT9gG5JYfcMFe9v79Uj7Dkeq vsdRHPEbcX2YDNHOKNkcttz0NtABtE1oQUXRvh6BdHrv/vTET3Ig4VUqxeN9FjWnE3YO +SO9MRjoOl8gXoCbID3a5nejMgJZ/jtGOzlIoOUH8InGin2MJ9wJqv5KpK1RXNHcQ0yx VEGA== X-Gm-Message-State: AIkVDXLkl1izTrkH1Hbxmgy/0zuuFO2qNkWxGFebUDCcvBtpSp6CfU+hreSZdTqd/weoTA== X-Received: by 10.98.220.91 with SMTP id t88mr4378009pfg.78.1484060850908; Tue, 10 Jan 2017 07:07:30 -0800 (PST) Received: from calancha-pc (217.225.128.101.dy.bbexcite.jp. [101.128.225.217]) by smtp.gmail.com with ESMTPSA id q190sm6533641pfb.51.2017.01.10.07.07.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Jan 2017 07:07:30 -0800 (PST) From: Tino Calancha X-Google-Original-From: Tino Calancha Date: Wed, 11 Jan 2017 00:07:28 +0900 (JST) X-X-Sender: calancha@calancha-pc To: npostavs@users.sourceforge.net Subject: Re: bug#25410: 26.0.50; Refine an unified diff hunk only if adds lines In-Reply-To: <8737gr0zbn.fsf@users.sourceforge.net> Message-ID: References: <8737grz0q3.fsf@gmail.com> <8737gr0zbn.fsf@users.sourceforge.net> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII X-Spam-Score: -0.6 (/) X-Debbugs-Envelope-To: 25410 Cc: 25410@debbugs.gnu.org, Tino Calancha X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.6 (/) On Tue, 10 Jan 2017, npostavs@users.sourceforge.net wrote: > Tino Calancha writes: > >> After deletion of a large file from CVS, a diff shows >> a very large hunk with just deleted lines. Then, for unified diffs, a call >> to `diff-refine-hunk' on that hunk takes a huge time. >> Instead, it's better to first check if the hunk adds new lines: only when >> this is true, then proceed with the hunk refinement. > > What about a diff that adds a very large file? Perhaps we should only > refine if there added lines *and* deleted lines? On Tue, 10 Jan 2017, npostavs@users.sourceforge.net wrote: >What about a diff that adds a very large file? Perhaps we should only >refine if there added lines *and* deleted lines? That's logical; at the end neither a hunk just deleting nor one just adding lines need to be refined. We might do that if you like. It would be more symmetrical. >From a performance point of view, current code in the case where the hunk just adds lines is not as patological as the opposite one. For instance: emacs -Q M-! git diff ef8c9f8^ ef8c9f8 RET C-x o C-x C-q M-x diff-mode RET R ; Reverse the direction of the diffs. C-c C-b ; Refine hunk. ;; Perform reasonably fast. From debbugs-submit-bounces@debbugs.gnu.org Tue Jan 10 21:49:58 2017 Received: (at 25410) by debbugs.gnu.org; 11 Jan 2017 02:49:58 +0000 Received: from localhost ([127.0.0.1]:49271 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cR8z8-0007xG-G1 for submit@debbugs.gnu.org; Tue, 10 Jan 2017 21:49:58 -0500 Received: from mail-pf0-f182.google.com ([209.85.192.182]:35359) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cR8z6-0007wx-8I for 25410@debbugs.gnu.org; Tue, 10 Jan 2017 21:49:56 -0500 Received: by mail-pf0-f182.google.com with SMTP id f144so47776415pfa.2 for <25410@debbugs.gnu.org>; Tue, 10 Jan 2017 18:49:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=nDoVce2refDbbZssMc0+25RQX2wmrZUNdc9ipGNAlBM=; b=u0ktRthTaYN6bjxwuep9APRz9PwYx08KNuz0WDB9SenUCZ8uMw3jUpBy1qMDmvpfQv 1jWfJE9NjGHDecjMfHuQrtXvbBrzdxczDaQKH2VGqrObV5qkB4E4fr+E/WTeJW369Lw4 8zZtSOW1m9LRgGeTBoKFoV+zbT6tTWQ0yMxhfsBoLPnaD0+5DykuhHvJUwTBA48MUHyY OR4m84WqzxISneIzJwyqoPAwdTW53eqIlneXUdJRfDOP6YU+pAMuqJMQsN+kr/ifdUlb 6zsAteGIAm/QHE5YWhkW2F1zgB5Bbs/FEebhPv0b4KYz9ZXLPtH4vh38di6wHjvz/ZLE gMww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=nDoVce2refDbbZssMc0+25RQX2wmrZUNdc9ipGNAlBM=; b=JgS4hlZzUbEPgkoAdiw1pTWXjNP87MHkGY5TiJgFFd1zd+xWEx0Gppav3eGjnkPUS/ SnzQHwKnTS1ytRStwoi9dI4oSpJhgc1pWEVcsiS1O2VEh9ilAPWwrICsOBsHFl9U4MDE RnV9aPvu5/Uv/+qkk1K+J3O6pFPS1BQYOOTx9F6uHAIrDxUxIVfYCledWx2jjTaiLQ1/ Sx3euYW8Le9E93xv1sQiSh8e0WRoTQZQxr31DmhbHCk+54jOEHHDg3ncMTzi+Mn5iIRV 1iRB3x2lJqCnTZKHZ69KN7+r3ayb+QF3Y84SrlP5ANEbx9iws0mXQXYbbTjtAyHFHzLZ Thgg== X-Gm-Message-State: AIkVDXLk9g1PzJRrXf8kFG2dQ85rYDtN9M5YD7Lz/0zRxZedAMdvfGn5lVQjMje248wCoA== X-Received: by 10.99.109.206 with SMTP id i197mr7457807pgc.4.1484102990450; Tue, 10 Jan 2017 18:49:50 -0800 (PST) Received: from calancha-pc (217.225.128.101.dy.bbexcite.jp. [101.128.225.217]) by smtp.gmail.com with ESMTPSA id a24sm8803240pfh.57.2017.01.10.18.49.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Jan 2017 18:49:49 -0800 (PST) From: Tino Calancha To: npostavs@users.sourceforge.net Subject: Re: bug#25410: 26.0.50; Refine an unified diff hunk only if adds lines References: <8737grz0q3.fsf@gmail.com> <8737gr0zbn.fsf@users.sourceforge.net> Date: Wed, 11 Jan 2017 11:49:45 +0900 In-Reply-To: <8737gr0zbn.fsf@users.sourceforge.net> (npostavs's message of "Tue, 10 Jan 2017 09:22:36 -0500") Message-ID: <87fukqe2eu.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -1.1 (-) X-Debbugs-Envelope-To: 25410 Cc: 25410@debbugs.gnu.org, Tino Calancha X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.1 (-) npostavs@users.sourceforge.net writes: > Tino Calancha writes: > >> After deletion of a large file from CVS, a diff shows >> a very large hunk with just deleted lines. Then, for unified diffs, a call >> to `diff-refine-hunk' on that hunk takes a huge time. >> Instead, it's better to first check if the hunk adds new lines: only when >> this is true, then proceed with the hunk refinement. > > What about a diff that adds a very large file? Perhaps we should only > refine if there added lines *and* deleted lines? I have updated the patch. Now it checks before the `pcase' that the hunk adds and removes lines. Only when this is true, we enter in the `pcase'. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; >From 0ff79ca6f106f121a05b8c5de55990b88fecb4d2 Mon Sep 17 00:00:00 2001 From: Tino Calancha Date: Wed, 11 Jan 2017 11:42:56 +0900 Subject: [PATCH] Only refine diff hunks that both remove and add lines * lisp/vc/diff-mode.el (diff-refine-hunk): Refine the hunk only if it adds and removes some lines (Bug#25410). --- lisp/vc/diff-mode.el | 77 ++++++++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index 9dfcd944bb..f0c53e6f8a 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el @@ -2075,44 +2075,45 @@ diff-refine-hunk (props-c '((diff-mode . fine) (face diff-refine-changed))) (props-r '((diff-mode . fine) (face diff-refine-removed))) (props-a '((diff-mode . fine) (face diff-refine-added)))) - - (remove-overlays beg end 'diff-mode 'fine) - - (goto-char beg) - (pcase style - (`unified - (while (re-search-forward - (eval-when-compile - (let ((no-LF-at-eol-re "\\(?:\\\\.*\n\\)?")) - (concat "^\\(?:-.*\n\\)+" no-LF-at-eol-re - "\\(\\)" - "\\(?:\\+.*\n\\)+" no-LF-at-eol-re))) - end t) - (smerge-refine-subst (match-beginning 0) (match-end 1) - (match-end 1) (match-end 0) - nil 'diff-refine-preproc props-r props-a))) - (`context - (let* ((middle (save-excursion (re-search-forward "^---"))) - (other middle)) - (while (re-search-forward "^\\(?:!.*\n\\)+" middle t) - (smerge-refine-subst (match-beginning 0) (match-end 0) - (save-excursion - (goto-char other) - (re-search-forward "^\\(?:!.*\n\\)+" end) - (setq other (match-end 0)) - (match-beginning 0)) - other - (if diff-use-changed-face props-c) - 'diff-refine-preproc - (unless diff-use-changed-face props-r) - (unless diff-use-changed-face props-a))))) - (_ ;; Normal diffs. - (let ((beg1 (1+ (point)))) - (when (re-search-forward "^---.*\n" end t) - ;; It's a combined add&remove, so there's something to do. - (smerge-refine-subst beg1 (match-beginning 0) - (match-end 0) end - nil 'diff-refine-preproc props-r props-a)))))))) + ;; Only refine the hunk if both adds and removes lines (Bug#25410). + (when (and (save-excursion (re-search-forward "^-.*\n" end t)) + (re-search-forward "^\\+.*\n" end t)) + (remove-overlays beg end 'diff-mode 'fine) + (goto-char beg) + (pcase style + (`unified + (while (re-search-forward + (eval-when-compile + (let ((no-LF-at-eol-re "\\(?:\\\\.*\n\\)?")) + (concat "^\\(?:-.*\n\\)+" no-LF-at-eol-re + "\\(\\)" + "\\(?:\\+.*\n\\)+" no-LF-at-eol-re))) + end t) + (smerge-refine-subst (match-beginning 0) (match-end 1) + (match-end 1) (match-end 0) + nil 'diff-refine-preproc props-r props-a))) + (`context + (let* ((middle (save-excursion (re-search-forward "^---"))) + (other middle)) + (while (re-search-forward "^\\(?:!.*\n\\)+" middle t) + (smerge-refine-subst (match-beginning 0) (match-end 0) + (save-excursion + (goto-char other) + (re-search-forward "^\\(?:!.*\n\\)+" end) + (setq other (match-end 0)) + (match-beginning 0)) + other + (if diff-use-changed-face props-c) + 'diff-refine-preproc + (unless diff-use-changed-face props-r) + (unless diff-use-changed-face props-a))))) + (_ ;; Normal diffs. + (let ((beg1 (1+ (point)))) + (when (re-search-forward "^---.*\n" end t) + ;; It's a combined add&remove, so there's something to do. + (smerge-refine-subst beg1 (match-beginning 0) + (match-end 0) end + nil 'diff-refine-preproc props-r props-a))))))))) (defun diff-undo (&optional arg) "Perform `undo', ignoring the buffer's read-only status." -- 2.11.0 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; In GNU Emacs 26.0.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.22.5) of 2017-01-10 Repository revision: fa0a2b4e7c81f57aecc1d94df00588a4dd5c281d From debbugs-submit-bounces@debbugs.gnu.org Wed Jan 11 03:13:14 2017 Received: (at 25410) by debbugs.gnu.org; 11 Jan 2017 08:13:14 +0000 Received: from localhost ([127.0.0.1]:49342 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cRE1y-0007MS-D8 for submit@debbugs.gnu.org; Wed, 11 Jan 2017 03:13:14 -0500 Received: from mail-pf0-f196.google.com ([209.85.192.196]:35795) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cRE1w-0007MG-PG for 25410@debbugs.gnu.org; Wed, 11 Jan 2017 03:13:13 -0500 Received: by mail-pf0-f196.google.com with SMTP id f144so13488156pfa.2 for <25410@debbugs.gnu.org>; Wed, 11 Jan 2017 00:13:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=tGezf4Cw4BJSVlnuIxULTTtG77sT9zoz/ysUUq0/Yic=; b=EldpRm4TZ2qisbwInv9X/ImPvKMsxRbX4CEXTFKJGgiNWALQmJEanLLd4u2TKjx5dL y1QgwJWZ9xPdENrpMDBCwmMMqGBRBqvTLwkYYUtGuhLNIlV3crAHA3ZgMIvbMG3PpBHD D303/oigK0LXpoAEycftSxfOuCUJBIvpoJWzOLmZYwraHyA6S7cSNZ7BoYB04VKMeNQl J64nHU3ByTQwr5OE/SafciLzNQ/ksRm/WEVaaxjecAt+e7WnYqTmRIVwou3yks6/oOF0 uv8H4p5/5UhgUMUA1oCnNXHi54Ymf0zFP7kJTsfAX1Vim+nBkVCHAGNrSHIAYOsU4xMu 8SoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=tGezf4Cw4BJSVlnuIxULTTtG77sT9zoz/ysUUq0/Yic=; b=s4Q3R02LmWl4v5BlGpz1gyBOEiyrNGcGZl4LnhhluIT6iowCIP7L8kp4WPJYRsyh33 ij4AsOypPWB5WAdgDKb29xKtDZJGqbjBYo+SgVo8MwggwZbWRkQ+YI+eSCcFo2P2OWTF nmb/ofTsPlJxBuyHte6unxNBo8Hmo9xe7rdwl8Sv7ydTdx+8OzAP2WKVD5mFHhZJsDDg icB6ZekHFF12xekzZfDR5vGTED0PrJ/T8/ai21K6rZ+EI5knT+7Jg7bI5OimJ6hDBLC4 ERAz+vpwshSPsJvD/SO9Jbclr79iR9igurKA2BZbZgXbfaifCaWEMhFgQj7+YNHHKNF/ ZArA== X-Gm-Message-State: AIkVDXLDTuF1kZY8vD5dJO2WpgO9SgVdXaxhlmWaqeVubWD9vQFoBRqhWCs92mY7WKlxhw== X-Received: by 10.98.75.156 with SMTP id d28mr8849226pfj.59.1484122387202; Wed, 11 Jan 2017 00:13:07 -0800 (PST) Received: from calancha-pc (217.225.128.101.dy.bbexcite.jp. [101.128.225.217]) by smtp.gmail.com with ESMTPSA id p25sm11289036pfd.0.2017.01.11.00.13.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Jan 2017 00:13:06 -0800 (PST) From: Tino Calancha To: npostavs@users.sourceforge.net Subject: Re: bug#25410: 26.0.50; Refine an unified diff hunk only if adds lines References: <8737grz0q3.fsf@gmail.com> <8737gr0zbn.fsf@users.sourceforge.net> <87fukqe2eu.fsf@gmail.com> Date: Wed, 11 Jan 2017 17:13:02 +0900 In-Reply-To: <87fukqe2eu.fsf@gmail.com> (Tino Calancha's message of "Wed, 11 Jan 2017 11:49:45 +0900") Message-ID: <8760lmqak1.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -1.8 (-) X-Debbugs-Envelope-To: 25410 Cc: 25410@debbugs.gnu.org, Tino Calancha X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.8 (-) Tino Calancha writes: > npostavs@users.sourceforge.net writes: > >> What about a diff that adds a very large file? Perhaps we should only >> refine if there added lines *and* deleted lines? > I have updated the patch. Now it checks before the `pcase' that > the hunk adds and removes lines. Only when this is true, we enter > in the `pcase'. > - nil 'diff-refine-preproc props-r props-a)))))))) > + ;; Only refine the hunk if both adds and removes lines (Bug#25410). > + (when (and (save-excursion (re-search-forward "^-.*\n" end t)) > + (re-search-forward "^\\+.*\n" end t)) > + (remove-overlays beg end 'diff-mode 'fine) > + (goto-char beg) > + (pcase style > + (`unified This check only has sense for unified diffs, where the new lines start with '+' and the deleted ones start with '-'. We might use the first patch in this thread or the following one: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; >From 89742f18291c1bb7fc99dfd5ac71a7d625699534 Mon Sep 17 00:00:00 2001 From: Tino Calancha Date: Wed, 11 Jan 2017 17:05:05 +0900 Subject: [PATCH] Refine an unified diff hunk only if both removes and adds lines * lisp/vc/diff-mode.el (diff-refine-hunk): Refine the unified diff hunk only if it adds and removes some lines (Bug#25410). --- lisp/vc/diff-mode.el | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index 9dfcd944bb..4cc20338c1 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el @@ -2075,22 +2075,23 @@ diff-refine-hunk (props-c '((diff-mode . fine) (face diff-refine-changed))) (props-r '((diff-mode . fine) (face diff-refine-removed))) (props-a '((diff-mode . fine) (face diff-refine-added)))) - (remove-overlays beg end 'diff-mode 'fine) - (goto-char beg) (pcase style (`unified - (while (re-search-forward - (eval-when-compile - (let ((no-LF-at-eol-re "\\(?:\\\\.*\n\\)?")) - (concat "^\\(?:-.*\n\\)+" no-LF-at-eol-re - "\\(\\)" - "\\(?:\\+.*\n\\)+" no-LF-at-eol-re))) - end t) - (smerge-refine-subst (match-beginning 0) (match-end 1) - (match-end 1) (match-end 0) - nil 'diff-refine-preproc props-r props-a))) + ;; Only refine an unified hunk if both adds and removes lines (Bug#25410). + (when (and (save-excursion (re-search-forward "^-.*\n" end t)) + (save-excursion (re-search-forward "^\\+.*\n" end t))) + (while (re-search-forward + (eval-when-compile + (let ((no-LF-at-eol-re "\\(?:\\\\.*\n\\)?")) + (concat "^\\(?:-.*\n\\)+" no-LF-at-eol-re + "\\(\\)" + "\\(?:\\+.*\n\\)+" no-LF-at-eol-re))) + end t) + (smerge-refine-subst (match-beginning 0) (match-end 1) + (match-end 1) (match-end 0) + nil 'diff-refine-preproc props-r props-a)))) (`context (let* ((middle (save-excursion (re-search-forward "^---"))) (other middle)) -- 2.11.0 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; In GNU Emacs 26.0.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.22.5) of 2017-01-11 Repository revision: fa0a2b4e7c81f57aecc1d94df00588a4dd5c281d From debbugs-submit-bounces@debbugs.gnu.org Thu Jan 12 00:32:13 2017 Received: (at 25410) by debbugs.gnu.org; 12 Jan 2017 05:32:13 +0000 Received: from localhost ([127.0.0.1]:50610 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cRXzh-0006h3-6n for submit@debbugs.gnu.org; Thu, 12 Jan 2017 00:32:13 -0500 Received: from mail-pf0-f175.google.com ([209.85.192.175]:36008) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cRXzf-0006go-2u for 25410@debbugs.gnu.org; Thu, 12 Jan 2017 00:32:11 -0500 Received: by mail-pf0-f175.google.com with SMTP id 189so6762991pfu.3 for <25410@debbugs.gnu.org>; Wed, 11 Jan 2017 21:32:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=TVNfhCDRtbcZ75U/w+7qd9GPlWZm45Nk6BJP/e4t218=; b=KPCE5rMEveWJYjn/7+5rlDr7JmuWuPBsspQvPwaA6MEx37CMMJCPRKzkd4LcXRykES 4pq48eFENYLFf2xX5ddnTA4s078XoVJ7rrnUKe1gEwvZB2y9qPzIbNcCBGBrpj5Up+vQ 2TRDmEKx9zOLNhkrq4Bgj3IIjdMKUcD0XkHsTZKGe/O0NTFI3Y2czkfPCwTwqgdMzMdd lhyvkDyAttOTkCxY7mkSAue3gc4z7MhcObDQvV8yvqa51vEzBAyUqeckdzL65/2uVtdU rmGJMD3+ZIEd1gBPgrE27EVwLaiQKIe++vNuiyjnO5BW6JgP+zg2vZTTniQgY/COdTYK jn5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=TVNfhCDRtbcZ75U/w+7qd9GPlWZm45Nk6BJP/e4t218=; b=edRKGGFg488G+W46yJPLbvfXv5m3y8sQ3roVofhaQzwWqpt/MSVAKzP8rBGnJqSPKW i3eT2iNn/oDa1NVnMEIdrVd4zOllzzligqphzrcFx0F+uhmHB+kn8FWpPb1/78i2ug7f 5sgTHOE5jg8ZSLM4vOIx1nTfHcZnicfGa2r79yWZ4Qi/mYAjVJAM5o6j2DzZFtaeqcGx u38PjDOb8ZbLq+3s1/B/yp5eRjD2/pdJKqUD6KGbmXV52BLWm6vZqfzfwJI6622dEiXe ZoaGgAAtqqf6AznqdIVF2vFbMcJHSgsXB7kDurDwbRlyGjv+3KOAG07CZ05wjIEWvTp/ PIBQ== X-Gm-Message-State: AIkVDXLEjV/mwIDLh1pKhLc8n/7YOqU1O3RVV6byALpEkFf2bWuCErNvnEkfDPJPZeWjzg== X-Received: by 10.98.208.70 with SMTP id p67mr14705961pfg.15.1484199125183; Wed, 11 Jan 2017 21:32:05 -0800 (PST) Received: from calancha-pc (217.225.128.101.dy.bbexcite.jp. [101.128.225.217]) by smtp.gmail.com with ESMTPSA id 64sm17692017pfu.17.2017.01.11.21.32.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jan 2017 21:32:04 -0800 (PST) From: Tino Calancha X-Google-Original-From: Tino Calancha Date: Thu, 12 Jan 2017 14:32:02 +0900 (JST) X-X-Sender: calancha@calancha-pc To: npostavs@users.sourceforge.net Subject: Re: bug#25410: 26.0.50; Refine an unified diff hunk only if adds lines In-Reply-To: <87wpe0zz0s.fsf@users.sourceforge.net> Message-ID: References: <8737grz0q3.fsf@gmail.com> <8737gr0zbn.fsf@users.sourceforge.net> <87fukqe2eu.fsf@gmail.com> <8760lmqak1.fsf@gmail.com> <87wpe0zz0s.fsf@users.sourceforge.net> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: 25410 Cc: 25410@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.3 (-) On Wed, 11 Jan 2017, npostavs@users.sourceforge.net wrote: > Tino Calancha writes: > >> From a performance point of view, current code in the case where >> the hunk just adds lines is not as patological as the opposite one. >> M-! git diff ef8c9f8^ ef8c9f8 RET > > By the way, with Emacs 25.1, I notice trying to refine this gives me a > regex stack overflow error. Probably my recent changes to the regex > stack limits allow Emacs to spend more time on this instead of > overflowing. Yeah, your commit has revealed such nasty regexp's. Before we get a stack overflow and the refine of the hunk ends. >> We might use the first patch in this thread or the following one: > > It's probably okay to use the first patch (i.e., don't bother checking > for delete-only hunks), with an added comment about the asymmetry. But > I think it would be better to change diff-refine-hunk to avoid the > inefficient regex, like this: I agree with you it's better to not use such heavy regexp matching too many lines. Your patch LGTM. Thank very much. >>From f5ea9e585b535390a69e442d83ecbeec8e8e18d2 Mon Sep 17 00:00:00 2001 >From: Noam Postavsky >Date: Wed, 11 Jan 2017 23:21:38 -0500 >Subject: [PATCH v1] Avoid inefficient regex in diff-refine-hunk (Bug#25410) > >* lisp/vc/diff-mode.el (diff--forward-while-leading-char): New function. >(diff-refine-hunk): Use it instead of trying to match multiple lines >with a single lines. >--- > lisp/vc/diff-mode.el | 27 +++++++++++++++++---------- > 1 file changed, 17 insertions(+), 10 deletions(-) > >diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el >index 9dfcd94..915e0b1 100644 >--- a/lisp/vc/diff-mode.el >+++ b/lisp/vc/diff-mode.el >@@ -2062,6 +2062,15 @@ diff-refine-preproc > (declare-function smerge-refine-subst "smerge-mode" > (beg1 end1 beg2 end2 props-c &optional preproc props-r props-a)) > >+(defun diff--forward-while-leading-char (char bound) >+ "Move point until reaching a line not starting with CHAR. >+Return new point, if it was moved." >+ (let ((pt nil)) >+ (while (and (< (point) bound) (eql (following-char) char)) >+ (forward-line 1) >+ (setq pt (point))) >+ pt)) >+ > (defun diff-refine-hunk () > "Highlight changes of hunk at point at a finer granularity." > (interactive) >@@ -2081,16 +2090,14 @@ diff-refine-hunk > (goto-char beg) > (pcase style > (`unified >- (while (re-search-forward >- (eval-when-compile >- (let ((no-LF-at-eol-re "\\(?:\\\\.*\n\\)?")) >- (concat "^\\(?:-.*\n\\)+" no-LF-at-eol-re >- "\\(\\)" >- "\\(?:\\+.*\n\\)+" no-LF-at-eol-re))) >- end t) >- (smerge-refine-subst (match-beginning 0) (match-end 1) >- (match-end 1) (match-end 0) >- nil 'diff-refine-preproc props-r props-a))) >+ (while (re-search-forward "^-" end t) >+ (let ((beg-del (progn (beginning-of-line) (point))) >+ beg-add end-add) >+ (when (and (setq beg-add (diff--forward-while-leading-char ?- end)) >+ (or (diff--forward-while-leading-char ?\\ end) t) >+ (setq end-add (diff--forward-while-leading-char ?+ end))) >+ (smerge-refine-subst beg-del beg-add beg-add end-add >+ nil 'diff-refine-preproc props-r props-a))))) > (`context > (let* ((middle (save-excursion (re-search-forward "^---"))) > (other middle)) >-- >2.9.3 > From debbugs-submit-bounces@debbugs.gnu.org Thu Jan 12 23:49:44 2017 Received: (at 25410) by debbugs.gnu.org; 13 Jan 2017 04:49:44 +0000 Received: from localhost ([127.0.0.1]:51986 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cRto8-0000Pu-H6 for submit@debbugs.gnu.org; Thu, 12 Jan 2017 23:49:44 -0500 Received: from mail-it0-f66.google.com ([209.85.214.66]:32982) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cRto5-0000Pb-VN; Thu, 12 Jan 2017 23:49:42 -0500 Received: by mail-it0-f66.google.com with SMTP id v14so4034337itb.0; Thu, 12 Jan 2017 20:49:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=TVbCtGf9/I4dbe8wHt76dseOJ53fCAQCwEfWgKdUyr8=; b=Qwl1E4ZBH9h+whyBKF+q+NiIU8gqFksFb7X9XLUWL0vViGzC5SbN3vRPkld/x6DBzF jNebOiHgZpkK+wd5d6Y9jc+790TqX78ja3Jz1WNHb1IaJZUKsyjMofjT+kWanhdMnJLI mXQPMnZApbJLaKy8fUpvq+7JYZw5z2eKCZTmT3YqIOR4I3wPTnT3rkIDT7nJdCJd6TjU WqFZc4uQRGY0JqurJNKulN+7pRqnoZeryO31MjHmDQlw1uQ3O6wexeQr1QTxoh2OgKJj LrS7C5uUakk1vEyhhDAOieXiiNWPMLaPWUooJtEucFDX+h/3txKbBOYIPrRJME72g7rJ B+rQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=TVbCtGf9/I4dbe8wHt76dseOJ53fCAQCwEfWgKdUyr8=; b=aWBIai/MlbeMd9De4LV7hTUWBZgSA7K5cpQt506B34y1ONUWtUP2SJAlddQfD4t8DO m+JeTbTbjEcnYaAemFSL2tGPVTTDLSK4njYILZAgNlmqlmp1Xc0Vrv15mtO9XB8yEhcB zpPD6lYlm3EDz2mYMEfzQet8Di8hsy/gSqD7yP8pot3W6z75GVU7dDNZ/3fXJ+E9Ty1i InMyTzWyNZpZvoqP16eFNujM9KJSjwQinzcE99vWce5OTqNz62DGK+UZ7heA7iHhrccG h14CaIbcEazyj5epQFtrheBVI30auFkeXrRtJZSsOX/Oa7L8AhJe+hlbveXWKX1BzMhn yqDA== X-Gm-Message-State: AIkVDXKTeI2MSJ/eod2B/ZKBgwKb6zWZpZORVSCBnmN2HP5YaR7mS/aiydwvzih3TtzBfw== X-Received: by 10.36.66.4 with SMTP id i4mr660839itb.67.1484282976154; Thu, 12 Jan 2017 20:49:36 -0800 (PST) Received: from zony ([45.2.7.65]) by smtp.googlemail.com with ESMTPSA id v75sm359972ita.12.2017.01.12.20.49.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 12 Jan 2017 20:49:35 -0800 (PST) From: npostavs@users.sourceforge.net To: Tino Calancha Subject: Re: bug#25410: 26.0.50; Refine an unified diff hunk only if adds lines References: <8737grz0q3.fsf@gmail.com> <8737gr0zbn.fsf@users.sourceforge.net> <87fukqe2eu.fsf@gmail.com> <8760lmqak1.fsf@gmail.com> <87wpe0zz0s.fsf@users.sourceforge.net> Date: Thu, 12 Jan 2017 23:50:40 -0500 In-Reply-To: (Tino Calancha's message of "Thu, 12 Jan 2017 14:32:02 +0900 (JST)") Message-ID: <87inpjzhpb.fsf@users.sourceforge.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: 25410 Cc: 25410@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.5 (/) --=-=-= Content-Type: text/plain tags 25410 patch quit >> (`unified >>- (while (re-search-forward >>- (eval-when-compile >>- (let ((no-LF-at-eol-re "\\(?:\\\\.*\n\\)?")) >>- (concat "^\\(?:-.*\n\\)+" no-LF-at-eol-re >>- "\\(\\)" >>- "\\(?:\\+.*\n\\)+" no-LF-at-eol-re))) >>- end t) [...] >> + (while (re-search-forward "^-" end t) >> + (let ((beg-del (progn (beginning-of-line) (point))) >> + beg-add end-add) >> + (when (and (setq beg-add (diff--forward-while-leading-char ?- end)) >> + (or (diff--forward-while-leading-char ?\\ end) t) >> + (setq end-add (diff--forward-while-leading-char ?+ end))) Actually I made a mistake here, this doesn't allow for "\ No newline at end of file" in the + part of the hunk. Here's v2 (seems I hit Reply instead of Followup when sending v1, so it didn't reach the list). --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=v2-0001-Avoid-inefficient-regex-in-diff-refine-hunk-Bug-2.patch Content-Description: patch >From dd49ab3921744930b422dc408f44206055c94cae Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Thu, 12 Jan 2017 23:32:44 -0500 Subject: [PATCH v2] Avoid inefficient regex in diff-refine-hunk (Bug#25410) * lisp/vc/diff-mode.el (diff--forward-while-leading-char): New function. (diff-refine-hunk): Use it instead of trying to match multiple lines with a single lines. --- lisp/vc/diff-mode.el | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index 9dfcd94..b50b4a2 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el @@ -2062,6 +2062,15 @@ diff-refine-preproc (declare-function smerge-refine-subst "smerge-mode" (beg1 end1 beg2 end2 props-c &optional preproc props-r props-a)) +(defun diff--forward-while-leading-char (char bound) + "Move point until reaching a line not starting with CHAR. +Return new point, if it was moved." + (let ((pt nil)) + (while (and (< (point) bound) (eql (following-char) char)) + (forward-line 1) + (setq pt (point))) + pt)) + (defun diff-refine-hunk () "Highlight changes of hunk at point at a finer granularity." (interactive) @@ -2081,16 +2090,18 @@ diff-refine-hunk (goto-char beg) (pcase style (`unified - (while (re-search-forward - (eval-when-compile - (let ((no-LF-at-eol-re "\\(?:\\\\.*\n\\)?")) - (concat "^\\(?:-.*\n\\)+" no-LF-at-eol-re - "\\(\\)" - "\\(?:\\+.*\n\\)+" no-LF-at-eol-re))) - end t) - (smerge-refine-subst (match-beginning 0) (match-end 1) - (match-end 1) (match-end 0) - nil 'diff-refine-preproc props-r props-a))) + (while (re-search-forward "^-" end t) + (let ((beg-del (progn (beginning-of-line) (point))) + beg-add end-add) + (when (and (diff--forward-while-leading-char ?- end) + ;; Allow for "\ No newline at end of file". + (progn (diff--forward-while-leading-char ?\\ end) + (setq beg-add (point))) + (diff--forward-while-leading-char ?+ end) + (progn (diff--forward-while-leading-char ?\\ end) + (setq end-add (point)))) + (smerge-refine-subst beg-del beg-add beg-add end-add + nil 'diff-refine-preproc props-r props-a))))) (`context (let* ((middle (save-excursion (re-search-forward "^---"))) (other middle)) -- 2.9.3 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Fri Jan 13 01:14:16 2017 Received: (at 25410) by debbugs.gnu.org; 13 Jan 2017 06:14:16 +0000 Received: from localhost ([127.0.0.1]:52005 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cRv7w-0005v5-Db for submit@debbugs.gnu.org; Fri, 13 Jan 2017 01:14:16 -0500 Received: from mail-pf0-f179.google.com ([209.85.192.179]:35353) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cRv7u-0005ul-7G for 25410@debbugs.gnu.org; Fri, 13 Jan 2017 01:14:14 -0500 Received: by mail-pf0-f179.google.com with SMTP id f144so25956278pfa.2 for <25410@debbugs.gnu.org>; Thu, 12 Jan 2017 22:14:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=2Mg3S9zejRh/E7dAuOvM5BJCxOF0d0ytNA4qqcCBgFk=; b=ljHidW0jSMhjaVxKzaOI1RWfGbNLFnuUfgC+5ByQYH3I4J1ZYoboFz+6eMeOCPEGJ3 qCul2kbDevP1wheXz2BhBM7sQ9l0at0Fg+QQ/4vN74IVwwDULOIJzuud3n428aXUzXw6 NokGOVAwoO71KleIXaNLc6hLZbkw/xA8G632hGdj5iKM08Mga1V2qgcookULma6ewMd8 zjJp1wgPn+WfY2idIhE7h25Mqi4RCWez6xDBfVCrnG6/JNc0B8aFCw+dKc1mEQ0M9KHe jnuy/plhen+d02Fru29asLn61f9zcE9+sWcDbt4LI/hrUX78WcXhCaaqHXAsqaOuTO4N rVBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=2Mg3S9zejRh/E7dAuOvM5BJCxOF0d0ytNA4qqcCBgFk=; b=FRzFkzVmoAiBk0ZBvvTxbnWlavzBWtobiUjNDRVoJDt5vgXDvARLjkv0MbTjNqaivD qjAeBQnFTKFuqZJwX09JrmVBoYxSSVI1YwGW4/UuOdKzEu0C0IiPlM29miw0GDTLgNZm IvnslkBY9FRAdzYXLElxLvBwUiyJZvLXBXoXD6sVHORKd8SnItk92liNBQAdO+OQJiCD kgweCDptRgKHIyJTPc51rP6GS5pdvh1x3cRbspOgEbzgXWOda3IXYMCC8Q5K9F/jas6A OL7IMT1ZKPlq1fEbSmxK76ju4booO3zlPS0uDI/HjcKkO25nDfrxODDohdjTiieTdo7d Lw/g== X-Gm-Message-State: AIkVDXIlmAbMWG5k1AEwb5NO4bVfPHecAFKOUFIWOlbchF7MKt83pzFs+ruIQotim43d2w== X-Received: by 10.84.133.129 with SMTP id f1mr26930643plf.64.1484288048209; Thu, 12 Jan 2017 22:14:08 -0800 (PST) Received: from calancha-pc (217.225.128.101.dy.bbexcite.jp. [101.128.225.217]) by smtp.gmail.com with ESMTPSA id x16sm25495196pfk.79.2017.01.12.22.14.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Jan 2017 22:14:07 -0800 (PST) From: Tino Calancha X-Google-Original-From: Tino Calancha Date: Fri, 13 Jan 2017 15:14:04 +0900 (JST) X-X-Sender: calancha@calancha-pc To: npostavs@users.sourceforge.net Subject: Re: bug#25410: 26.0.50; Refine an unified diff hunk only if adds lines In-Reply-To: <87inpjzhpb.fsf@users.sourceforge.net> Message-ID: References: <8737grz0q3.fsf@gmail.com> <8737gr0zbn.fsf@users.sourceforge.net> <87fukqe2eu.fsf@gmail.com> <8760lmqak1.fsf@gmail.com> <87wpe0zz0s.fsf@users.sourceforge.net> <87inpjzhpb.fsf@users.sourceforge.net> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII X-Spam-Score: -1.1 (-) X-Debbugs-Envelope-To: 25410 Cc: 25410@debbugs.gnu.org, Tino Calancha X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.1 (-) On Thu, 12 Jan 2017, npostavs@users.sourceforge.net wrote: >+ (while (re-search-forward "^-" end t) >+ (let ((beg-del (progn (beginning-of-line) (point))) >+ beg-add end-add) >+ (when (and (diff--forward-while-leading-char ?- end) >+ ;; Allow for "\ No newline at end of file". >+ (progn (diff--forward-while-leading-char ?\\ end) >+ (setq beg-add (point))) >+ (diff--forward-while-leading-char ?+ end) >+ (progn (diff--forward-while-leading-char ?\\ end) >+ (setq end-add (point)))) >+ (smerge-refine-subst beg-del beg-add beg-add end-add >+ nil 'diff-refine-preproc props-r props-a))))) How about hide the complexity resulting for checking ?\\ inside the auxiliary function? diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index 9dfcd944bb..e3487a722b 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el @@ -2062,6 +2062,19 @@ diff-refine-preproc (declare-function smerge-refine-subst "smerge-mode" (beg1 end1 beg2 end2 props-c &optional preproc props-r props-a)) +(defun diff--forward-while-leading-char (char bound &optional ok-no-lf-eol) + "Move point until reaching a line not starting with CHAR. +Return new point, if it was moved. +If optional arg OK-NO-LF-EOL is non-nil, then allow no newline at end of line." + (let ((orig (point))) + (cl-labels ((fn (ch limit) + (while (and (< (point) limit) (eql (following-char) ch)) + (forward-line 1)))) + (progn + (fn char bound) + (when ok-no-lf-eol (fn ?\\ bound)) + (unless (= orig (point)) (point)))))) + (defun diff-refine-hunk () "Highlight changes of hunk at point at a finer granularity." (interactive) @@ -2081,16 +2094,13 @@ diff-refine-hunk (goto-char beg) (pcase style (`unified - (while (re-search-forward - (eval-when-compile - (let ((no-LF-at-eol-re "\\(?:\\\\.*\n\\)?")) - (concat "^\\(?:-.*\n\\)+" no-LF-at-eol-re - "\\(\\)" - "\\(?:\\+.*\n\\)+" no-LF-at-eol-re))) - end t) - (smerge-refine-subst (match-beginning 0) (match-end 1) - (match-end 1) (match-end 0) - nil 'diff-refine-preproc props-r props-a))) + (while (re-search-forward "^-" end t) + (let ((beg-del (progn (beginning-of-line) (point))) + (beg-add (diff--forward-while-leading-char ?- end 'no-lf-eol)) + (end-add (diff--forward-while-leading-char ?+ end 'no-lf-eol))) + (when (and beg-add end-add) + (smerge-refine-subst beg-del beg-add beg-add end-add + nil 'diff-refine-preproc props-r props-a))))) (`context (let* ((middle (save-excursion (re-search-forward "^---"))) (other middle)) From debbugs-submit-bounces@debbugs.gnu.org Fri Jan 13 07:11:31 2017 Received: (at 25410) by debbugs.gnu.org; 13 Jan 2017 12:11:31 +0000 Received: from localhost ([127.0.0.1]:52127 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cS0he-0008AV-Oj for submit@debbugs.gnu.org; Fri, 13 Jan 2017 07:11:31 -0500 Received: from mail-pf0-f170.google.com ([209.85.192.170]:35938) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cS0hd-0008AJ-IH for 25410@debbugs.gnu.org; Fri, 13 Jan 2017 07:11:29 -0500 Received: by mail-pf0-f170.google.com with SMTP id 189so30969605pfu.3 for <25410@debbugs.gnu.org>; Fri, 13 Jan 2017 04:11:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:subject:in-reply-to:message-id:references:user-agent :mime-version; bh=Mf6zOXp1l3XOyVEXMTZ981b89FaMg2qTMSYBtYAg3q0=; b=u8o1TMXFhqkzRXcSDaCIvqSYhIXWRYvrP+7gpQAqA3TnSqAWFnYrjwYGVAJXnCJnEQ ag8zl/+2vDW4lYKGMWfJMsPJaAAkij7cixavK5k4vP47rJ1KyU1Zz5G1FZOuEr8vA0Us ICz6V5FQjjJfZIY0I+PRjckRBX6pwPmE5+XO9bJUiD7ucKm9vXjxp7ZYB4ntcIwWVBqQ kEnMkBCwyvfmvk19ujzkGCqWD38dOlO3ZB0bSUrikHocM0sRY82igqL0mR+IdjuagwPp xImOiTKhwbykopDHONSzWyXRsgNdbMFVN1T3tJY+7tRzoD5McYy/QDA8xedZ2sgDqnak GJEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=Mf6zOXp1l3XOyVEXMTZ981b89FaMg2qTMSYBtYAg3q0=; b=GqYWUOxcRuWJViYvNBIqL9JMMpXXm1gtav0stxHbA4IjnyGpv3n0x/c5s6FHGQqrMD y7TBT6zCdWCl1WgrA3OocDgK154330tsQCD4RGirPyh3FDD2iE7ahsCFX90roW1pAKOy SA3+7k8nZO7YG3RrNDekAwNGHwvxL6FaKslYc0FXJ4dhZllDrOIjyyEpOAgLo/j/ScFI vSYCIti07fVOgFV6pep2jWbRwAtbVQ2mVJnL9WcFuOIkrs+yzd5k9lsBTkGJyV/PE9yy gkzCMSuX5k/xZht3br2CJv7ugMkEdV5E5FlX0X7vDadzvWeCsUotQCHkqtsmKtMOMfoX QK7Q== X-Gm-Message-State: AIkVDXK5VzBTj7wMTVFiU2qLAa9t+1Te4+vkPnSpKl5nIlrtVUZYe22z46CQnPfu8kelsQ== X-Received: by 10.98.86.203 with SMTP id h72mr12833411pfj.108.1484309482992; Fri, 13 Jan 2017 04:11:22 -0800 (PST) Received: from calancha-pc (217.225.128.101.dy.bbexcite.jp. [101.128.225.217]) by smtp.gmail.com with ESMTPSA id r78sm28935339pfe.55.2017.01.13.04.11.21 for <25410@debbugs.gnu.org> (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jan 2017 04:11:22 -0800 (PST) From: Tino Calancha X-Google-Original-From: Tino Calancha Date: Fri, 13 Jan 2017 21:11:20 +0900 (JST) X-X-Sender: calancha@calancha-pc To: 25410@debbugs.gnu.org Subject: Re: bug#25410: 26.0.50; Refine an unified diff hunk only if adds lines In-Reply-To: Message-ID: References: <8737grz0q3.fsf@gmail.com> <8737gr0zbn.fsf@users.sourceforge.net> <87fukqe2eu.fsf@gmail.com> <8760lmqak1.fsf@gmail.com> <87wpe0zz0s.fsf@users.sourceforge.net> <87inpjzhpb.fsf@users.sourceforge.net> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: 25410 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.3 (-) On Fri, 13 Jan 2017, Tino Calancha wrote: > + (while (re-search-forward "^-" end t) > + (let ((beg-del (progn (beginning-of-line) (point))) > + (beg-add (diff--forward-while-leading-char ?- end 'no-lf-eol)) > + (end-add (diff--forward-while-leading-char ?+ end 'no-lf-eol))) > + (when (and beg-add end-add) > + (smerge-refine-subst beg-del beg-add beg-add end-add > + nil 'diff-refine-preproc props-r props-a))))) This is symmetrical respect beg-add/end-add but we could save a `diff--forward-while-leading-char' call if beg-add is nil. I think the following lazy version is better: diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index 9dfcd944bb..d550a59d6d 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el @@ -2062,6 +2062,19 @@ diff-refine-preproc (declare-function smerge-refine-subst "smerge-mode" (beg1 end1 beg2 end2 props-c &optional preproc props-r props-a)) +(defun diff--forward-while-leading-char (char bound &optional ok-no-lf-eol) + "Move point until reaching a line not starting with CHAR. +Return new point, if it was moved. +If optional arg OK-NO-LF-EOL is non-nil, then allow no newline at end of line." + (let ((orig (point))) + (cl-labels ((fn (ch limit) + (while (and (< (point) limit) (eql (following-char) ch)) + (forward-line 1)))) + (progn + (fn char bound) + (when ok-no-lf-eol (fn ?\\ bound)) + (unless (= orig (point)) (point)))))) + (defun diff-refine-hunk () "Highlight changes of hunk at point at a finer granularity." (interactive) @@ -2081,16 +2094,14 @@ diff-refine-hunk (goto-char beg) (pcase style (`unified - (while (re-search-forward - (eval-when-compile - (let ((no-LF-at-eol-re "\\(?:\\\\.*\n\\)?")) - (concat "^\\(?:-.*\n\\)+" no-LF-at-eol-re - "\\(\\)" - "\\(?:\\+.*\n\\)+" no-LF-at-eol-re))) - end t) - (smerge-refine-subst (match-beginning 0) (match-end 1) - (match-end 1) (match-end 0) - nil 'diff-refine-preproc props-r props-a))) + (while (re-search-forward "^-" end t) + (let* ((beg-del (progn (beginning-of-line) (point))) + (beg-add (diff--forward-while-leading-char ?- end t)) + (end-add (and beg-add + (diff--forward-while-leading-char ?+ end t)))) + (when end-add + (smerge-refine-subst beg-del beg-add beg-add end-add + nil 'diff-refine-preproc props-r props-a))))) (`context (let* ((middle (save-excursion (re-search-forward "^---"))) (other middle)) From debbugs-submit-bounces@debbugs.gnu.org Fri Jan 13 11:31:18 2017 Received: (at 25410) by debbugs.gnu.org; 13 Jan 2017 16:31:18 +0000 Received: from localhost ([127.0.0.1]:53079 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cS4l4-000196-0J for submit@debbugs.gnu.org; Fri, 13 Jan 2017 11:31:18 -0500 Received: from mail-oi0-f65.google.com ([209.85.218.65]:34899) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cS4l2-00018r-89 for 25410@debbugs.gnu.org; Fri, 13 Jan 2017 11:31:16 -0500 Received: by mail-oi0-f65.google.com with SMTP id x84so7392702oix.2 for <25410@debbugs.gnu.org>; Fri, 13 Jan 2017 08:31:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=1wFPIaFhqhsnX8DmCI4a2ma6rMFZ3V9+YmjP2FNe8gU=; b=Fm7BIV8susi/TJBzSSTwCk+XkUkaYfzGmTPBLh7YMPh7XKq+4tIsI1FFLcKhRNTQNK tt5Bip/TxZH856CjBqE3ue6hzf37n8FKXByR0/YG/yvr98b/WXUUq/L2jx+1vYhQKfJG PQeRg6L7uujIQGJhZwp78wntM6oRjnKPbOEMbliOKy4j5Fpy7NTqd1mzXsQmmdYG7FOG uA7N9hEhpyiKyhxxSbG0ct3HddLGhbRwt2mp1Bqkumkk8WAHSUFOKBiBkX3z8QcYch/+ W5q3t0mWj+TtqinnLhABRcOPcam000TLNarJBzHX2ava0QcJR8nSyip0rGE2AsXH/cNB WMGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=1wFPIaFhqhsnX8DmCI4a2ma6rMFZ3V9+YmjP2FNe8gU=; b=EqsL1xJArI9jO7l/NO48oc1Vwxc5AIZ8xzZKsLvfEQ7b6p6ZzirxdLdRROdW/dBDE/ +LhzB6bFXbe16six54Pgy5jFawnlJZtvYb8EZcJFpFl3fJ1xCFjHTjQB0f+uaxWLGREY I4IBTMxyI1zplVABcJEf4NE5dsvjnO5bSwW79vmDjM4Z3IdexV/UKrZH3W5YyLysKbQw x034zB1had3HuK4nUDxy7wgqC6ZjDiyevub74fC26JMGbImBdExaJHwsQPeElnCt9SQm aOylFRX1dHC5bGITM7IuOppSHtkLfL31RCyVvHTbrEDOef+NHjnPDTy5jxkhWpdy3L8H R84A== X-Gm-Message-State: AIkVDXIspKTNBaga+NUuL/qybBG792kTLMMtS4LzplQtKDKw7tq189+miaZ5dYMGK+FE0InSh/Gvd41WqE+aAg== X-Received: by 10.157.36.161 with SMTP id z30mr1409150ota.208.1484325070607; Fri, 13 Jan 2017 08:31:10 -0800 (PST) MIME-Version: 1.0 Received: by 10.157.21.117 with HTTP; Fri, 13 Jan 2017 08:31:10 -0800 (PST) In-Reply-To: References: <8737grz0q3.fsf@gmail.com> <8737gr0zbn.fsf@users.sourceforge.net> <87fukqe2eu.fsf@gmail.com> <8760lmqak1.fsf@gmail.com> <87wpe0zz0s.fsf@users.sourceforge.net> <87inpjzhpb.fsf@users.sourceforge.net> From: Noam Postavsky Date: Fri, 13 Jan 2017 11:31:10 -0500 X-Google-Sender-Auth: QnLGIkJfIeP7AAvoNRo24lrLrxE Message-ID: Subject: Re: bug#25410: 26.0.50; Refine an unified diff hunk only if adds lines To: Tino Calancha Content-Type: text/plain; charset=UTF-8 X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: 25410 Cc: 25410@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.5 (/) On Fri, Jan 13, 2017 at 1:14 AM, Tino Calancha wrote: > >> + (while (re-search-forward "^-" end t) >> + (let ((beg-del (progn (beginning-of-line) (point))) >> + beg-add end-add) >> + (when (and (diff--forward-while-leading-char ?- end) >> + ;; Allow for "\ No newline at end of file". >> + (progn (diff--forward-while-leading-char ?\\ end) >> + (setq beg-add (point))) >> + (diff--forward-while-leading-char ?+ end) >> + (progn (diff--forward-while-leading-char ?\\ end) >> + (setq end-add (point)))) > > How about hide the complexity resulting for checking ?\\ inside the > auxiliary function? I'm okay with doing this, but I slightly prefer leaving the complexity at the top level. I think pushing the ?\\ check inside diff--forward-while-leading-char makes that function's purpose a bit incoherent and the complexity reduction in the caller doesn't look significant enough to balance that. From debbugs-submit-bounces@debbugs.gnu.org Sat Jan 14 00:38:50 2017 Received: (at 25410) by debbugs.gnu.org; 14 Jan 2017 05:38:50 +0000 Received: from localhost ([127.0.0.1]:53271 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cSH3B-0007Qk-Ph for submit@debbugs.gnu.org; Sat, 14 Jan 2017 00:38:49 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:36203) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cSH39-0007QX-CS for 25410@debbugs.gnu.org; Sat, 14 Jan 2017 00:38:48 -0500 Received: by mail-pf0-f194.google.com with SMTP id 19so62019pfo.3 for <25410@debbugs.gnu.org>; Fri, 13 Jan 2017 21:38:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=oemeoTz2rdVjO+kbo85NMp7uqGBE/s2SHDIBnAUx12M=; b=K3Z3tdnDcqEazXI3g1Z66KrTGqoGLcBxQGKCrIfXUss+LX2PaKzViMgfCbGn2/Fblw ztEYIF1uKZY/412sHgbZRPjJVddD/0C534E94gFDsBirLomTsHI1AbrQ3poljXSgvbsl zkpn5UOS8t9dp3YbuXYXGjyUzkxiBMs+DYJu8SKkdOmhRW4yHgvFYxhV7mkkqs1iG8ku U3jBgHQ1zaR2y7db6vMvSS7oFuJloWQxZiHtJidUigYjI7BD31TrnAG2q5802qhiySPG g7g5EWw12n0BP0iD3QO6OBEGrp2nmQTcm7ybNbkkBraUv3fgUFsPED66bht2bcaembBP tgjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=oemeoTz2rdVjO+kbo85NMp7uqGBE/s2SHDIBnAUx12M=; b=YKG2EUW+A7XaHYuT6CO5drfDIQbi7QYPe2NLxmuPifAoW/KZA4XcZMcmQSUqjPxhdd iaE+yMa8YzKD2LDPI6ECUgKsd8/A3SozrmMnNu8udZr4Cx1LivwFS3KgHGguQl3RmVz6 O/NbO8lZlu31BOwoSTShhDD+NpE7z5aQotqFwKLXsriZUNi/e5DPfV1oDj8aQJa0uVW2 0h0TmRnovUp/05oWCS7u6n4Dya4azk/kJmYD9DLb4o6FYCy8GxvlNvaHTdThmVXeonSr B4GkCO2zt77eZyiHtsvgV6ApneHqyHcvsnUZGzUjnQ8zVElhLhUWCNdMksJ3YZ/gee8g PwKQ== X-Gm-Message-State: AIkVDXK3bK+C+D86UC6AVznudfepaJRdHPvSZArAol22xj6ePWv8nDFnBYFR30rq0S8Cpg== X-Received: by 10.84.198.129 with SMTP id p1mr35067159pld.14.1484372321391; Fri, 13 Jan 2017 21:38:41 -0800 (PST) Received: from calancha-pc (33.94.100.220.dy.bbexcite.jp. [220.100.94.33]) by smtp.gmail.com with ESMTPSA id a25sm32898938pgd.26.2017.01.13.21.38.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jan 2017 21:38:40 -0800 (PST) From: Tino Calancha X-Google-Original-From: Tino Calancha Date: Sat, 14 Jan 2017 14:38:36 +0900 (JST) X-X-Sender: calancha@calancha-pc To: Noam Postavsky Subject: Re: bug#25410: 26.0.50; Refine an unified diff hunk only if adds lines In-Reply-To: Message-ID: References: <8737grz0q3.fsf@gmail.com> <8737gr0zbn.fsf@users.sourceforge.net> <87fukqe2eu.fsf@gmail.com> <8760lmqak1.fsf@gmail.com> <87wpe0zz0s.fsf@users.sourceforge.net> <87inpjzhpb.fsf@users.sourceforge.net> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed X-Spam-Score: -0.6 (/) X-Debbugs-Envelope-To: 25410 Cc: 25410@debbugs.gnu.org, Tino Calancha X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.6 (/) On Fri, 13 Jan 2017, Noam Postavsky wrote: > On Fri, Jan 13, 2017 at 1:14 AM, Tino Calancha wrote: >> >>> + (while (re-search-forward "^-" end t) >>> + (let ((beg-del (progn (beginning-of-line) (point))) >>> + beg-add end-add) >>> + (when (and (diff--forward-while-leading-char ?- end) >>> + ;; Allow for "\ No newline at end of file". >>> + (progn (diff--forward-while-leading-char ?\\ end) >>> + (setq beg-add (point))) >>> + (diff--forward-while-leading-char ?+ end) >>> + (progn (diff--forward-while-leading-char ?\\ end) >>> + (setq end-add (point)))) >> >> How about hide the complexity resulting for checking ?\\ inside the >> auxiliary function? > > I'm okay with doing this, but I slightly prefer leaving the complexity > at the top level. I think pushing the ?\\ check inside > diff--forward-while-leading-char makes that function's purpose a bit > incoherent and the complexity reduction in the caller doesn't look > significant enough to balance that. Agreed. Indeed, keeping simple `diff--forward-while-leading-char' favours reutilization: it seems to me like this function could be used elsewhere. From debbugs-submit-bounces@debbugs.gnu.org Wed Jan 18 20:54:09 2017 Received: (at 25410) by debbugs.gnu.org; 19 Jan 2017 01:54:09 +0000 Received: from localhost ([127.0.0.1]:35101 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cU1vV-0004VC-Jt for submit@debbugs.gnu.org; Wed, 18 Jan 2017 20:54:09 -0500 Received: from mail-it0-f67.google.com ([209.85.214.67]:34865) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cU1vS-0004Uf-Tu; Wed, 18 Jan 2017 20:54:07 -0500 Received: by mail-it0-f67.google.com with SMTP id 203so3567450ith.2; Wed, 18 Jan 2017 17:54:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=czh6LZNVhKle+TuXaWvjWUSiqrQMmTki82VnQ2R0ln0=; b=r21O5jf8StAyuGnhbRfpN6bHEbHS5gQCS9jlg+ssLQ7SnUTcXHkTKojdQeXZ1Nf2mJ cavMbyuB3sP1BONQ9eAfO9C1czXnDrZ/KWORq4mE2JEGEMHRG0kBMw0keWVQs0wGvxrq XKJs/quIQZkbvx2EjFDkMnAkM40vYMoYUSPq0b+IEG3Ke9OvnvyqsRLsjCSW5eAQJsLQ aV8xAHqJKkxTT6DIIx5zKX9eISPZr2vTb2tCw59fhU+ZoX6YVXvvE9NExdrp1+GVfihB Hv8QNMa8+j4+/viBnM1T9mxkCxG4ZcqmXvyEFy9staCTQIDZt1X2nMv8Mcoo5/4X7OUl 7YmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=czh6LZNVhKle+TuXaWvjWUSiqrQMmTki82VnQ2R0ln0=; b=W6zGRpJtyDMbGXOFXFxH+c00GNAXPdtQy/9uKRPBiSD4wIK8FIZxFUaDekEQaunJwn 7HL0l6QuFxmc31tevvfC/BlbUN34p1hH4egwtknoI13neosX+lRdQ5R48S4ClN1Mh+nM Tnh85ugqPHTa3U0xZX8erDtDwLW/waNb22RdZda2Abxvde+yHV3F3wN2Ip8mhf7/hGeR gUpGqDAh7iIYeoMucSINfg6mdxTL2axCGKvaAjJDJ1RNxCHmPrYdmjUglVkHZxL+TkRS 8u/6vj3p0ERa5JKxItP7uWBUmwvj2ftd3jJ3u6rGccK5yKvOEG4D0j8V055LQkri5ikU 67mw== X-Gm-Message-State: AIkVDXJIBoo25trE/FougItVz54cQ+qdXB58IhPeiInKZumfN0LLwLT9fZtdnMTBLB99EQ== X-Received: by 10.36.155.194 with SMTP id o185mr28997619itd.71.1484790841186; Wed, 18 Jan 2017 17:54:01 -0800 (PST) Received: from zony ([45.2.7.65]) by smtp.googlemail.com with ESMTPSA id j88sm2011879ioo.29.2017.01.18.17.54.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Jan 2017 17:54:00 -0800 (PST) From: npostavs@users.sourceforge.net To: Tino Calancha Subject: Re: bug#25410: 26.0.50; Refine an unified diff hunk only if adds lines References: <8737grz0q3.fsf@gmail.com> <8737gr0zbn.fsf@users.sourceforge.net> <87fukqe2eu.fsf@gmail.com> <8760lmqak1.fsf@gmail.com> <87wpe0zz0s.fsf@users.sourceforge.net> <87inpjzhpb.fsf@users.sourceforge.net> Date: Wed, 18 Jan 2017 20:55:07 -0500 In-Reply-To: <87inpjzhpb.fsf@users.sourceforge.net> (npostavs@users.sourceforge.net's message of "Thu, 12 Jan 2017 23:50:40 -0500") Message-ID: <87o9z3x18k.fsf@users.sourceforge.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: 25410 Cc: 25410@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.5 (/) tags 25410 fixed close 25410 26.1 quit npostavs@users.sourceforge.net writes: > Subject: [PATCH v2] Avoid inefficient regex in diff-refine-hunk (Bug#25410) Pushed to master [1: 8c0fcaf] 1: 2017-01-18 20:37:31 -0500 8c0fcaf66733f0538a3f024f383cb34a3c93d73c Avoid inefficient regex in diff-refine-hunk (Bug#25410) From unknown Fri Jun 20 07:12:17 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Thu, 16 Feb 2017 12:24:03 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator