From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#52349: 29.0.50; vc-git and diff-mode: stage hunks Date: Mon, 19 Sep 2022 09:50:18 +0300 Organization: LINKOV.NET Message-ID: <86leqf6bwl.fsf@mail.linkov.net> References: <268cee0d-465d-b862-d1d6-f5da4d69e737@inventati.org> <864k7kfd56.fsf@mail.linkov.net> <86fsr3uen2.fsf@mail.linkov.net> <95d2d999-49ad-13c4-9f25-0935650a1e42@yandex.ru> <8635ktjfll.fsf@mail.linkov.net> <36b963e4-5af7-dd9e-af92-4404541b9f4d@yandex.ru> <86v8xjx45h.fsf@mail.linkov.net> <861qt9h1hh.fsf@mail.linkov.net> <864jy1mrk8.fsf@mail.linkov.net> <86fsh1ll5y.fsf@mail.linkov.net> <87edwlo52t.fsf@melete.silentflame.com> <868rmqypjz.fsf@mail.linkov.net> <70b6d879-ea34-a473-aa27-7fc7b72fd7d0@yandex.ru> <86mtb4tpz6.fsf@mail.linkov.net> <78b1100c-89a6-5daf-548f-778807105307@yandex.ru> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9599"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu) Cc: 52349@debbugs.gnu.org, Sean Whitton To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Sep 19 10:28:17 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oaC8X-0002DA-Qz for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 19 Sep 2022 10:28:17 +0200 Original-Received: from localhost ([::1]:54338 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oaC8W-0004uP-QH for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 19 Sep 2022 04:28:16 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39910) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oaBbO-0006ZF-FI for bug-gnu-emacs@gnu.org; Mon, 19 Sep 2022 03:54:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:53119) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oaBbO-0004oI-5w for bug-gnu-emacs@gnu.org; Mon, 19 Sep 2022 03:54:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oaBbN-0007XW-UF for bug-gnu-emacs@gnu.org; Mon, 19 Sep 2022 03:54:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 19 Sep 2022 07:54:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 52349 X-GNU-PR-Package: emacs Original-Received: via spool by 52349-submit@debbugs.gnu.org id=B52349.166357402828963 (code B ref 52349); Mon, 19 Sep 2022 07:54:01 +0000 Original-Received: (at 52349) by debbugs.gnu.org; 19 Sep 2022 07:53:48 +0000 Original-Received: from localhost ([127.0.0.1]:52197 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oaBb9-0007X4-Lu for submit@debbugs.gnu.org; Mon, 19 Sep 2022 03:53:47 -0400 Original-Received: from relay6-d.mail.gandi.net ([217.70.183.198]:59099) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oaBb5-0007Wc-Uq for 52349@debbugs.gnu.org; Mon, 19 Sep 2022 03:53:45 -0400 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id A2664C0002; Mon, 19 Sep 2022 07:53:35 +0000 (UTC) In-Reply-To: <78b1100c-89a6-5daf-548f-778807105307@yandex.ru> (Dmitry Gutov's message of "Mon, 19 Sep 2022 05:09:19 +0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:243045 Archived-At: > Do you know if Git use a stable ordering for files? It seems the ordering is stable unless it's changed explicitly by command line options. > If not, here's where the proposed implementation might fail: > > Suppose we have the staging area with contents > > a/bar b/bar > +bbb > a/foo b/foo > +aaa > +ccc > > and the diff to check in with contents > > a/foo b/foo > +aaa > a/bar b/bar > +bbb > +ccc > > ...then the check will succeed, I think. This check is intended to detect only added/deleted files that get into the staging area. > Even if Git always sorts them the same, I suppose an externally-produced > diff could trigger this scenario. It should be a pretty rare case, though, > so it's probably fine. > > A tweak like the following could fix it, though: instead of replacing the > chunks with "", maybe keep the file headers. Then the remaining contents > for the same file in vc-git-patch-string wouldn't be able to stick to the > previous file's chunks. This looks too complicated. And indeed, this is a rare case, so maybe something like this could be added when this will became a real problem. >>> Perhaps if we called diff-file-next in addition to (move-beginning-of-line >>> 1)? >> diff-file-next doesn't work: it stops in the middle of the diff file >> header. >> Therefore the patch navigates git diff file headers explicitly. >> >>> But we need to save both strings: and ensure that if there is a match >>> for that file header, then all hunks are contained in the patch as well >>> (and nothing extra, for that file). >> This is implemented by the patch. Maybe it could help you to see how it >> works >> by running it under debugger and stepping through it. >> >>> It's complex logic, so if you manage to write a test as well, that would be >>> excellent. >> A test could written when someone will create infrastructure for testing >> git commands with helpers to create a git repository and checking its content. > > test/lisp/vc/vc-tests.el actually contains a helper like this. > > Every scenario starts with calling vc-test--create-repo-function, and there > are tests for 'version-diff' at the very end of the file. It's somewhat > convoluted, so I don't blame you for missing it. Actually, I looked into test/lisp/vc/vc-git-tests.el that is almost empty. I expected that since this check is git-specific, it should be in vc-git-tests.el.