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: Fri, 21 Feb 2020 01:14:20 +0200 Organization: LINKOV.NET Message-ID: <87v9o0kg1f.fsf@mail.linkov.net> References: <877e5dzgnb.fsf@gnus.org> <932cfe15-5e8b-1bf4-5b81-9d0f2a513dea@yandex.ru> <87a77hqp6m.fsf@mail.linkov.net> <87zhdghjca.fsf@mail.linkov.net> <5d2163b9-4bf4-e072-ef9e-0fc1550a2108@yandex.ru> <87imk35uy6.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="96333"; 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 Fri Feb 21 01:11:37 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 1j4vuq-000OwJ-RL for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 21 Feb 2020 01:11:36 +0100 Original-Received: from localhost ([::1]:50706 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4vup-0000Ns-RS for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 20 Feb 2020 19:11:35 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:32809) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4vuL-00089j-Rv for bug-gnu-emacs@gnu.org; Thu, 20 Feb 2020 19:11:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j4vuK-0007Y1-GX for bug-gnu-emacs@gnu.org; Thu, 20 Feb 2020 19:11:05 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:40161) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j4vuK-0007Xn-BE for bug-gnu-emacs@gnu.org; Thu, 20 Feb 2020 19:11:04 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1j4vuK-0005DA-7I for bug-gnu-emacs@gnu.org; Thu, 20 Feb 2020 19:11:04 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 21 Feb 2020 00:11:04 +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.158224382719890 (code B ref 34949); Fri, 21 Feb 2020 00:11:04 +0000 Original-Received: (at 34949) by debbugs.gnu.org; 21 Feb 2020 00:10:27 +0000 Original-Received: from localhost ([127.0.0.1]:46116 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1j4vti-0005Ak-PE for submit@debbugs.gnu.org; Thu, 20 Feb 2020 19:10:27 -0500 Original-Received: from aye.elm.relay.mailchannels.net ([23.83.212.6]:15107) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1j4vtf-0005Aa-RS for 34949@debbugs.gnu.org; Thu, 20 Feb 2020 19:10:24 -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 A354A540861; Fri, 21 Feb 2020 00:10:22 +0000 (UTC) Original-Received: from pdx1-sub0-mail-a86.g.dreamhost.com (100-96-13-15.trex.outbound.svc.cluster.local [100.96.13.15]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 2E809540A4A; Fri, 21 Feb 2020 00:10:22 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|jurta@jurta.org Original-Received: from pdx1-sub0-mail-a86.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); Fri, 21 Feb 2020 00:10:22 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|jurta@jurta.org X-MailChannels-Auth-Id: dreamhost X-Abaft-Abaft: 183ae9090f2af5ec_1582243822423_4140162099 X-MC-Loop-Signature: 1582243822423:3528702544 X-MC-Ingress-Time: 1582243822423 Original-Received: from pdx1-sub0-mail-a86.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a86.g.dreamhost.com (Postfix) with ESMTP id D5E297F015; Thu, 20 Feb 2020 16:10:17 -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=J1m2wg5yN1oD5Xvabt6NGBUyQ1M=; b= cgPS6dUpiWRgzFoaZCCLe8Eu+T0zsGCnBV4U+PIZWVWtx5BQ2t+eW7XrdmtaHMBI 8hP1ZZz5bFhDoEX0ufXqFR+6Br1JimBSD+kN3hxCNPP2mAGtZRzBk8b3HiYKZq0Y YpnUeen747T/uIfmM+6nQUfWLtd5Y74wQzQcZsqoFYU= 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-a86.g.dreamhost.com (Postfix) with ESMTPSA id D65357EFDF; Thu, 20 Feb 2020 16:10:14 -0800 (PST) X-DH-BACKEND: pdx1-sub0-mail-a86 In-Reply-To: <87imk35uy6.fsf@mail.linkov.net> (Juri Linkov's message of "Wed, 19 Feb 2020 01:36:49 +0200") X-VR-OUT-STATUS: OK X-VR-OUT-SCORE: -100 X-VR-OUT-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedugedrkeefgddulecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucggtfgfnhhsuhgsshgtrhhisggvpdfftffgtefojffquffvnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvffuohhfffgjkfgfgggtsehmtderredtredtnecuhfhrohhmpefluhhrihcunfhinhhkohhvuceojhhurhhisehlihhnkhhovhdrnhgvtheqnecukfhppeeluddruddvledruddtfedrvdejnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmohguvgepshhmthhppdhhvghloheplhhotggrlhhhohhsthdrlhhinhhkohhvrdhnvghtpdhinhgvthepledurdduvdelrddutdefrddvjedprhgvthhurhhnqdhprghthheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqedpmhgrihhlfhhrohhmpehjuhhriheslhhinhhkohhvrdhnvghtpdhnrhgtphhtthhopegughhuthhovheshigrnhguvgigrdhruh 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:176330 Archived-At: --=-=-= Content-Type: text/plain >> I think the only possible problem here is that lambda is invoked >> asynchronously. But we can sleep while waiting for it. > > Would it be possible to call dir-status-files synchronously? If asynchronousness is inevitable, we could rely on callbacks. Indeed this path leads to callback hell, but what are other options? This unfinished patch shows a possible development direction: vc-next-action executed in Dired will call vc-dired-deduce-fileset with a callback to continue with a prepared vc-fileset. vc-dired-deduce-fileset will call a more general vc-directory-deduce-fileset that will call a currently unimplemented function vc-dir-status-files whose implementation will be like in your diff-hl-dired-update. Also a new command vc-next-action-on-root will commit all modified files, ignoring any unregistered files. I miss such a command in VC-Dir: typing 'v' (vc-next-action) at the beginning of *vc-dir* buffer signals the error: "When applying VC operations to multiple files, the files are required to be in similar VC states. File in state 'edited' clashes with state 'unregistered'". Often I have a lot of unregistered files lying around for a long time, and it takes too much time manually marking only edited files for every commit, skipping each unregistered file. Also some parts of the previous patch should be reverted because I discovered that state changing VC operations in Dired even on marked files (as opposed to directories) is unreliable: when a file is modified, using vc-state doesn't return its real state when updated outside of Emacs. This part should be replaced with asynchronous dir-status-files that returns the most accurate state. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=callback-hell.patch diff --git a/lisp/vc/vc-hooks.el b/lisp/vc/vc-hooks.el index 345a28d3f1..80c580e5ec 100644 --- a/lisp/vc/vc-hooks.el +++ b/lisp/vc/vc-hooks.el @@ -897,6 +897,7 @@ vc-prefix-map (define-key map "s" 'vc-create-tag) (define-key map "u" 'vc-revert) (define-key map "v" 'vc-next-action) + (define-key map "V" 'vc-next-action-on-root) (define-key map "+" 'vc-update) ;; I'd prefer some kind of symmetry with vc-update: (define-key map "P" 'vc-push) diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index f7d651fac6..13d60b6fcf 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -1065,19 +1067,27 @@ vc-deduce-fileset (list buffer-file-name)))) (t (error "File is not under version control"))))) +(defun vc-root-deduce-fileset (callback) + (let* ((backend (vc-responsible-backend default-directory)) + (rootdir (vc-call-backend backend 'root default-directory))) + (vc-directory-deduce-fileset rootdir callback))) + +(defun vc-directory-deduce-fileset (dir callback) + ;; TODO: use vc-dir-status-files + ) + (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) +(defun vc-dired-deduce-fileset (&optional callback) (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 + (when callback + ;; TODO: use vc-directory-deduce-fileset (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 @@ -1132,6 +1142,11 @@ vc-read-backend (completing-read prompt (mapcar #'symbol-name vc-handled-backends) nil 'require-match))) +(defun vc-next-action-on-root (verbose) + (interactive "P") + (vc-root-deduce-fileset + (lambda (vc-fileset) (vc-next-action-on-fileset vc-fileset verbose)))) + ;; Here's the major entry point. ;;;###autoload @@ -1158,8 +1173,16 @@ vc-next-action If every file is locked by you and unchanged, unlock them. If every file is locked by someone else, offer to steal the lock." (interactive "P") - (let* ((vc-fileset (vc-deduce-fileset nil t 'state-model-only-files)) - (backend (car vc-fileset)) + (cond + ((derived-mode-p 'dired-mode) + ;; Async operation + (vc-dired-deduce-fileset + (lambda (vc-fileset) (vc-next-action-on-fileset vc-fileset verbose)))) + (t (vc-next-action-on-fileset + (vc-deduce-fileset nil t 'state-model-only-files) verbose)))) + +(defun vc-next-action-on-fileset (vc-fileset verbose) + (let* ((backend (car vc-fileset)) (files (nth 1 vc-fileset)) ;; (fileset-only-files (nth 2 vc-fileset)) ;; FIXME: We used to call `vc-recompute-state' here. @@ -3138,6 +3171,10 @@ vc-default-dir-status-files (funcall update-function (mapcar (lambda (file) (list file 'up-to-date)) files))) +(defun vc-dir-status-files (backend dir files update-function) + (funcall update-function + (mapcar (lambda (file) (list file 'up-to-date)) files))) + (defun vc-check-headers () "Check if the current file has any headers in it." (interactive) --=-=-=--