git.el: Display some information about the HEAD commit.
Use git-log --pretty=oneline to print a short description of the current HEAD (and merge heads if any) in the buffer header. Signed-off-by: Alexandre Julliard <julliard@winehq.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Alexandre Julliard committed
Mar 26, 2007 at 12:16 UTC
b704e589f411d51c7240d104d88422aa2d757822
1 file changed
+20
-2
contrib/emacs/git.el
+20
-2
@@ -263,6 +263,16 @@ and returns the process output as a string."
263
(locale-charset-to-coding-system repo-config))
264
'utf-8)))
265
266
+(defun git-get-logoutput-coding-system ()
267
+ "Return the coding system used for git-log output."
268
+ (let ((repo-config (or (git-config "i18n.logoutputencoding")
269
+ (git-config "i18n.commitencoding"))))
270
+ (or git-commits-coding-system
271
+ (and repo-config
272
+ (fboundp 'locale-charset-to-coding-system)
273
+ (locale-charset-to-coding-system repo-config))
274
+ 'utf-8)))
275
+
276
(defun git-escape-file-name (name)
277
"Escape a file name if necessary."
278
(if (string-match "[\n\t\"\\]" name)
@@ -406,6 +416,14 @@ and returns the process output as a string."
416
(push (match-string 0) heads))))
417
(nreverse heads)))
418
419
+(defun git-get-commit-description (commit)
420
+ "Get a one-line description of COMMIT."
421
+ (let ((coding-system-for-read (git-get-logoutput-coding-system)))
422
+ (let ((descr (git-call-process-env-string nil "log" "--max-count=1" "--pretty=oneline" commit)))
423
+ (if (and descr (string-match "\\`\\([0-9a-f]\\{40\\}\\) *\\(.*\\)$" descr))
424
+ (concat (substring (match-string 1 descr) 0 10) " - " (match-string 2 descr))
425
+ descr))))
426
+
427
;;;; File info structure
428
;;;; ------------------------------------------------------------
429
@@ -573,7 +591,7 @@ and returns the process output as a string."
591
"Refresh the ewoc header and footer."
592
(let ((branch (git-symbolic-ref "HEAD"))
593
(head (if (git-empty-db-p) "Nothing committed yet"
576
- (substring (git-rev-parse "HEAD") 0 10)))
594
+ (git-get-commit-description "HEAD")))
595
(merge-heads (git-get-merge-heads)))
596
(ewoc-set-hf status
597
(format "Directory: %s\nBranch: %s\nHead: %s%s\n"
@@ -584,7 +602,7 @@ and returns the process output as a string."
602
head
603
(if merge-heads
604
(concat "\nMerging: "
587
- (mapconcat (lambda (str) (substring str 0 10)) merge-heads " "))
605
+ (mapconcat (lambda (str) (git-get-commit-description str)) merge-heads "\n "))
606
""))
607
(if (ewoc-nth status 0) "" " No changes."))))
608