Function: majutsu-diff-wash-diffstat

majutsu-diff-wash-diffstat is a natively compiled function defined in majutsu-diff.el.

Signature

(majutsu-diff-wash-diffstat)

Documentation

Wash the diffstat produced by jj diff --stat.

Assumes point is at the start of the diff output and that the output was generated using --git --stat, meaning the diffstat appears before the first "diff --git" header.

Source Code

;; Defined in /nix/store/jagqw3nms546pad0gxi5f3wsckk6pji7-emacs-packages-deps/share/emacs/site-lisp/majutsu-diff.el
;;; Diff wash

(defun majutsu-diff-wash-diffstat ()
  "Wash the diffstat produced by `jj diff --stat'.

Assumes point is at the start of the diff output and that the output was
generated using `--git --stat', meaning the diffstat appears before the
first \"diff --git\" header."
  (let ((files (majutsu-diff--collect-diff-files))
        heading
        (beg (point)))
    ;; Like `magit-diff-wash-diffstat': find the summary line first, delete it,
    ;; then rewrite each stat line as a `diffstat' section.
    (when (re-search-forward "^ ?\\([0-9]+ +files? change[^\n]*\n\\)" nil t)
      (setq heading (match-string 1))
      (delete-region (match-beginning 0) (match-end 0))
      (goto-char beg)
      (magit-insert-section (diffstat)
        (magit-insert-heading
          (propertize heading 'font-lock-face 'magit-diff-file-heading))
        (while (looking-at majutsu-diff-statline-re)
          (let* ((file (match-string-no-properties 1))
                 (sep  (match-string 2))
                 (cnt  (match-string 3))
                 (add  (match-string 4))
                 (del  (match-string 5)))
            (majutsu-diff--delete-line)
            (when (string-match " +$" file)
              (setq sep (concat (match-string 0 file) sep))
              (setq file (substring file 0 (match-beginning 0))))
            (setq file (string-trim-right file))
            (magit-insert-section (jj-file (or (pop files) file))
              (insert (magit-format-file 'stat file 'magit-filename))
              (insert sep)
              (cond
               ((string-match "\\`(binary)\\(?: +\\([+-][0-9]+\\) bytes\\)?\\'" cnt)
                (insert (propertize "(binary)" 'font-lock-face
                                    'majutsu-diffstat-binary))
                (when-let* ((delta (match-string 1 cnt)))
                  (insert " "
                          (propertize delta 'font-lock-face
                                      (if (string-prefix-p "-" delta)
                                          'magit-diffstat-removed
                                        'magit-diffstat-added))
                          " bytes")))
               (t
                (insert cnt)))
              (insert " ")
              (when add
                (insert (propertize add 'font-lock-face
                                    'magit-diffstat-added)))
              (when del
                (insert (propertize del 'font-lock-face
                                    'magit-diffstat-removed)))
              (insert "\n"))))
        (if (looking-at "^$") (forward-line) (insert "\n"))))))