From e579e9252b2b0eb145edc5075f5015b6797bf254 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 28 Jun 2025 10:30:29 +0100 Subject: [PATCH] vc-dir-update: Update 'backend' VC properties * lisp/vc/vc-dir.el (vc-dir-update): Update 'backend' VC file properties from ENTRIES. This resolves some issues relating to cache invalidation. * lisp/vc/vc-hooks.el (vc-backend): Improve docstring. (cherry picked from commit 6cd9574e20dccb15924dd42f0f481ba5b7367a42) --- lisp/vc/vc-dir.el | 14 ++++++++++---- lisp/vc/vc-hooks.el | 5 ++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lisp/vc/vc-dir.el b/lisp/vc/vc-dir.el index ae648deadee..7ab119abc13 100644 --- a/lisp/vc/vc-dir.el +++ b/lisp/vc/vc-dir.el @@ -487,9 +487,11 @@ If BODY uses EVENT, it should be a variable, (vc-dir-fileinfo->name data))))))) (defun vc-dir-update (entries buffer &optional noinsert) - "Update BUFFER's ewoc from the list of ENTRIES. -If NOINSERT, ignore elements on ENTRIES which are not in the ewoc." - ;; Add ENTRIES to the vc-dir buffer BUFFER. + "Update BUFFER's VC-Dir ewoc from ENTRIES. +This has the effect of adding ENTRIES to the VC-Dir buffer BUFFER. +If optional argument NOINSERT is non-nil, update ewoc nodes, but don't +add elements of ENTRIES to the buffer that aren't already in the ewoc. +Also update some VC file properties from ENTRIES." (with-current-buffer buffer ;; Insert the entries sorted by name into the ewoc. ;; We assume the ewoc is sorted too, which should be the @@ -592,7 +594,11 @@ If NOINSERT, ignore elements on ENTRIES which are not in the ewoc." (apply #'vc-dir-create-fileinfo entry)))))) (when to-remove (let ((inhibit-read-only t)) - (apply #'ewoc-delete vc-ewoc (nreverse to-remove))))))) + (apply #'ewoc-delete vc-ewoc (nreverse to-remove))))) + ;; Update VC file properties. + (pcase-dolist (`(,file ,state ,_extra) entries) + (vc-file-setprop file 'vc-backend + (if (eq state 'unregistered) 'none vc-dir-backend))))) (defun vc-dir-busy () (and (buffer-live-p vc-dir-process-buffer) diff --git a/lisp/vc/vc-hooks.el b/lisp/vc/vc-hooks.el index 0b81b5d1866..21f1df007df 100644 --- a/lisp/vc/vc-hooks.el +++ b/lisp/vc/vc-hooks.el @@ -377,7 +377,10 @@ backend is tried first." (defun vc-backend (file-or-list) "Return the version control type of FILE-OR-LIST, nil if it's not registered. -If the argument is a list, the files must all have the same back end." +If the argument is a list, the files must all have the same back end. + +This function returns cached information. To query the VCS regarding +whether FILE-OR-LIST is registered or unregistered, use `vc-registered'." ;; `file' can be nil in several places (typically due to the use of ;; code like (vc-backend buffer-file-name)). (cond ((stringp file-or-list) -- 2.39.5