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, 12 Sep 2022 21:19:41 +0300 Organization: LINKOV.NET Message-ID: <86mtb4tpz6.fsf@mail.linkov.net> References: <268cee0d-465d-b862-d1d6-f5da4d69e737@inventati.org> <9106387a-98cf-396f-bf45-ccb04581787b@yandex.ru> <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> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9145"; 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 12 20:22:34 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 1oXo4l-0002AN-N4 for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 12 Sep 2022 20:22:31 +0200 Original-Received: from localhost ([::1]:56742 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oXo4k-0007oi-EA for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 12 Sep 2022 14:22:30 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35026) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oXo4J-0007nR-7z for bug-gnu-emacs@gnu.org; Mon, 12 Sep 2022 14:22:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:59128) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oXo4I-0006VZ-GD for bug-gnu-emacs@gnu.org; Mon, 12 Sep 2022 14:22:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oXo4I-0006zk-C5 for bug-gnu-emacs@gnu.org; Mon, 12 Sep 2022 14:22:02 -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, 12 Sep 2022 18:22:02 +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.166300687226785 (code B ref 52349); Mon, 12 Sep 2022 18:22:02 +0000 Original-Received: (at 52349) by debbugs.gnu.org; 12 Sep 2022 18:21:12 +0000 Original-Received: from localhost ([127.0.0.1]:47816 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oXo3U-0006xw-8j for submit@debbugs.gnu.org; Mon, 12 Sep 2022 14:21:12 -0400 Original-Received: from relay12.mail.gandi.net ([217.70.178.232]:35649) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oXo3S-0006xh-No for 52349@debbugs.gnu.org; Mon, 12 Sep 2022 14:21:11 -0400 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id 3E9B1200008; Mon, 12 Sep 2022 18:21:02 +0000 (UTC) In-Reply-To: <70b6d879-ea34-a473-aa27-7fc7b72fd7d0@yandex.ru> (Dmitry Gutov's message of "Mon, 12 Sep 2022 00:57:47 +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:242294 Archived-At: >> + (if (string-search file-diff vc-git-patch-string) >> + (setq vc-git-patch-string >> + (string-replace file-diff "" vc-git-patch-string)) > > Not sure I understand this part. We're replacing some text (the diff file > header) with empty text in the patch string? But not the whole hunk? Actually it replaces the whole new/deleted file differences. > It might work if we removed the whole hunk as well, but we need to make > sure that the staged contents for that file are exactly the same as what is > contained for that file in vc-git-patch-string. This is exactly what this patch does. > 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.