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#62731: 29.0.60; diff-apply-hunk doesn't work for creating new files Date: Wed, 2 Oct 2024 21:57:48 +0300 Message-ID: <36712130-53f5-4515-a887-d8df3175b271@gutov.dev> References: <87jzyln9g0.fsf@catern.com> <86ldz70z4i.fsf@gnu.org> 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="3995"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird Cc: sbaugh@catern.com, 62731@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Oct 02 20:59:42 2024 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 1sw4ZZ-0000tz-Q3 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 02 Oct 2024 20:59:42 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sw4Z2-0000d3-NY; Wed, 02 Oct 2024 14:59:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sw4Yv-0000cH-Gr for bug-gnu-emacs@gnu.org; Wed, 02 Oct 2024 14:59:01 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sw4Yv-0001gv-5e for bug-gnu-emacs@gnu.org; Wed, 02 Oct 2024 14:59:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=In-Reply-To:From:References:MIME-Version:Date:To:Subject; bh=dL4vzt7HuRLsZZusZurS/0FD9S2/SBj1HBJT/d9/BX8=; b=BaRJq2nnstzaZ83BHzWYGMxHI3MJeB3RfbHKFDi7g4IejQ7+WbigOdIzm0r0/h6rCYGVA858mZVoYGf2UKJAzn6EyhiNXzdOAO45KQswzGkCpnhsHM9TFOJ6ek5xfNxxRTF/+9Q0Ln6c8b9Ule/KL7hcqkPIOpLNQNUOdOpfyFli4X1wxFi+1hqQm+Q2DlvM3eIMMdTbYNZn7jzcGOtFKo3+LXiXs7n2Vir+dPVnZFepZ6oJ+1t+tSWcK2Va0iESoMtVzNfOA1rRZcg/WkxkMC7xb7T805DrCMjcDktfm4WM1fes54JAz1579tzFLwqaFU1cczXSGbrESgQuHSiD+g==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sw4Yv-0001xQ-T1 for bug-gnu-emacs@gnu.org; Wed, 02 Oct 2024 14:59:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 02 Oct 2024 18:59:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62731 X-GNU-PR-Package: emacs Original-Received: via spool by 62731-submit@debbugs.gnu.org id=B62731.17278954827420 (code B ref 62731); Wed, 02 Oct 2024 18:59:01 +0000 Original-Received: (at 62731) by debbugs.gnu.org; 2 Oct 2024 18:58:02 +0000 Original-Received: from localhost ([127.0.0.1]:59234 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sw4Xx-0001vR-Cb for submit@debbugs.gnu.org; Wed, 02 Oct 2024 14:58:01 -0400 Original-Received: from fhigh-a4-smtp.messagingengine.com ([103.168.172.155]:45891) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sw4Xv-0001v5-7l for 62731@debbugs.gnu.org; Wed, 02 Oct 2024 14:57:59 -0400 Original-Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfhigh.phl.internal (Postfix) with ESMTP id 4C78C11401A1; Wed, 2 Oct 2024 14:57:53 -0400 (EDT) Original-Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Wed, 02 Oct 2024 14:57:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gutov.dev; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1727895473; x=1727981873; bh=dL4vzt7HuRLsZZusZurS/0FD9S2/SBj1HBJT/d9/BX8=; b= YjBpfpLi/Y1YMrhyQH8BY4hF6Lh8XY2PjGe0YFCPkdCeQt+dw0wLkU7Y/F5FE0zN eW2AGH584rChbSkCA4B6u8EpOKFz/k8Koo4OQOyKzNBCi3pkaTHWT1muvbYrfzT3 GadjcCDFAOrxEV5hyUhNeM/kwGIyGVneh87YFicTz4nUadftwDxJar3x1ZRweTxb JmXPDHVPGC3+WMvdveEp3n1+tWH8gVTJ1EQJbJnWqdBzOxXmjzPl6BqcQp2T1Pfl fODjm5v9Quq+vcW1f5+m/rHLLmnMLZgGp0DR+LiKl1TG1+R4r7Y9vMJbGv25rOqN tVUanaiTafPwTzAvrUIgyw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1727895473; x= 1727981873; bh=dL4vzt7HuRLsZZusZurS/0FD9S2/SBj1HBJT/d9/BX8=; b=P xKD8Ont+bbSfKrgTBunlcXApHFFa7jf45n0xKbEF49WMvImRe4yA2gIo5pFGg5uf 7yCgxxO5ffo8CG5D+5ZSYX9iGg2K4PMHV928mlvtohhk2JbzhGvdeh6PJ5Ad15mb 9YlN5pX1FK1vr4/KTIPF+y9PhFyLj8M/LqhP/eg0930MPz1I7WOADLQZX8Ni1SI5 aH/gHKhYHn/h//zrEhRFyxM9vlkUs0Gu8uOyUkO8K75I30OgGneNlsga4zflCxwu c6W/0DTqeyeiG/X+neUb6x4DUwzEneTka8xYTYS/UcWeidXWXEdwH3YYN2O5k5jZ 0R0kkgfYQAXxdMmd1TK1Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdduledguddvkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefkffggfgfuvfevfhfhjggtgfesthejredttddv jeenucfhrhhomhepffhmihhtrhihucfiuhhtohhvuceoughmihhtrhihsehguhhtohhvrd guvghvqeenucggtffrrghtthgvrhhnpeeugeekieeftdekvdelueejfeekleehhffhlefh vefgteeijeetfeffvefhvddtgfenucffohhmrghinhepshhtrggtkhhovhgvrhhflhhofi drtghomhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhm pegumhhithhrhiesghhuthhovhdruggvvhdpnhgspghrtghpthhtohepfedpmhhouggvpe hsmhhtphhouhhtpdhrtghpthhtohepvghlihiisehgnhhurdhorhhgpdhrtghpthhtohep shgsrghughhhsegtrghtvghrnhdrtghomhdprhgtphhtthhopeeivdejfeduseguvggssg hughhsrdhgnhhurdhorhhg X-ME-Proxy: Feedback-ID: i07de48aa:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 2 Oct 2024 14:57:51 -0400 (EDT) Content-Language: en-US In-Reply-To: <86ldz70z4i.fsf@gnu.org> 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:292860 Archived-At: On 02/10/2024 09:58, Eli Zaretskii wrote: >> Date: Wed, 2 Oct 2024 03:41:05 +0300 >> From: Dmitry Gutov >> >>> Observed behavior: diff-mode prompts for the location of "b/foo", and >>> doesn't allow specifying the location as a non-existent file, meaning >>> the file can't actaully be created. >> >> This is annoying indeed. >> >> The attached patch should handle this: >> >> * When OLD equals to /dev/null, allow reading non-existing file name. >> * When NEW starts with b/ or /a, slice that off if such dir does not exist. >> * Bonus: when the diff is applied in reverse, the checked file names are >> switched. That helps undo deletions as well. Or renames. > > I think Git uses other prefixes as well (something like i/ and r/, > perhaps?) Interesting, I don't remember seeing 'i/' or 'r/' in use. OT2H, apparently the prefixes are configurable both through command line and Git config: https://stackoverflow.com/questions/6764953/what-is-the-reason-for-the-a-b-prefixes-of-git-diff I think that can mean two things: a/ and b/ could be different, and also - if a/ and b/ conflict with some dir, the repository could have settings to change the diff prefixes. Although not every user will know that, perhaps. > And relying on b/ being an existing directory can cause > false positives. How about relying on the "--git" part in the > "diff --git" header instead, and in the Git case _always_ removing one > leading directory? I guess that's an option too. > (And if this also happens with Hg, include that in > the test as well.) With Hg, the format look like this: diff -r df0ef194120b -r 2039b18843da accessible/aom/AccessibleNode.cpp No mention of 'Hg', that is. Could we match "\`diff -r" and And I suppose this is theoretically a problem for most VC backends, although of we only support Git and Hg, it might be fine. That piece of code only affect the default file name input anyway. -r is a real 'diff' option, by the way. When I try it, here's how the header looks: diff '--color=auto' -u -r emacs/aclocal.m4 emacs-master/aclocal.m4 --- emacs/aclocal.m4 2024-08-19 04:06:06.237502671 +0300 +++ emacs-master/aclocal.m4 2024-09-14 05:42:16.907845058 +0300 > Also, what about the opposite case, when NEW is /dev/null? does that > work correctly? Not currently or with the proposed patch. It could be fixed along similar lines, but I'm not clear on the ideal behavior here. Delete the "old" file and kill its buffer? And say that with 'message'? This would differ from the regular diff-apply-hunk behavior in that nothing else might appear on screen if the buffer was not displayed, and if it was displayed - that would kill a visible buffer. Unusual for Emacs behavior either way. Deleting files is something that one can do manually, though, so solving this seems lower priority.