From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#34949: 27.0.50; Docstring of `vc-deduce-fileset' incomplete Date: Tue, 18 Feb 2020 01:42:13 +0200 Message-ID: <87zhdghjca.fsf@mail.linkov.net> References: <877e5dzgnb.fsf@gnus.org> <932cfe15-5e8b-1bf4-5b81-9d0f2a513dea@yandex.ru> <87a77hqp6m.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="30145"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu) Cc: Lars Ingebrigtsen , 34949@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Feb 18 01:16:16 2020 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 1j3qYi-0007h0-Dy for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 18 Feb 2020 01:16:16 +0100 Original-Received: from localhost ([::1]:54908 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j3qYh-0008NC-FJ for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 17 Feb 2020 19:16:15 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37881) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j3qYV-0008Lf-Ur for bug-gnu-emacs@gnu.org; Mon, 17 Feb 2020 19:16:05 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j3qYU-0001Zu-G3 for bug-gnu-emacs@gnu.org; Mon, 17 Feb 2020 19:16:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:33413) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j3qYU-0001Zo-BN for bug-gnu-emacs@gnu.org; Mon, 17 Feb 2020 19:16:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1j3qYU-0000t1-7q for bug-gnu-emacs@gnu.org; Mon, 17 Feb 2020 19:16:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 18 Feb 2020 00:16:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 34949 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed Original-Received: via spool by 34949-submit@debbugs.gnu.org id=B34949.15819849053310 (code B ref 34949); Tue, 18 Feb 2020 00:16:02 +0000 Original-Received: (at 34949) by debbugs.gnu.org; 18 Feb 2020 00:15:05 +0000 Original-Received: from localhost ([127.0.0.1]:39380 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1j3qXY-0000rK-QI for submit@debbugs.gnu.org; Mon, 17 Feb 2020 19:15:05 -0500 Original-Received: from brown.birch.relay.mailchannels.net ([23.83.209.23]:62133) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1j3qXW-0000q0-AD for 34949@debbugs.gnu.org; Mon, 17 Feb 2020 19:15:02 -0500 X-Sender-Id: dreamhost|x-authsender|jurta@jurta.org Original-Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 4BB8B22B75; Tue, 18 Feb 2020 00:15:01 +0000 (UTC) Original-Received: from pdx1-sub0-mail-a38.g.dreamhost.com (100-96-217-4.trex.outbound.svc.cluster.local [100.96.217.4]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id D27FA22C09; Tue, 18 Feb 2020 00:15:00 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|jurta@jurta.org Original-Received: from pdx1-sub0-mail-a38.g.dreamhost.com ([TEMPUNAVAIL]. [64.90.62.162]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384) by 0.0.0.0:2500 (trex/5.18.5); Tue, 18 Feb 2020 00:15:01 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|jurta@jurta.org X-MailChannels-Auth-Id: dreamhost X-Descriptive-Fearful: 0a0d1085636ba595_1581984901099_2413300860 X-MC-Loop-Signature: 1581984901099:328043626 X-MC-Ingress-Time: 1581984901099 Original-Received: from pdx1-sub0-mail-a38.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a38.g.dreamhost.com (Postfix) with ESMTP id 06AF0B2700; Mon, 17 Feb 2020 16:14:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=linkov.net; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=linkov.net; bh=TzTNronUZgOerkZcxQj2ZXxeb8U=; b= 3LJQt1vrnwHxcNSRcCjVSluGpG8o0/lQGtlbw9jc5Bq8p/GAUOKm6R+5ZzMCmKAf TtcBv7Hw7vL9QMOgfqKt9zNF2eS/nLd4H14m2hcrDHb1RBXydvABQHk83rPM3zW/ M08MmmmqA9Skwh2KAYLWJbltfKldwPp7Joga5SDffjw= Original-Received: from localhost.linkov.net (m91-129-103-27.cust.tele2.ee [91.129.103.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: jurta@jurta.org) by pdx1-sub0-mail-a38.g.dreamhost.com (Postfix) with ESMTPSA id 42D8BB279A; Mon, 17 Feb 2020 16:14:53 -0800 (PST) X-DH-BACKEND: pdx1-sub0-mail-a38 In-Reply-To: <87a77hqp6m.fsf@mail.linkov.net> (Juri Linkov's message of "Wed, 25 Dec 2019 01:28:01 +0200") X-VR-OUT-STATUS: OK X-VR-OUT-SCORE: -100 X-VR-OUT-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedugedrjeejgddulecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucggtfgfnhhsuhgsshgtrhhisggvpdfftffgtefojffquffvnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvffufhffjgfkfgggtgesmhdtreertdertdenucfhrhhomheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqeenucfkphepledurdduvdelrddutdefrddvjeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhhouggvpehsmhhtphdphhgvlhhopehlohgtrghlhhhoshhtrdhlihhnkhhovhdrnhgvthdpihhnvghtpeeluddruddvledruddtfedrvdejpdhrvghtuhhrnhdqphgrthhhpefluhhrihcunfhinhhkohhvuceojhhurhhisehlihhnkhhovhdrnhgvtheqpdhmrghilhhfrhhomhepjhhurhhisehlihhnkhhovhdrnhgvthdpnhhrtghpthhtohepughguhhtohhvseihrghnuggvgidrrhhu X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 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:176172 Archived-At: --=-=-= Content-Type: text/plain >> What I don't fully understand, however, is why prohibit state-changing >> operations in Dired buffers. Is it just because there's no VC-Dir buffer >> easily at hand, to update the visible file statuses? > > Exactly the same question I ask myself every time I forget about this limitation > and type 'C-x v v' in Dired. I see now why it's difficult to support state changing VC operations in dired. The difficultly comes from the need to get a VC state from every marked file and to confirm that all marked files are in the same state. So I implemented this in vc-dired-deduce-fileset whose basic algorithm was taken from vc-dir-deduce-fileset. Now with this patch state changing VC operations are supported on marked _files_ in dired. However, the need for the OBSERVER arg still remains because this patch doesn't support state changing VC operations on marked _directories_ in dired. It raises the error in this case: State changing VC operations on directories not supported in `dired-mode' State changing VC operations could be supported on directories as well, but there are several possibilities to choose from, and I can't decide: 1. On a marked directory get a state from all its files (probably this variant makes no sense) 2. On a marked directory get only files with a "modified" state (i.e. edited/added/removed) But the latter is not easy to implement because the needed functionality is missing in VC, because the only VC method that is suitable for this is 'dir-status-files' to get VC files from a directory but it's too tightly integrated with vc-dir and can't be easily separated, i.e. there is no easy way to do something like: (with-temp-buffer (vc-call-backend (vc-responsible-backend default-directory) 'dir-status-files default-directory nil (lambda (entries &optional more-to-come) (message "! %S" entries)))) Once we decide how to support marked directories in dired, the arg OBSERVER can be deprecated. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=vc-dired-deduce-fileset.patch diff --git a/lisp/vc/vc-dispatcher.el b/lisp/vc/vc-dispatcher.el index 5ae300bf09..4a04c9365a 100644 --- a/lisp/vc/vc-dispatcher.el +++ b/lisp/vc/vc-dispatcher.el @@ -746,7 +746,8 @@ vc-finish-logentry (defun vc-dispatcher-browsing () "Are we in a directory browser buffer?" - (derived-mode-p 'vc-dir-mode)) + (or (derived-mode-p 'vc-dir-mode) + (derived-mode-p 'dired-mode))) ;; These are unused. ;; (defun vc-dispatcher-in-fileset-p (fileset) diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index ec252b74d4..bba1fb5919 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -1032,9 +1032,7 @@ vc-deduce-fileset ((derived-mode-p 'vc-dir-mode) (vc-dir-deduce-fileset state-model-only-files)) ((derived-mode-p 'dired-mode) - (if observer - (vc-dired-deduce-fileset) - (error "State changing VC operations not supported in `dired-mode'"))) + (vc-dired-deduce-fileset state-model-only-files observer)) ((setq backend (vc-backend buffer-file-name)) (if state-model-only-files (list backend (list buffer-file-name) @@ -1046,7 +1044,8 @@ vc-deduce-fileset ;; FIXME: Why this test? --Stef (or (buffer-file-name vc-parent-buffer) (with-current-buffer vc-parent-buffer - (derived-mode-p 'vc-dir-mode)))) + (or (derived-mode-p 'vc-dir-mode) + (derived-mode-p 'dired-mode))))) (progn ;FIXME: Why not `with-current-buffer'? --Stef. (set-buffer vc-parent-buffer) (vc-deduce-fileset observer allow-unregistered state-model-only-files))) @@ -1066,9 +1065,31 @@ vc-deduce-fileset (list buffer-file-name)))) (t (error "File is not under version control"))))) -(defun vc-dired-deduce-fileset () - (list (vc-responsible-backend default-directory) - (dired-map-over-marks (dired-get-filename nil t) nil))) +(declare-function dired-get-marked-files "dired" + (&optional localp arg filter distinguish-one-marked error)) + +(defun vc-dired-deduce-fileset (&optional state-model-only-files observer) + (let ((backend (vc-responsible-backend default-directory)) + (files (dired-get-marked-files nil nil nil nil t)) + only-files-list + state + model) + (when (and (not observer) (cl-some #'file-directory-p files)) + (error "State changing VC operations on directories not supported in `dired-mode'")) + + (when state-model-only-files + (setq only-files-list (mapcar (lambda (file) (cons file (vc-state file))) files)) + (setq state (cdar only-files-list)) + ;; Check that all files are in a consistent state, since we use that + ;; state to decide which operation to perform. + (dolist (crt (cdr only-files-list)) + (unless (vc-compatible-state (cdr crt) state) + (error "When applying VC operations to multiple files, the files are required\nto be in similar VC states.\n%s in state %s clashes with %s in state %s" + (car crt) (cdr crt) (caar only-files-list) state))) + (setq only-files-list (mapcar 'car only-files-list)) + (when (and state (not (eq state 'unregistered))) + (setq model (vc-checkout-model backend only-files-list)))) + (list backend files only-files-list state model))) (defun vc-ensure-vc-buffer () "Make sure that the current buffer visits a version-controlled file." --=-=-=--