Function: treemacs-do-update-single-file-git-state
treemacs-do-update-single-file-git-state is a byte-compiled function
defined in treemacs-async.el.
Signature
(treemacs-do-update-single-file-git-state FILE &optional EXCLUDE-PARENTS OVERRIDE-STATUS)
Documentation
Asynchronously update the given FILE node's git fontification.
Since an update to a single node can potentially also mean a change to the states of all its parents they will likewise be updated by this function. If the file's current and new git status are the same this function will do nothing.
When EXCLUDE-PARENTS is non-nil only the given FILE only the file node is updated. This is only used in case a file-watch update requires the insertion of a new file that, due to being recently created, does not have a git status cache entry.
When OVERRIDE-STATUS is non-nil the FILE's cached git status will not be used.
FILE: FilePath EXCLUDE-PARENTS: Boolean OVERRIDE-STATUS: Boolean
Source Code
;; Defined in ~/.emacs.d/elpa/treemacs-20251226.1307/treemacs-async.el
(defun treemacs-do-update-single-file-git-state (file &optional exclude-parents override-status)
"Asynchronously update the given FILE node's git fontification.
Since an update to a single node can potentially also mean a change to the
states of all its parents they will likewise be updated by this function. If
the file's current and new git status are the same this function will do
nothing.
When EXCLUDE-PARENTS is non-nil only the given FILE only the file node is
updated. This is only used in case a file-watch update requires the insertion
of a new file that, due to being recently created, does not have a git status
cache entry.
When OVERRIDE-STATUS is non-nil the FILE's cached git status will not be used.
FILE: FilePath
EXCLUDE-PARENTS: Boolean
OVERRIDE-STATUS: Boolean"
(let* ((local-buffer (current-buffer))
(parent (treemacs--parent file))
(parent-node (treemacs-find-in-dom parent)))
(when (and
treemacs-git-mode
parent-node
(null (ht-get treemacs--single-git-update-debouce-store file)))
(ht-set! treemacs--single-git-update-debouce-store file t)
(let* ((parents (unless (or exclude-parents
(eq 'simple treemacs--git-mode)
(null (treemacs-dom-node->parent parent-node)))
;; include the first parent...
(cons (treemacs-dom-node->key parent-node)
;; ...but exclude the project root
(cdr (-map #'treemacs-dom-node->key
(treemacs-dom-node->all-parents parent-node))))))
(git-cache (ht-get treemacs--git-cache parent))
(current-face (if override-status
"OVERRIDE"
(or (-some-> git-cache (ht-get file) (symbol-name))
"NONE")))
(cmd `(,treemacs-python-executable
"-O"
,treemacs--single-file-git-status.py
,treemacs-git-executable ,file ,current-face ,@parents)))
(pfuture-callback cmd
:directory parent
:name "Treemacs Update Single File Process"
:on-success
(progn
(ht-remove! treemacs--single-git-update-debouce-store file)
(when (buffer-live-p local-buffer)
(with-current-buffer local-buffer
(treemacs-with-writable-buffer
(save-excursion
;; first the file node with its own default face
(-let [output (read (pfuture-callback-output))]
(-let [(path . face) (pop output)]
(treemacs--git-face-quick-change path face git-cache))
;; then the directories
(pcase-dolist (`(,path . ,face) output)
(treemacs--git-face-quick-change path face))))))))
:on-error
(progn
(ht-remove! treemacs--single-git-update-debouce-store file)
(pcase (process-exit-status process)
(2 (ignore "No Change, Do Nothing"))
(_
(-let [err-str (treemacs--remove-trailing-newline (pfuture-output-from-buffer pfuture-buffer))]
(treemacs-log-err "Update of node \"%s\" failed with status \"%s\" and result"
file (treemacs--remove-trailing-newline status))
(treemacs-log-err "\"%s\"" (treemacs--remove-trailing-newline err-str)))))))))))