]> git.eshelyaron.com Git - emacs.git/commitdiff
Disable VC in special directories on Android
authorPo Lu <luangruo@yahoo.com>
Sat, 30 Mar 2024 07:05:30 +0000 (15:05 +0800)
committerEshel Yaron <me@eshelyaron.com>
Sat, 30 Mar 2024 19:36:41 +0000 (20:36 +0100)
* lisp/vc/vc-hooks.el (vc-registered, vc-backend): Return nil
without invoking any backend if FILE or FILE-OR-LIST sits within
/content or /assets.

(cherry picked from commit 21af3a9d9706baa417298e70260efa3fce72c6f1)

lisp/vc/vc-hooks.el

index 75f68dd80d14a1d388ec4daebeb31d34ea3713cc..8f212e9693376218c0b0260e7b13643963651267 100644 (file)
@@ -326,30 +326,37 @@ This function performs the check each time it is called.  To rely
 on the result of a previous call, use `vc-backend' instead.  If the
 file was previously registered under a certain backend, then that
 backend is tried first."
-  (let (handler)
-    (cond
-     ((and (file-name-directory file)
-           (string-match vc-ignore-dir-regexp (file-name-directory file)))
-      nil)
-     ((setq handler (find-file-name-handler file 'vc-registered))
-      ;; handler should set vc-backend and return t if registered
-      (funcall handler 'vc-registered file))
-     (t
-      ;; There is no file name handler.
-      ;; Try vc-BACKEND-registered for each handled BACKEND.
-      (catch 'found
-       (let ((backend (vc-file-getprop file 'vc-backend)))
-         (mapc
-          (lambda (b)
-            (and (vc-call-backend b 'registered file)
-                 (vc-file-setprop file 'vc-backend b)
-                 (throw 'found t)))
-          (if (or (not backend) (eq backend 'none))
-              vc-handled-backends
-            (cons backend vc-handled-backends))))
-        ;; File is not registered.
-        (vc-file-setprop file 'vc-backend 'none)
-        nil)))))
+  ;; Subprocesses (and with them, VC backends) can't run from /contents
+  ;; or /actions, which are fictions maintained by Emacs that do not
+  ;; exist in the filesystem.
+  (if (and (eq system-type 'android)
+           (string-match-p "/\\(content\\|assets\\)[/$]"
+                           (expand-file-name file)))
+      nil
+    (let (handler)
+      (cond
+       ((and (file-name-directory file)
+             (string-match vc-ignore-dir-regexp (file-name-directory file)))
+        nil)
+       ((setq handler (find-file-name-handler file 'vc-registered))
+        ;; handler should set vc-backend and return t if registered
+        (funcall handler 'vc-registered file))
+       (t
+        ;; There is no file name handler.
+        ;; Try vc-BACKEND-registered for each handled BACKEND.
+        (catch 'found
+         (let ((backend (vc-file-getprop file 'vc-backend)))
+           (mapc
+            (lambda (b)
+              (and (vc-call-backend b 'registered file)
+                   (vc-file-setprop file 'vc-backend b)
+                   (throw 'found t)))
+            (if (or (not backend) (eq backend 'none))
+                vc-handled-backends
+              (cons backend vc-handled-backends))))
+          ;; File is not registered.
+          (vc-file-setprop file 'vc-backend 'none)
+          nil))))))
 
 (defun vc-backend (file-or-list)
   "Return the version control type of FILE-OR-LIST, nil if it's not registered.
@@ -357,15 +364,22 @@ If the argument is a list, the files must all have the same back end."
   ;; `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)
-        (let ((property (vc-file-getprop file-or-list 'vc-backend)))
-          ;; Note that internally, Emacs remembers unregistered
-          ;; files by setting the property to `none'.
-          (cond ((eq property 'none) nil)
-                (property)
-                ;; vc-registered sets the vc-backend property
-                (t (if (vc-registered file-or-list)
-                       (vc-file-getprop file-or-list 'vc-backend)
-                     nil)))))
+         ;; Subprocesses (and with them, VC backends) can't run from
+         ;; /contents or /actions, which are fictions maintained by
+         ;; Emacs that do not exist in the filesystem.
+         (if (and (eq system-type 'android)
+                  (string-match-p "/\\(content\\|assets\\)[/$]"
+                                  (expand-file-name file-or-list)))
+             nil
+          (let ((property (vc-file-getprop file-or-list 'vc-backend)))
+            ;; Note that internally, Emacs remembers unregistered
+            ;; files by setting the property to `none'.
+            (cond ((eq property 'none) nil)
+                  (property)
+                  ;; vc-registered sets the vc-backend property
+                  (t (if (vc-registered file-or-list)
+                         (vc-file-getprop file-or-list 'vc-backend)
+                       nil))))))
        ((and file-or-list (listp file-or-list))
         (vc-backend (car file-or-list)))
        (t