From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ashwin Kafle Newsgroups: gmane.emacs.bugs Subject: bug#52508: [PATCH] Option for vc-delete-file to keep file on disk Date: Wed, 15 Dec 2021 18:07:27 +0000 Message-ID: <854k79spwg.fsf@airmail.cc> References: <85bl1igo9d.fsf@ashwink.com.np> <83sfuuhs5l.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22928"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: Ashwin Kafle , 52508@debbugs.gnu.org, dgutov@yandex.ru To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Dec 15 19:52:28 2021 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 1mxZO7-0005mo-Ny for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 15 Dec 2021 19:52:27 +0100 Original-Received: from localhost ([::1]:35566 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mxZO6-0007dR-Ey for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 15 Dec 2021 13:52:26 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:52834) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mxYgA-0005ns-5x for bug-gnu-emacs@gnu.org; Wed, 15 Dec 2021 13:07:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:50331) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mxYg9-0008Lm-PO for bug-gnu-emacs@gnu.org; Wed, 15 Dec 2021 13:07:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mxYg9-0004xs-LT for bug-gnu-emacs@gnu.org; Wed, 15 Dec 2021 13:07:01 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: <85bl1igo9d.fsf@ashwink.com.np> Resent-From: Ashwin Kafle Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 15 Dec 2021 18:07:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 52508 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 52508-submit@debbugs.gnu.org id=B52508.163959159819053 (code B ref 52508); Wed, 15 Dec 2021 18:07:01 +0000 Original-Received: (at 52508) by debbugs.gnu.org; 15 Dec 2021 18:06:38 +0000 Original-Received: from localhost ([127.0.0.1]:33644 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mxYfl-0004xF-U8 for submit@debbugs.gnu.org; Wed, 15 Dec 2021 13:06:38 -0500 Original-Received: from forward103j.mail.yandex.net ([5.45.198.246]:43546) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mxYfj-0004x0-J9 for 52508@debbugs.gnu.org; Wed, 15 Dec 2021 13:06:36 -0500 Original-Received: from iva8-1a0d05019375.qloud-c.yandex.net (iva8-1a0d05019375.qloud-c.yandex.net [IPv6:2a02:6b8:c0c:108e:0:640:1a0d:501]) by forward103j.mail.yandex.net (Yandex) with ESMTP id C4C64100F43; Wed, 15 Dec 2021 21:06:28 +0300 (MSK) Original-Received: from iva8-a4a480c9f089.qloud-c.yandex.net (iva8-a4a480c9f089.qloud-c.yandex.net [2a02:6b8:c0c:da5:0:640:a4a4:80c9]) by iva8-1a0d05019375.qloud-c.yandex.net (mxback/Yandex) with ESMTP id FsWaipvJSX-6SeKWiu2; Wed, 15 Dec 2021 21:06:28 +0300 Authentication-Results: iva8-1a0d05019375.qloud-c.yandex.net; dkim=pass Original-Received: by iva8-a4a480c9f089.qloud-c.yandex.net (smtp/Yandex) with ESMTPSA id uIOjOUXCiQ-6RPOIu8X; Wed, 15 Dec 2021 21:06:27 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) X-Yandex-Fwd: 2 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:222431 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: [...] >> I've created the attached patch to have vc-delete file to keep files on >> disk using a prefix argument. I've only tested it for vc-git. > > Thanks, sounds useful. > > A few minor comments below, mainly to the documentation parts: [...] Thanks, now fixed and attached. > >> - (let ((backup-inhibited nil)) >> + (let ((backup-inhibited nil) >> + ;; if you don't set this, then for some reason, the file is never >> brought back >> + (backup-by-copying t)) > > Wouldn't it be better to understand why this mystery happens? Yeah, a backup function should bring back the original file. That is indeed weird. But I can't read much elisp yet to be of help in here. In this case, backup-by-copying seems to be the better method for backups since the intention is to not touch the original files at all. Reading the docstring of backup-buffer, backup-by-rename doesn't look fit for this use case. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Option-for-vc-delete-file-to-keep-file-on-disk.patch >From b8e5b8463f15a53e5fb6ddac5447005d4133606b Mon Sep 17 00:00:00 2001 From: Ashwin Kafle Date: Wed, 15 Dec 2021 23:49:47 +0545 Subject: [PATCH] Option for vc-delete-file to keep file on disk Add a prefix argument on vc-delete-file to keep affected file on disk and keep the current buffer intact. This option relies on the backends to not delete files themselves. * doc/emacs/vc1-xtra.texi: Document the change. * lisp/vc/vc-git.el (vc-git-delete-file): Make git leave files on disk. * lisp/vc/vc.el (vc-delete-file): Change vc-delete-file to accept optional prefix argument. --- doc/emacs/vc1-xtra.texi | 3 ++- etc/NEWS | 4 ++++ lisp/vc/vc-git.el | 4 ++-- lisp/vc/vc.el | 18 ++++++++++++------ 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/doc/emacs/vc1-xtra.texi b/doc/emacs/vc1-xtra.texi index 4cd00cba6c..99e5eef7c1 100644 --- a/doc/emacs/vc1-xtra.texi +++ b/doc/emacs/vc1-xtra.texi @@ -122,7 +122,8 @@ VC Delete/Rename If you wish to delete a version-controlled file, use the command @kbd{M-x vc-delete-file}. This prompts for the file name, and deletes it via the version control system. The file is removed from the -working tree, and in the VC Directory buffer +working tree, and in the VC Directory buffer. If you give a prefix argument, +the file is not deleted from disk. @iftex (@pxref{VC Directory Mode,,, emacs, the Emacs Manual}), @end iftex diff --git a/etc/NEWS b/etc/NEWS index 8d83b2a7e3..af358aaedb 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -372,6 +372,10 @@ info node. This command only works for the Emacs and Emacs Lisp manuals. ** vc +*** 'C-x v x' accepts a prefix argument to keep file on disk. +Previously 'C-x v x' always deleted the selected file. Now if you give it +prefix argument, it will keep the buffer and file on disk intact. +Currently this is only implemented for vc-git. --- *** 'C-x v v' on an unregistered file will now use the most specific backend. Previously, if you had an SVN-covered "~/" directory, and a Git-covered diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index 5c6a39aec9..69ef216529 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -1569,8 +1569,8 @@ vc-git-next-revision (or (vc-git-symbolic-commit next-rev) next-rev))) (defun vc-git-delete-file (file) - (vc-git-command nil 0 (vc-git--literal-pathspec file) "rm" "-f" "--")) - + (vc-git-command nil 0 (vc-git--literal-pathspec file) "rm" "-f" "--cached" "--")) +) (defun vc-git-rename-file (old new) (vc-git-command nil 0 (list old new) "mv" "-f" "--")) diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index 64f752f248..a4d390fea8 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -2970,14 +2970,17 @@ vc-transfer-file (vc-checkin file new-backend comment (stringp comment))))) ;;;###autoload -(defun vc-delete-file (file) +(defun vc-delete-file (file &optional keep-file) "Delete file and mark it as such in the version control system. If called interactively, read FILE, defaulting to the current -buffer's file name if it's under version control." +buffer's file name if it's under version control. +If a prefix argument is given (optional argument KEEP-FILE) then +don't delete the file from the disk." (interactive (list (read-file-name "VC delete file: " nil (when (vc-backend buffer-file-name) buffer-file-name) - t))) + t) + current-prefix-arg)) (setq file (expand-file-name file)) (let ((buf (get-file-buffer file)) (backend (vc-backend file))) @@ -2999,19 +3002,22 @@ vc-delete-file (unless (or (file-directory-p file) (null make-backup-files) (not (file-exists-p file))) (with-current-buffer (or buf (find-file-noselect file)) - (let ((backup-inhibited nil)) + (let ((backup-inhibited nil) + ;; If you don't set this, then for some reason, the file is never brought back. + (backup-by-copying t)) (backup-buffer)))) ;; Bind `default-directory' so that the command that the backend ;; runs to remove the file is invoked in the correct context. (let ((default-directory (file-name-directory file))) (vc-call-backend backend 'delete-file file)) ;; If the backend hasn't deleted the file itself, let's do it for him. - (when (file-exists-p file) (delete-file file)) + (when (and (file-exists-p file) (null keep-file)) + (delete-file file)) ;; Forget what VC knew about the file. (vc-file-clearprops file) ;; Make sure the buffer is deleted and the *vc-dir* buffers are ;; updated after this. - (vc-resynch-buffer file nil t))) + (vc-resynch-buffer file keep-file t))) ;;;###autoload (defun vc-rename-file (old new) -- 2.34.1 --=-=-=--