Use diff-index and diff-files for the status buffer.

Instead of a --numstat diff.  This gives more information.

* magit.el (magit-insert-diff-title): Factored out of
magit-wash-diff-section.  Don't handle mode changes separately from
content changes.
(magit-wash-raw-diffs, magit-wash-raw-diff): New.
(magit-wash-numstat-diffs, magit-wash-numstat-diff): Removed.
(magit-insert-unstaged-changes): Use git diff-files.
(magit-insert-staged-changes): Use git diff-index.
This commit is contained in:
Marius Vollmer 2009-07-27 23:02:02 +03:00
parent 3e77accab9
commit 6e33fdf6c7

View file

@ -1442,6 +1442,23 @@ Please see the manual for a complete description of Magit.
(defvar magit-hide-diffs nil) (defvar magit-hide-diffs nil)
(defun magit-insert-diff-title (status file file2)
(let ((status-text (case status
((unmerged)
(format "Unmerged %s" file))
((new)
(format "New %s" file))
((deleted)
(format "Deleted %s" file))
((renamed)
(format "Renamed %s (from %s)"
file file2))
((modified)
(format "Modified %s" file))
(t
(format "? %s" file)))))
(insert "\t" status-text "\n")))
(defun magit-wash-diff-section () (defun magit-wash-diff-section ()
(cond ((looking-at "^\\* Unmerged path \\(.*\\)") (cond ((looking-at "^\\* Unmerged path \\(.*\\)")
(let ((file (match-string-no-properties 1))) (let ((file (match-string-no-properties 1)))
@ -1463,9 +1480,6 @@ Please see the manual for a complete description of Magit.
((save-excursion ((save-excursion
(search-forward-regexp "^new file" end t)) (search-forward-regexp "^new file" end t))
'new) 'new)
((save-excursion
(search-forward-regexp "^new mode" end t))
'mode)
((save-excursion ((save-excursion
(search-forward-regexp "^deleted" end t)) (search-forward-regexp "^deleted" end t))
'deleted) 'deleted)
@ -1478,25 +1492,9 @@ Please see the manual for a complete description of Magit.
((save-excursion ((save-excursion
(search-forward-regexp "^rename from \\(.*\\)" (search-forward-regexp "^rename from \\(.*\\)"
end t)) end t))
(match-string-no-properties 1)))) (match-string-no-properties 1)))))
(status-text (case status
((unmerged)
(format "Unmerged %s" file))
((new)
(format "New %s" file))
((mode)
(format "New mode %s" file))
((deleted)
(format "Deleted %s" file))
((renamed)
(format "Renamed %s (from %s)"
file file2))
((modified)
(format "Modified %s" file))
(
(format "? %s" file)))))
(magit-set-section-info (list status file file2)) (magit-set-section-info (list status file file2))
(insert "\t" status-text "\n") (magit-insert-diff-title status file file2)
(goto-char end) (goto-char end)
(let ((magit-section-hidden-default nil)) (let ((magit-section-hidden-default nil))
(magit-wash-sequence #'magit-wash-hunk)))) (magit-wash-sequence #'magit-wash-hunk))))
@ -1559,15 +1557,22 @@ Please see the manual for a complete description of Magit.
(magit-wash-diff-section) (magit-wash-diff-section)
(goto-char (point-max)))))) (goto-char (point-max))))))
(defun magit-wash-numstat-diffs () (defun magit-wash-raw-diffs ()
(magit-wash-sequence #'magit-wash-numstat-diff)) (magit-wash-sequence #'magit-wash-raw-diff))
(defun magit-wash-numstat-diff () (defun magit-wash-raw-diff ()
(if (looking-at "\\(^[0-9-]+\\)\t\\([0-9-]+\\)\t\\(.*\\)$") (if (looking-at
(let ((added (string-to-number (match-string 1))) ":\\([0-7]+\\) \\([0-7]+\\) [0-9a-f]+ [0-9a-f]+ \\(.\\)[0-9]*\t\\([^\t\n]+\\)$")
(deleted (string-to-number (match-string 2))) (let ((old-perm (match-string-no-properties 1))
(file (match-string-no-properties 3)) (new-perm (match-string-no-properties 2))
(magit-section-hidden-default magit-hide-diffs)) (status (case (string-to-char (match-string-no-properties 3))
(?A 'new)
(?D 'deleted)
(?M 'modified)
(?U 'unmerged)
(?T 'new-type)
(t nil)))
(file (match-string-no-properties 4)))
;; The 'diff' section that is created here will not work with ;; The 'diff' section that is created here will not work with
;; magit-insert-diff-item-patch etc when we leave it empty. ;; magit-insert-diff-item-patch etc when we leave it empty.
;; Luckily, numstat diffs are only produced for staged and ;; Luckily, numstat diffs are only produced for staged and
@ -1576,12 +1581,11 @@ Please see the manual for a complete description of Magit.
;; brittle, of course. ;; brittle, of course.
(magit-with-section file 'diff (magit-with-section file 'diff
(delete-region (point) (+ (line-end-position) 1)) (delete-region (point) (+ (line-end-position) 1))
(if (or (not (magit-section-hidden magit-top-section)) (if (not (magit-section-hidden magit-top-section))
(< (+ added deleted) 20))
(magit-insert-diff file) (magit-insert-diff file)
(magit-set-section-info (list 'modified file nil)) (magit-set-section-info (list status file nil))
(magit-set-section-needs-refresh-on-show t) (magit-set-section-needs-refresh-on-show t)
(insert (format "\tModified %s\n" file)))) (magit-insert-diff-title status file nil)))
t) t)
nil)) nil))
@ -1690,8 +1694,8 @@ Please see the manual for a complete description of Magit.
(defun magit-insert-unstaged-changes (title) (defun magit-insert-unstaged-changes (title)
(let ((magit-hide-diffs t)) (let ((magit-hide-diffs t))
(let ((magit-diff-options '())) (let ((magit-diff-options '()))
(magit-git-section 'unstaged title 'magit-wash-numstat-diffs (magit-git-section 'unstaged title 'magit-wash-raw-diffs
"diff" "--numstat")))) "diff-files"))))
(defun magit-insert-staged-changes (no-commit) (defun magit-insert-staged-changes (no-commit)
(let ((magit-hide-diffs t) (let ((magit-hide-diffs t)
@ -1699,8 +1703,8 @@ Please see the manual for a complete description of Magit.
(magit-git-string "mktree") (magit-git-string "mktree")
"HEAD"))) "HEAD")))
(let ((magit-diff-options '("--cached"))) (let ((magit-diff-options '("--cached")))
(magit-git-section 'staged "Staged changes:" 'magit-wash-numstat-diffs (magit-git-section 'staged "Staged changes:" 'magit-wash-raw-diffs
"diff" "--cached" "--numstat" "diff-index" "--cached"
base)))) base))))
;;; Logs and Commits ;;; Logs and Commits