Function: magit-todos--git-diff-callback
magit-todos--git-diff-callback is a natively compiled function defined
in magit-todos.el.
Signature
(magit-todos--git-diff-callback &key MAGIT-STATUS-BUFFER RESULTS-REGEXP SEARCH-REGEXP-ELISP PROCESS HEADING EXCLUDE-GLOBS &allow-other-keys)
Documentation
Callback for git diff scanner output.
Insert into MAGIT-STATUS-BUFFER. RESULTS-REGEXP matches a result
on each line. SEARCH-REGEXP-ELISP finds the next hunk of
results. PROCESS is the "git diff" process object.
magit-todos-section-heading is bound to HEADING when inserting
items. EXCLUDE-GLOBS is a list of glob patterns matching
filenames to be excluded.
Source Code
;; Defined in /nix/store/xy37aj9089qvbs5clw0qszpi3hrh3mxx-emacs-packages-deps/share/emacs/site-lisp/elpa/magit-todos-20250928.1611/magit-todos.el
(cl-defun magit-todos--git-diff-callback (&key magit-status-buffer results-regexp search-regexp-elisp process heading
exclude-globs &allow-other-keys)
"Callback for git diff scanner output.
Insert into MAGIT-STATUS-BUFFER. RESULTS-REGEXP matches a result
on each line. SEARCH-REGEXP-ELISP finds the next hunk of
results. PROCESS is the \"git diff\" process object.
`magit-todos-section-heading' is bound to HEADING when inserting
items. EXCLUDE-GLOBS is a list of glob patterns matching
filenames to be excluded."
;; NOTE: Doesn't handle newlines in filenames or diff.mnemonicPrefix.
(cl-macrolet ((next-diff () `(re-search-forward (rx bol "diff --git ") nil t))
(next-filename () `(when (re-search-forward (rx bol "+++ b/" (group (1+ nonl))) nil t)
(match-string 1)))
(next-hunk-line-number () `(when (re-search-forward (rx bol "@@ -"
(1+ digit) (optional "," (1+ digit)) (1+ space)
"+" (group (1+ digit)) (optional "," (1+ digit)))
file-end t)
(string-to-number (match-string 1))))
(file-end () `(or (save-excursion
(when (re-search-forward (rx bol "diff --git ")
nil t)
(match-beginning 0)))
(point-max)))
(hunk-end () `(or (save-excursion
(when (re-search-forward (rx (or (seq bol "diff --git ")
(seq bol "@@ ")))
nil t)
(match-beginning 0)))
(point-max))))
(with-current-buffer (process-buffer process)
(goto-char (point-min))
(let ((glob-regexps (mapcar #'wildcard-to-regexp exclude-globs))
items filename file-end hunk-end line-number)
(while (next-diff)
(while (setf filename (next-filename))
(unless (--some? (string-match it filename) glob-regexps)
(setf file-end (file-end))
(while (setf line-number (next-hunk-line-number))
(setf hunk-end (hunk-end))
(while (re-search-forward (rx bol "+") hunk-end t)
;; Since "git diff-index" doesn't accept PCREs to its "-G" option, we have to test the search regexp ourselves.
(when (re-search-forward search-regexp-elisp (line-end-position) t)
(when-let* ((line (buffer-substring (line-beginning-position) (line-end-position)))
(item (with-temp-buffer
;; NOTE: We fake grep output by inserting the filename, line number, position, etc.
;; This lets us use the same results regexp that's used for grep-like output.
(save-excursion
(insert filename ":" (number-to-string line-number) ":0: " line))
(magit-todos--line-item results-regexp filename))))
(push item items)))
(cl-incf line-number))))))
(let ((magit-todos-section-heading heading))
(setf (buffer-local-value 'magit-todos-branch-item-cache magit-status-buffer) items)
(magit-todos--insert-items magit-status-buffer items :branch-p t))))))