@matheusbsbs / matheus-bagliano / commits / 40f162b04b
Fork 0

git.el: Display file types and type changes.

Handle the T status from git-diff-index to display type changes between file/symlink/subproject. Also always show the file type for symlink and subprojects to indicate that they are not normal files. Signed-off-by: Alexandre Julliard <julliard@winehq.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Alexandre Julliard committed Jan 6, 2008 at 12:13 UTC 40f162b04b3d5155a7e41d27c9f52383a5fa5a9f
1 file changed +31 -3
contrib/emacs/git.el
+31 -3
@@ -489,8 +489,7 @@ and returns the process output as a string."
489 "Set the state of a file info."
490 (unless (eq (git-fileinfo->state info) state)
491 (setf (git-fileinfo->state info) state
492 - (git-fileinfo->old-perm info) 0
493 - (git-fileinfo->new-perm info) 0
492 + (git-fileinfo->new-perm info) (git-fileinfo->old-perm info)
493 (git-fileinfo->rename-state info) nil
494 (git-fileinfo->orig-name info) nil
495 (git-fileinfo->needs-refresh info) t)))
@@ -524,6 +523,7 @@ and returns the process output as a string."
523 (?A 'added)
524 (?D 'deleted)
525 (?U 'unmerged)
526 + (?T 'modified)
527 (t nil)))
528
529 (defun git-status-code-as-string (code)
@@ -538,6 +538,33 @@ and returns the process output as a string."
538 ('ignored (propertize "Ignored " 'face 'git-ignored-face))
539 (t "? ")))
540
541 +(defun git-file-type-as-string (info)
542 + "Return a string describing the file type of INFO."
543 + (let* ((old-type (lsh (or (git-fileinfo->old-perm info) 0) -9))
544 + (new-type (lsh (or (git-fileinfo->new-perm info) 0) -9))
545 + (str (case new-type
546 + (?\100 ;; file
547 + (case old-type
548 + (?\100 nil)
549 + (?\120 " (type change symlink -> file)")
550 + (?\160 " (type change subproject -> file)")))
551 + (?\120 ;; symlink
552 + (case old-type
553 + (?\100 " (type change file -> symlink)")
554 + (?\160 " (type change subproject -> symlink)")
555 + (t " (symlink)")))
556 + (?\160 ;; subproject
557 + (case old-type
558 + (?\100 " (type change file -> subproject)")
559 + (?\120 " (type change symlink -> subproject)")
560 + (t " (subproject)")))
561 + (?\000 ;; deleted or unknown
562 + (case old-type
563 + (?\120 " (symlink)")
564 + (?\160 " (subproject)")))
565 + (t (format " (unknown type %o)" new-type)))))
566 + (if str (propertize str 'face 'git-status-face) "")))
567 +
568 (defun git-rename-as-string (info)
569 "Return a string describing the copy or rename associated with INFO, or an empty string if none."
570 (let ((state (git-fileinfo->rename-state info)))
@@ -567,6 +594,7 @@ and returns the process output as a string."
594 " " (git-status-code-as-string (git-fileinfo->state info))
595 " " (git-permissions-as-string (git-fileinfo->old-perm info) (git-fileinfo->new-perm info))
596 " " (git-escape-file-name (git-fileinfo->name info))
597 + (git-file-type-as-string info)
598 (git-rename-as-string info))))
599
600 (defun git-insert-info-list (status infolist)
@@ -603,7 +631,7 @@ Return the list of files that haven't been handled."
631 (apply #'git-call-process-env t nil "diff-index" "-z" "-M" "HEAD" "--" files)
632 (goto-char (point-min))
633 (while (re-search-forward
606 - ":\\([0-7]\\{6\\}\\) \\([0-7]\\{6\\}\\) [0-9a-f]\\{40\\} [0-9a-f]\\{40\\} \\(\\([ADMU]\\)\0\\([^\0]+\\)\\|\\([CR]\\)[0-9]*\0\\([^\0]+\\)\0\\([^\0]+\\)\\)\0"
634 + ":\\([0-7]\\{6\\}\\) \\([0-7]\\{6\\}\\) [0-9a-f]\\{40\\} [0-9a-f]\\{40\\} \\(\\([ADMUT]\\)\0\\([^\0]+\\)\\|\\([CR]\\)[0-9]*\0\\([^\0]+\\)\0\\([^\0]+\\)\\)\0"
635 nil t 1)
636 (let ((old-perm (string-to-number (match-string 1) 8))
637 (new-perm (string-to-number (match-string 2) 8))