GNU bug report logs - #52508
[PATCH] Option for vc-delete-file to keep file on disk

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Ashwin Kafle <ashwin@HIDDEN>; Keywords: patch; merged with #52507; dated Wed, 15 Dec 2021 12:56:03 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.
Forcibly Merged 52507 52508. Request was from Juri Linkov <juri@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at 52508 <at> debbugs.gnu.org:


Received: (at 52508) by debbugs.gnu.org; 15 Dec 2021 14:14:42 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Dec 15 09:14:42 2021
Received: from localhost ([127.0.0.1]:60594 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1mxV3J-0002cu-JU
	for submit <at> debbugs.gnu.org; Wed, 15 Dec 2021 09:14:41 -0500
Received: from eggs.gnu.org ([209.51.188.92]:46336)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1mxV3I-0002cg-GZ
 for 52508 <at> debbugs.gnu.org; Wed, 15 Dec 2021 09:14:40 -0500
Received: from [2001:470:142:3::e] (port=50660 helo=fencepost.gnu.org)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1mxV3C-0000CC-SC; Wed, 15 Dec 2021 09:14:34 -0500
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=xyGxYEMk9OcuDY810qFs+s5ulhZYrPNVAjYaTGlcCDw=; b=IKNv2p5lbMOe
 t3PDBJqOX+/kQ7m9hp30knMen/z4sNUaebbwRw1xAm8/fg8q5gm+VPGkshgcF/j55GaRyN7K+LH6s
 HhKNpqolo9WqK6wO2oAaWJUot2JYhm0ccme3L9orxVoZFaG4AY7jEPblW294PuUhQ7MaesI/i5MTM
 1JuSseovMK6eDa67DLlXP+fxwqrHhpsfCa7SnKOXB2vDyp9jy81SIbqdvZMD2fZtkxGGimsF784x1
 KFfN/+erMnYgGZMW2blqpFGngt56DyCg717ERNXHaNqVkIfjx/91BSrXGvJdpuePHQ46+vRJFDCph
 pGdaYQBxAeWw8JH46ZMhyQ==;
Received: from [87.69.77.57] (port=4989 helo=home-c4e4a596f7)
 by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1mxV3C-0005L2-Mw; Wed, 15 Dec 2021 09:14:35 -0500
Date: Wed, 15 Dec 2021 16:14:14 +0200
Message-Id: <83sfuuhs5l.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Ashwin Kafle <ashwin@HIDDEN>
In-Reply-To: <85bl1igo9d.fsf@HIDDEN> (message from Ashwin Kafle on
 Wed, 15 Dec 2021 10:23:42 +0000)
Subject: Re: bug#52508: [PATCH] Option for vc-delete-file to keep file on disk
References: <85bl1igo9d.fsf@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 52508
Cc: 52508 <at> debbugs.gnu.org, dgutov@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Ashwin Kafle <ashwin@HIDDEN>
> Date: Wed, 15 Dec 2021 10:23:42 +0000
> Cc: Ashwin Kafle <ashwin@HIDDEN>, Dmitry Gutov <dgutov@HIDDEN>
> 
> 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:

> * doc/emacs/vc1-xtra.texi: Document the change.
> * lisp/vc/vc-git.el: Make git leave files on disk.
> * lisp/vc/vc.el: Change vc-delete-file to accept optional prefix argument.

Our conventions are to use the ChangeLog style of these entries, which
means they should state the function names where the changes are made,
not just the file names.

> --- 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,
                                               ^^
We leave 2 spaces between sentences, per US English conventions.

> +*** 'C-x v x' accepts a prefix argument to keep file on disk

Period at the end of the heading, please.

> +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.

Two spaces between sentences.

> -(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."
> -  (interactive (list (read-file-name "VC delete file: " nil
> -                                     (when (vc-backend buffer-file-name)
> -                                       buffer-file-name)
> -                                     t)))
> +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"

Period missing at the end of the last sentence.

> -	(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?

Also, please start the comment with a capital letter and end it with a
period.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#52508; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 15 Dec 2021 12:55:23 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Dec 15 07:55:23 2021
Received: from localhost ([127.0.0.1]:60441 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1mxToX-0006f1-GG
	for submit <at> debbugs.gnu.org; Wed, 15 Dec 2021 07:55:23 -0500
Received: from lists.gnu.org ([209.51.188.17]:54972)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <ashwin@HIDDEN>) id 1mxRRD-0000Km-Ih
 for submit <at> debbugs.gnu.org; Wed, 15 Dec 2021 05:23:07 -0500
Received: from eggs.gnu.org ([209.51.188.92]:36328)
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <ashwin@HIDDEN>)
 id 1mxRRD-0006Ra-An
 for bug-gnu-emacs@HIDDEN; Wed, 15 Dec 2021 05:23:07 -0500
Received: from forward100p.mail.yandex.net ([77.88.28.100]:50832)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <ashwin@HIDDEN>)
 id 1mxRR9-0005nt-K6
 for bug-gnu-emacs@HIDDEN; Wed, 15 Dec 2021 05:23:06 -0500
Received: from myt4-644a0c5be03a.qloud-c.yandex.net
 (myt4-644a0c5be03a.qloud-c.yandex.net [IPv6:2a02:6b8:c12:7af:0:640:644a:c5b])
 by forward100p.mail.yandex.net (Yandex) with ESMTP id 8364A4F07F11
 for <bug-gnu-emacs@HIDDEN>; Wed, 15 Dec 2021 13:22:43 +0300 (MSK)
Received: from myt5-cceafa914410.qloud-c.yandex.net
 (myt5-cceafa914410.qloud-c.yandex.net [2a02:6b8:c12:3b23:0:640:ccea:fa91])
 by myt4-644a0c5be03a.qloud-c.yandex.net (mxback/Yandex) with ESMTP id
 vZhN9SDlRN-MhfKJnYM; Wed, 15 Dec 2021 13:22:43 +0300
Authentication-Results: myt4-644a0c5be03a.qloud-c.yandex.net; dkim=pass
Received: by myt5-cceafa914410.qloud-c.yandex.net (smtp/Yandex) with ESMTPSA
 id 7CFz9qRr0R-MfPaxRh6; Wed, 15 Dec 2021 13:22:42 +0300
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
 (Client certificate not present)
X-Yandex-Fwd: 2
From: Ashwin Kafle <ashwin@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: [PATCH] Option for vc-delete-file to keep file on disk
Date: Wed, 15 Dec 2021 10:23:42 +0000
Message-ID: <85bl1igo9d.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
Received-SPF: pass client-ip=77.88.28.100; envelope-from=ashwin@HIDDEN;
 helo=forward100p.mail.yandex.net
X-Spam_score_int: -18
X-Spam_score: -1.9
X-Spam_bar: -
X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_MSPIKE_H2=-0.001,
 SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: -1.3 (-)
X-Debbugs-Envelope-To: submit
X-Mailman-Approved-At: Wed, 15 Dec 2021 07:55:18 -0500
Cc: Ashwin Kafle <ashwin@HIDDEN>, Dmitry Gutov <dgutov@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.3 (--)

--=-=-=
Content-Type: text/plain

Hello,
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.

I've already signed the copyright papers.


--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
 filename=0001-Option-for-vc-delete-file-to-keep-file-on-disk.patch

From 8bfbc34afa760c4d526fa15d8dddc78f2be78a81 Mon Sep 17 00:00:00 2001
From: Ashwin Kafle <ashwin@HIDDEN>
Date: Wed, 15 Dec 2021 15:25:04 +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: Make git leave files on disk.
* lisp/vc/vc.el: 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           | 20 +++++++++++---------
 4 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/doc/emacs/vc1-xtra.texi b/doc/emacs/vc1-xtra.texi
index 4cd00cba6c..2cf69583b3 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..2469060a3d 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..43fc0e787e 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -2970,14 +2970,13 @@ 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."
-  (interactive (list (read-file-name "VC delete file: " nil
-                                     (when (vc-backend buffer-file-name)
-                                       buffer-file-name)
-                                     t)))
+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 "f\nP")
   (setq file (expand-file-name file))
   (let ((buf (get-file-buffer file))
         (backend (vc-backend file)))
@@ -2999,19 +2998,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


--=-=-=--




Acknowledgement sent to Ashwin Kafle <ashwin@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#52508; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Wed, 15 Dec 2021 17:00:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.