From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#52349: 29.0.50; vc-git and diff-mode: stage hunks Date: Mon, 19 Sep 2022 05:09:19 +0300 Message-ID: <78b1100c-89a6-5daf-548f-778807105307@yandex.ru> 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> <86mtb4tpz6.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9874"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Cc: 52349@debbugs.gnu.org, Sean Whitton To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Sep 19 04:10:14 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 1oa6Ef-0002Pq-K1 for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 19 Sep 2022 04:10:13 +0200 Original-Received: from localhost ([::1]:36902 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oa6Ee-0000XQ-4A for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 18 Sep 2022 22:10:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37078) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oa6EU-0000X2-UC for bug-gnu-emacs@gnu.org; Sun, 18 Sep 2022 22:10:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:52554) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oa6EU-0002MW-LD for bug-gnu-emacs@gnu.org; Sun, 18 Sep 2022 22:10:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oa6EU-0004QB-H3 for bug-gnu-emacs@gnu.org; Sun, 18 Sep 2022 22:10:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 19 Sep 2022 02:10: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.166355337016942 (code B ref 52349); Mon, 19 Sep 2022 02:10:02 +0000 Original-Received: (at 52349) by debbugs.gnu.org; 19 Sep 2022 02:09:30 +0000 Original-Received: from localhost ([127.0.0.1]:51632 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oa6Dy-0004PC-0U for submit@debbugs.gnu.org; Sun, 18 Sep 2022 22:09:30 -0400 Original-Received: from mail-wr1-f53.google.com ([209.85.221.53]:44725) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oa6Dv-0004Ow-Ne for 52349@debbugs.gnu.org; Sun, 18 Sep 2022 22:09:28 -0400 Original-Received: by mail-wr1-f53.google.com with SMTP id c11so45246526wrp.11 for <52349@debbugs.gnu.org>; Sun, 18 Sep 2022 19:09:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:from:to:cc:subject:date; bh=Cee0RL3te3uTvvaQP4Oj5TwGZKRZ0BOzp8Q8cSurzfk=; b=Sjf4fAUOc9yE5G6QnKPPzeFTCDd8/SRwiWOmQJPBflVDtiLvR1NVu3GT9ymE82ZGMp yk+g5pM8NQt3HBS+c8SoIwoZ8DOQn3Ql4UzraKl/U1u/iGQxCoTQGmFEjT4fedXdhtbK IJTXwAtzqu/06dcNcaj9agPBHNGA9GB0sBgMJvwwNZhEwseuKTNzjPaDr/bC2js+ncYw YH9B1Zriv8pHVM7UMkmolpqr78C655um89m7d0CqEoxHz0SLU2T/REbn/6xrf+Uu9HaE gU3TDe3XpVBuCUQpQ8p5dW5DWSriCOEysEn9yjWrJz0pjBu9he8a2fKzUxqtkBO8Tj6M OEig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:x-gm-message-state:from:to:cc:subject:date; bh=Cee0RL3te3uTvvaQP4Oj5TwGZKRZ0BOzp8Q8cSurzfk=; b=ciAsfQz1o6zBgUrwVBh0ImgCqGl7i8RBwMtI19Ie5D+3zDJMZ29RE33fjIsTDC7ASo VhrNdQFjZnoEfE/nrboKXKY4lvwJ74Coc+DKK2IwvthAfFEhSvXIPg9MH6m7D5z9z7/v 18PFB3kJK+bisf3CDkwTLusarJ/3JiSIOcvzRlUnCE54CvWlyqlwkh+Ird/4wZS5AV+h laolj/uPnlbI0Fg/EObE5VJDpbX900mdxKCH462hIo4lACH46tIZllfHmIrr1JXUqH7v 5DDlFgdK6koOKKCQfvPJN2Rrx5x2ydt718bQkU/8jOndTmZFGxyy3aNinJgsc7l0PP+w 48ng== X-Gm-Message-State: ACrzQf3EyiI528YJZo5dEf1IPf+8UYZIvSx37gt0yuTXxXe1vJoHoXbA 7lKemxZBC+qKxOf0W5fqlOs= X-Google-Smtp-Source: AMsMyM7uadY/ZCtBKET6gxBTZ2ygWZBCTdgyIMofzwWSk+8GjyNUn2xoeIc/8gxvvNrP5wR4KNcr4A== X-Received: by 2002:a5d:4ecd:0:b0:22a:42ec:8d74 with SMTP id s13-20020a5d4ecd000000b0022a42ec8d74mr9722827wrv.359.1663553361625; Sun, 18 Sep 2022 19:09:21 -0700 (PDT) Original-Received: from [192.168.0.6] ([46.251.119.176]) by smtp.googlemail.com with ESMTPSA id j13-20020adfff8d000000b0022ae59d472esm7107887wrr.112.2022.09.18.19.09.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 18 Sep 2022 19:09:21 -0700 (PDT) Content-Language: en-US In-Reply-To: <86mtb4tpz6.fsf@mail.linkov.net> 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:243025 Archived-At: On 12.09.2022 21:19, Juri Linkov wrote: >>> + (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. Right, sorry, I see it now. Do you know if Git use a stable ordering for files? 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. 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. >> 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.