From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#62731: 29.0.60; diff-apply-hunk doesn't work for creating new files Date: Wed, 02 Oct 2024 09:58:53 +0300 Message-ID: <86ldz70z4i.fsf@gnu.org> References: <87jzyln9g0.fsf@catern.com> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16761"; mail-complaints-to="usenet@ciao.gmane.io" Cc: sbaugh@catern.com, 62731@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Oct 02 09:00:16 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 1svtLM-0004DQ-9s for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 02 Oct 2024 09:00:16 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1svtLE-0003Sk-SS; Wed, 02 Oct 2024 03:00: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 1svtL8-0003Pr-FF for bug-gnu-emacs@gnu.org; Wed, 02 Oct 2024 03:00:03 -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 1svtL8-0003k2-2R for bug-gnu-emacs@gnu.org; Wed, 02 Oct 2024 03:00:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=References:In-Reply-To:From:Date:To:Subject; bh=GIZMb6nXv8uyqoFaq7Qrdyr8C3AFnFfrwH/ML5FTJgE=; b=YWBlAO4eYFhl1WOHFFcIOTarpdV+bR2c+pxiCur7JH19CqH2boNuLdiSKY97ihrJGgs7pEcDBbawa5XcdDrZG+SfPAAWj34ghCaiiWD5Bpv24frA69dzDwl1zktSw+H9clYsEGBwvf0GOHOx8Kl0EPNkC/7Ic6sRY6XzL4dFJsufEG/zBlEOnemnOYPjK1+ctAi78TCYihneOLjrd8iwD+DBj+YUEkwuQC0s2rzZnfMhItDZ9dmH/MKI7RZvw3wGWrlrP17B5w7G/A95Http71/ebuIVV3jb11APC8l56iH+s13B4CtDcCG4QqMasV5464SA6UTk+ELMkVTLud0fjg==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1svtL8-0004OJ-49 for bug-gnu-emacs@gnu.org; Wed, 02 Oct 2024 03:00:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 02 Oct 2024 07:00:02 +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.172785234316776 (code B ref 62731); Wed, 02 Oct 2024 07:00:02 +0000 Original-Received: (at 62731) by debbugs.gnu.org; 2 Oct 2024 06:59:03 +0000 Original-Received: from localhost ([127.0.0.1]:56411 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1svtKB-0004MV-6C for submit@debbugs.gnu.org; Wed, 02 Oct 2024 02:59:03 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:53574) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1svtK9-0004M0-AL for 62731@debbugs.gnu.org; Wed, 02 Oct 2024 02:59:01 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1svtK3-0003fr-Mb; Wed, 02 Oct 2024 02:58:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=GIZMb6nXv8uyqoFaq7Qrdyr8C3AFnFfrwH/ML5FTJgE=; b=eQidQjjb7T3J ZoyTxb+ZYAQXVMJgk4Dv2aQpvBsdyMeK5FVzlLRhS+prnsz3sPHYcjkAtzxVrRfMjSfaiZDv9e5w2 Di4OMFZCkTTLomrBc604tTwgNX8qdebMqpOE62HvYMDEnENAePR+q3F6tynKWuUHliV4UT3L/aE9o Eq9nq2nkUXQKGDV4Ej/myHco0hl6KYeeXvjJzvMFKnjPT4H90YCiWTi0RjfB15yPXrTmNEXCek9f2 W564/hHyYbTfh10U4iucVF8qsx5rrCUY5oyRTwbJS+jnt30Bhgkowl+0rIvpMgLl0idhUQOttsU9r m4R+eDBPwk45cjyuAORK9A==; In-Reply-To: (message from Dmitry Gutov on Wed, 2 Oct 2024 03:41:05 +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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:292822 Archived-At: > 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?) 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? (And if this also happens with Hg, include that in the test as well.) Also, what about the opposite case, when NEW is /dev/null? does that work correctly? Thanks.