From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: npostavs@users.sourceforge.net Newsgroups: gmane.emacs.bugs Subject: bug#25410: 26.0.50; Refine an unified diff hunk only if adds lines Date: Thu, 12 Jan 2017 23:50:40 -0500 Message-ID: <87inpjzhpb.fsf@users.sourceforge.net> References: <8737grz0q3.fsf@gmail.com> <8737gr0zbn.fsf@users.sourceforge.net> <87fukqe2eu.fsf@gmail.com> <8760lmqak1.fsf@gmail.com> <87wpe0zz0s.fsf@users.sourceforge.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1484283026 10719 195.159.176.226 (13 Jan 2017 04:50:26 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 13 Jan 2017 04:50:26 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) Cc: 25410@debbugs.gnu.org To: Tino Calancha Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Jan 13 05:50:21 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cRtoY-0001Ak-Mp for geb-bug-gnu-emacs@m.gmane.org; Fri, 13 Jan 2017 05:50:10 +0100 Original-Received: from localhost ([::1]:39049 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cRtob-0001qv-GK for geb-bug-gnu-emacs@m.gmane.org; Thu, 12 Jan 2017 23:50:13 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36889) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cRtoT-0001ob-QG for bug-gnu-emacs@gnu.org; Thu, 12 Jan 2017 23:50:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cRtoQ-0005MC-L4 for bug-gnu-emacs@gnu.org; Thu, 12 Jan 2017 23:50:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:36587) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cRtoQ-0005Lz-Ee for bug-gnu-emacs@gnu.org; Thu, 12 Jan 2017 23:50:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cRtoP-0000QY-O4 for bug-gnu-emacs@gnu.org; Thu, 12 Jan 2017 23:50:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: npostavs@users.sourceforge.net Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 13 Jan 2017 04:50:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 25410 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 25410-submit@debbugs.gnu.org id=B25410.14842829841615 (code B ref 25410); Fri, 13 Jan 2017 04:50:01 +0000 Original-Received: (at 25410) by debbugs.gnu.org; 13 Jan 2017 04:49:44 +0000 Original-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 Original-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 Original-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) Original-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) In-Reply-To: (Tino Calancha's message of "Thu, 12 Jan 2017 14:32:02 +0900 (JST)") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:128052 Archived-At: --=-=-= 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 --=-=-=--