From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Konstantin Kharlamov Newsgroups: gmane.emacs.bugs Subject: bug#37395: [PATCH] diff-mode.el: take into account patch separators Date: Mon, 16 Sep 2019 23:31:10 +0300 Message-ID: <1568665870.19637.0@yandex.ru> References: <1568323985.28657.0@yandex.ru> <20190912213445.16304-1-Hi-Angel@yandex.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=koi8-r; format=flowed Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="250657"; mail-complaints-to="usenet@blaine.gmane.org" Cc: 37395@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Sep 16 22:32:29 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1i9xfh-0012yJ-7L for geb-bug-gnu-emacs@m.gmane.org; Mon, 16 Sep 2019 22:32:29 +0200 Original-Received: from localhost ([::1]:39828 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i9xfg-0003q1-6K for geb-bug-gnu-emacs@m.gmane.org; Mon, 16 Sep 2019 16:32:28 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53142) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i9xfI-0003ph-97 for bug-gnu-emacs@gnu.org; Mon, 16 Sep 2019 16:32:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i9xfH-0001SV-0i for bug-gnu-emacs@gnu.org; Mon, 16 Sep 2019 16:32:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:42322) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i9xfG-0001SN-UJ for bug-gnu-emacs@gnu.org; Mon, 16 Sep 2019 16:32:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1i9xfG-0008Qj-Ov for bug-gnu-emacs@gnu.org; Mon, 16 Sep 2019 16:32:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Konstantin Kharlamov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 16 Sep 2019 20:32:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 37395 X-GNU-PR-Package: emacs Original-Received: via spool by 37395-submit@debbugs.gnu.org id=B37395.156866588230265 (code B ref 37395); Mon, 16 Sep 2019 20:32:02 +0000 Original-Received: (at 37395) by debbugs.gnu.org; 16 Sep 2019 20:31:22 +0000 Original-Received: from localhost ([127.0.0.1]:51143 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1i9xeb-0007rd-L9 for submit@debbugs.gnu.org; Mon, 16 Sep 2019 16:31:22 -0400 Original-Received: from forward104o.mail.yandex.net ([37.140.190.179]:32893) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1i9xeY-0007jb-IW for 37395@debbugs.gnu.org; Mon, 16 Sep 2019 16:31:19 -0400 Original-Received: from mxback27o.mail.yandex.net (mxback27o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::78]) by forward104o.mail.yandex.net (Yandex) with ESMTP id 0B3219406D5; Mon, 16 Sep 2019 23:31:12 +0300 (MSK) Original-Received: from iva4-994a9845f60e.qloud-c.yandex.net (iva4-994a9845f60e.qloud-c.yandex.net [2a02:6b8:c0c:152e:0:640:994a:9845]) by mxback27o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id J04yHk4s5K-VBIaOfa4; Mon, 16 Sep 2019 23:31:12 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1568665872; bh=9LF4/XjjvmxITVruj+k16/3nvjZ17mvlm3buMYxV3vA=; h=In-Reply-To:Cc:To:Subject:From:References:Date:Message-Id; b=kHntFE9xicIOylfAPKT3nTTkGDq55bkpugi2ZivZFH6/DbVXK5sfD8CDH4Pk5jOyD QE3zNbBIOqPC89h+Jf3FfBGJDLIDysgp/CHyBfqN3W5feG+E3RYDc9HO0bGiTfYIlE 92JdTynpO597jcju5XhChGMZ286Kn5CY/86tiCvw= Authentication-Results: mxback27o.mail.yandex.net; dkim=pass header.i=@yandex.ru Original-Received: by iva4-994a9845f60e.qloud-c.yandex.net (nwsmtp/Yandex) with ESMTPSA id HbLLW4CwpP-VAHqJnUc; Mon, 16 Sep 2019 23:31:11 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) In-Reply-To: <1568357907.5095.0@yandex.ru> X-Mailer: geary/3.33.90 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: 209.51.188.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:166583 Archived-At: On =F0=D4, =D3=C5=CE 13, 2019 at 09:58, Konstantin Kharlamov=20 wrote: >=20 >=20 > On =F0=D4, =D3=C5=CE 13, 2019 at 09:14, Eli Zaretskii wrot= e: >>> From: Konstantin Kharlamov >>> Date: Fri, 13 Sep 2019 00:34:45 +0300 >>>=20 >>> * lisp/vc/diff-mode.el (diff-goto-line-before-patch-separator): an >>> inline function to check if prev. line was git-format-patch=20 >>> =7F=7Fseparator, >>> in which case go there. >>> (diff-end-of-hunk): make use of=20 >>> =7F=7F(diff-goto-line-before-patch-separator) >>=20 >> The descriptions of changes should start with a capital letter. =20 >> Also, >> your lines in the commit log message are too long, they should not >> exceed 61 characters (because in the release tarball we create a >> ChangeLog file from them, which prepends a TAB character to each >> line). >>=20 >>> +(defsubst diff-goto-line-before-patch-separator () >>> + "Go to prev. line, then if it has patch separator as produced >>> +by git-format-patch, stay there. Otherwise go back." >>=20 >> The first line of a doc string should be a complete sentence. I >> suggest to rephrase as follows: >>=20 >> Return buffer position before patch separator produced by=20 >> =7Fgit-format-patch. >=20 > Thank you, I'll address the comments a bit later this day! >=20 >>> + (previous-line) >>> + (when (not (looking-at "-- ")) >>> + (next-line)) >>> + (point)) >>=20 >> Btw, Diff mode is more general than just Git-produced diffs. Is=20 >> there >> any possibility that this change will misfire in diffs produced by >> other tools? If so, perhaps we should also verify the buffer is=20 >> under >> Git control. >=20 > Oh, while writing this, I figured I should change the regexp from `--=20 > ` to `^-- $`. Will do. >=20 > With that addressed: very unlikely. A miscalculation could happen if=20 > all of the following holds true *simultaneously*: >=20 > * The diff removes a line with the exact text `- `, i.e. two=20 > characters {dash,space}. That would result in {dash,dash,space} diff,=20 > same as patch separator. > * The line was the last line removed in the hunk. > * The hunk has no context after the removed line >=20 > Note, these need to hold true simultaneously. Give the low=20 > probability of this compared to git-format-patch that is used=20 > literally everywhere (and that without this patch diff-mode can't=20 > handle it), I think this is a reasonable trade-off. While still on it: I figured I could detect whether diff has git-diff=20 format by searching the `diff --git` text that seems to be always=20 present when starting diff-mode, and only then try to find the=20 patch-separator. Done. I'm not sure if the `setq-local foo` and then=20 modification of the `foo` in `(define-derived-mode)` is the preferred=20 way to do this, but otherwise it seems to be fine, and worked in my=20 tests. =