From 384c8cede3ed9a68a3fb916dbe803ee8fc7be4e3 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 4 Oct 2023 12:13:39 +1100 Subject: [PATCH 1/4] Disable automatic scans in remote repositories, add option to re-renable New option magit-todos-update-remote controls whether todos are automatically updated in remote repos (accessed via TRAMP). Defaults to disabled. New option was suggested in #132 (although not a fix for that issue), and is disabled by default as suggested in #157. --- README.org | 3 ++- magit-todos.el | 70 +++++++++++++++++++++++++++++--------------------- 2 files changed, 43 insertions(+), 30 deletions(-) diff --git a/README.org b/README.org index 47bd2ff3..0744f45f 100644 --- a/README.org +++ b/README.org @@ -141,7 +141,7 @@ Helm and Ivy are also supported. Note that the =helm= and =ivy= packages are no :CUSTOM_ID: TRAMP :END: -=magit-todos= attempts to work in remote repositories accessed via TRAMP. Note that if TRAMP can't find the scanner configured in =magit-todos-scanner=, you may need to use directory-local variables to either add the correct path to =tramp-remote-path= or choose a different scanner. +To-dos are not automatically scanned in remote repositories accessed via TRAMP, unless ~magit-todos-update-remote~ is set. Note that if TRAMP can't find the scanner configured in =magit-todos-scanner=, you may need to use directory-local variables to either add the correct path to =tramp-remote-path= or choose a different scanner. * Changelog :PROPERTIES: @@ -154,6 +154,7 @@ Helm and Ivy are also supported. Note that the =helm= and =ivy= packages are no + Branch-specific TODOs are also cached (to avoid rescanning when automatic updates are disabled. This can improve performance in large repos). *Changes* ++ To-dos are not automatically scanned in remote repositories accessed via TRAMP, unless new option ~magit-todos-update-remote~ is set. ([[https://github.com/alphapapa/magit-todos/pull/157][#157]]. Thanks to [[https://github.com/projectgus][Angus Gratton]].) + Option ~magit-todos-keyword-suffix~ defaults to allowing suffixes to be enclosed by parentheses or brackets (rather than just parentheses). + Minor improvements to warnings about files containing very long lines: display as messages instead of warnings, and signal errors from outside the process sentinel. diff --git a/magit-todos.el b/magit-todos.el index e5fe465d..81d89e9a 100644 --- a/magit-todos.el +++ b/magit-todos.el @@ -207,6 +207,14 @@ items." (integer :tag "Automatically, but cache items for N seconds") (const :tag "Manually" nil))) +(defcustom magit-todos-update-remote nil + "Automatically scan in remote repositories. +If nil, remote repos are only scanned when a manual scan is +initiated (see command `magit-todos-update'). Remote repos +include ones accessed via TRAMP (i.e. any path for which +`file-remote-p' returns non-nil)." + :type 'boolean) + (defcustom magit-todos-fontify-keyword-headers t "Apply keyword faces to group keyword headers." :type 'boolean) @@ -711,38 +719,42 @@ Assumes current buffer is ITEM's buffer." "Insert to-do items into current buffer. This function should be called from inside a ‘magit-status’ buffer." (declare (indent defun)) - (when magit-todos-active-scan - ;; Avoid running multiple scans for a single magit-status buffer. - (let ((buffer (process-buffer magit-todos-active-scan))) - (when (process-live-p magit-todos-active-scan) - (delete-process magit-todos-active-scan)) - (when (buffer-live-p buffer) - (kill-buffer buffer))) - (setq magit-todos-active-scan nil)) - (pcase magit-todos-update - ((or 't ; Automatic + (when (or magit-todos-update-remote + magit-todos-updating + (not (file-remote-p default-directory))) + ;; Skip automatic scans of remote buffers if magit-todos-update-remote is unset. + (when magit-todos-active-scan + ;; Avoid running multiple scans for a single magit-status buffer. + (let ((buffer (process-buffer magit-todos-active-scan))) + (when (process-live-p magit-todos-active-scan) + (delete-process magit-todos-active-scan)) + (when (buffer-live-p buffer) + (kill-buffer buffer))) + (setq magit-todos-active-scan nil)) + (pcase magit-todos-update + ((or 't ; Automatic ;; Manual and updating now (and 'nil (guard magit-todos-updating)) ;; Caching and cache expired - (and (pred integerp) (guard (or magit-todos-updating ; Forced update - (>= (float-time - (time-subtract (current-time) - magit-todos-last-update-time)) - magit-todos-update) - (null magit-todos-last-update-time))))) - ;; Scan and insert. - ;; HACK: I don't like setting a special var here, because it seems like lexically binding a - ;; special var should follow down the chain, but it isn't working, so we'll do this. - (setq magit-todos-updating t) - (setq magit-todos-active-scan (funcall magit-todos-scanner - :callback #'magit-todos--insert-items - :magit-status-buffer (current-buffer) - :directory default-directory - :depth magit-todos-depth)) - (magit-todos--maybe-insert-branch-todos 'rescan)) - (_ ; Caching and cache not expired, or not automatic and not manually updating now - (magit-todos--insert-items (current-buffer) magit-todos-item-cache) - (magit-todos--maybe-insert-branch-todos 'cached)))) + (and (pred integerp) (guard (or magit-todos-updating ; Forced update + (>= (float-time + (time-subtract (current-time) + magit-todos-last-update-time)) + magit-todos-update) + (null magit-todos-last-update-time))))) + ;; Scan and insert. + ;; HACK: I don't like setting a special var here, because it seems like lexically binding a + ;; special var should follow down the chain, but it isn't working, so we'll do this. + (setq magit-todos-updating t) + (setq magit-todos-active-scan (funcall magit-todos-scanner + :callback #'magit-todos--insert-items + :magit-status-buffer (current-buffer) + :directory default-directory + :depth magit-todos-depth)) + (magit-todos--maybe-insert-branch-todos 'rescan)) + (_ ; Caching and cache not expired, or not automatic and not manually updating now + (magit-todos--insert-items (current-buffer) magit-todos-item-cache) + (magit-todos--maybe-insert-branch-todos 'cached))))) (defun magit-todos--maybe-insert-branch-todos (&optional type) "Insert branch todos when appropriate. From 69fae213d4fac8f03163e77e3d7c84463fe39efd Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Sat, 18 May 2024 21:39:19 -0500 Subject: [PATCH 2/4] Docs: Update readme --- README.org | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.org b/README.org index 0744f45f..21a1448b 100644 --- a/README.org +++ b/README.org @@ -141,7 +141,9 @@ Helm and Ivy are also supported. Note that the =helm= and =ivy= packages are no :CUSTOM_ID: TRAMP :END: -To-dos are not automatically scanned in remote repositories accessed via TRAMP, unless ~magit-todos-update-remote~ is set. Note that if TRAMP can't find the scanner configured in =magit-todos-scanner=, you may need to use directory-local variables to either add the correct path to =tramp-remote-path= or choose a different scanner. +Remote repositories (i.e. ones accessed via TRAMP) are not automatically scanned for to-dos unless option ~magit-todos-update-remote~ is enabled. Otherwise, a scan may be manually initiated with the command ~magit-todos-update~. + +Note that if TRAMP can't find the scanner configured in option ~magit-todos-scanner~, you may need to use directory-local variables to either add the correct path to variable ~tramp-remote-path~ or choose a different scanner. * Changelog :PROPERTIES: @@ -152,9 +154,10 @@ To-dos are not automatically scanned in remote repositories accessed via TRAMP, *Additions* + Branch-specific TODOs are also cached (to avoid rescanning when automatic updates are disabled. This can improve performance in large repos). ++ Option ~magit-todos-upate-remote~ allows automatic scanning in remote repositories. ([[https://github.com/alphapapa/magit-todos/pull/157][#157]]. Thanks to [[https://github.com/projectgus][Angus Gratton]].) *Changes* -+ To-dos are not automatically scanned in remote repositories accessed via TRAMP, unless new option ~magit-todos-update-remote~ is set. ([[https://github.com/alphapapa/magit-todos/pull/157][#157]]. Thanks to [[https://github.com/projectgus][Angus Gratton]].) ++ Remote repositories are no longer automatically scanned (see new option ~magit-todos-update-remote~). + Option ~magit-todos-keyword-suffix~ defaults to allowing suffixes to be enclosed by parentheses or brackets (rather than just parentheses). + Minor improvements to warnings about files containing very long lines: display as messages instead of warnings, and signal errors from outside the process sentinel. From c76eb971d8b45daa89c2300804f8e73b6600d6b2 Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Sat, 18 May 2024 21:44:40 -0500 Subject: [PATCH 3/4] Tidy: Indentation --- magit-todos.el | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/magit-todos.el b/magit-todos.el index 81d89e9a..86a55159 100644 --- a/magit-todos.el +++ b/magit-todos.el @@ -208,7 +208,7 @@ items." (const :tag "Manually" nil))) (defcustom magit-todos-update-remote nil - "Automatically scan in remote repositories. + "Automatically scan in remote repositories. If nil, remote repos are only scanned when a manual scan is initiated (see command `magit-todos-update'). Remote repos include ones accessed via TRAMP (i.e. any path for which @@ -720,8 +720,8 @@ Assumes current buffer is ITEM's buffer." This function should be called from inside a ‘magit-status’ buffer." (declare (indent defun)) (when (or magit-todos-update-remote - magit-todos-updating - (not (file-remote-p default-directory))) + magit-todos-updating + (not (file-remote-p default-directory))) ;; Skip automatic scans of remote buffers if magit-todos-update-remote is unset. (when magit-todos-active-scan ;; Avoid running multiple scans for a single magit-status buffer. @@ -733,28 +733,28 @@ This function should be called from inside a ‘magit-status’ buffer." (setq magit-todos-active-scan nil)) (pcase magit-todos-update ((or 't ; Automatic - ;; Manual and updating now - (and 'nil (guard magit-todos-updating)) - ;; Caching and cache expired - (and (pred integerp) (guard (or magit-todos-updating ; Forced update - (>= (float-time - (time-subtract (current-time) - magit-todos-last-update-time)) - magit-todos-update) - (null magit-todos-last-update-time))))) - ;; Scan and insert. - ;; HACK: I don't like setting a special var here, because it seems like lexically binding a - ;; special var should follow down the chain, but it isn't working, so we'll do this. - (setq magit-todos-updating t) - (setq magit-todos-active-scan (funcall magit-todos-scanner - :callback #'magit-todos--insert-items - :magit-status-buffer (current-buffer) - :directory default-directory - :depth magit-todos-depth)) - (magit-todos--maybe-insert-branch-todos 'rescan)) + ;; Manual and updating now + (and 'nil (guard magit-todos-updating)) + ;; Caching and cache expired + (and (pred integerp) (guard (or magit-todos-updating ; Forced update + (>= (float-time + (time-subtract (current-time) + magit-todos-last-update-time)) + magit-todos-update) + (null magit-todos-last-update-time))))) + ;; Scan and insert. + ;; HACK: I don't like setting a special var here, because it seems like lexically binding a + ;; special var should follow down the chain, but it isn't working, so we'll do this. + (setq magit-todos-updating t) + (setq magit-todos-active-scan (funcall magit-todos-scanner + :callback #'magit-todos--insert-items + :magit-status-buffer (current-buffer) + :directory default-directory + :depth magit-todos-depth)) + (magit-todos--maybe-insert-branch-todos 'rescan)) (_ ; Caching and cache not expired, or not automatic and not manually updating now - (magit-todos--insert-items (current-buffer) magit-todos-item-cache) - (magit-todos--maybe-insert-branch-todos 'cached))))) + (magit-todos--insert-items (current-buffer) magit-todos-item-cache) + (magit-todos--maybe-insert-branch-todos 'cached))))) (defun magit-todos--maybe-insert-branch-todos (&optional type) "Insert branch todos when appropriate. From 8f8e6ddfafa5de973122d0cd33a7fb03afdf51c1 Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Sat, 18 May 2024 21:44:48 -0500 Subject: [PATCH 4/4] Comment: Remove --- magit-todos.el | 1 - 1 file changed, 1 deletion(-) diff --git a/magit-todos.el b/magit-todos.el index 86a55159..dd30488a 100644 --- a/magit-todos.el +++ b/magit-todos.el @@ -722,7 +722,6 @@ This function should be called from inside a ‘magit-status’ buffer." (when (or magit-todos-update-remote magit-todos-updating (not (file-remote-p default-directory))) - ;; Skip automatic scans of remote buffers if magit-todos-update-remote is unset. (when magit-todos-active-scan ;; Avoid running multiple scans for a single magit-status buffer. (let ((buffer (process-buffer magit-todos-active-scan)))