git.el: Retrieve commit log information from .dotest directory.
If a git-am or git-rebase is in progress, fill the commit log buffer from the commit information found in the various files in the .dotest directory. Signed-off-by: Alexandre Julliard <julliard@winehq.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Alexandre Julliard committed
Mar 10, 2007 at 19:22 UTC
60fa08ed617dd148a9843bfdef2dfecf2ef60123
1 file changed
+53
-24
contrib/emacs/git.el
+53
-24
@@ -903,36 +903,65 @@ and returns the process output as a string."
903
(goto-char (point-max))
904
(insert sign-off "\n"))))
905
906
-(defun git-commit-file ()
907
- "Commit the marked file(s), asking for a commit message."
908
- (interactive)
906
+(defun git-setup-log-buffer (buffer &optional author-name author-email subject date msg)
907
+ "Setup the log buffer for a commit."
908
(unless git-status (error "Not in git-status buffer."))
910
- (let ((buffer (get-buffer-create "*git-commit*"))
911
- (merge-heads (git-get-merge-heads))
909
+ (let ((merge-heads (git-get-merge-heads))
910
(dir default-directory)
913
- (coding-system (git-get-commits-coding-system))
911
(committer-name (git-get-committer-name))
912
(committer-email (git-get-committer-email))
913
(sign-off git-append-signed-off-by))
914
(with-current-buffer buffer
918
- (when (eq 0 (buffer-size))
919
- (cd dir)
920
- (erase-buffer)
921
- (insert
922
- (propertize
923
- (format "Author: %s <%s>\n%s"
924
- committer-name committer-email
925
- (if merge-heads
926
- (format "Parent: %s\n%s\n"
927
- (git-rev-parse "HEAD")
928
- (mapconcat (lambda (str) (concat "Parent: " str)) merge-heads "\n"))
929
- ""))
930
- 'face 'git-header-face)
931
- (propertize git-log-msg-separator 'face 'git-separator-face)
932
- "\n")
933
- (when (file-readable-p ".git/MERGE_MSG")
934
- (insert-file-contents ".git/MERGE_MSG"))
935
- (when sign-off (git-append-sign-off committer-name committer-email))))
915
+ (cd dir)
916
+ (erase-buffer)
917
+ (insert
918
+ (propertize
919
+ (format "Author: %s <%s>\n%s%s"
920
+ (or author-name committer-name)
921
+ (or author-email committer-email)
922
+ (if date (format "Date: %s\n" date) "")
923
+ (if merge-heads
924
+ (format "Parent: %s\n%s\n"
925
+ (git-rev-parse "HEAD")
926
+ (mapconcat (lambda (str) (concat "Parent: " str)) merge-heads "\n"))
927
+ ""))
928
+ 'face 'git-header-face)
929
+ (propertize git-log-msg-separator 'face 'git-separator-face)
930
+ "\n")
931
+ (when subject (insert subject "\n\n"))
932
+ (cond (msg (insert msg "\n"))
933
+ ((file-readable-p ".dotest/msg")
934
+ (insert-file-contents ".dotest/msg"))
935
+ ((file-readable-p ".git/MERGE_MSG")
936
+ (insert-file-contents ".git/MERGE_MSG")))
937
+ ; delete empty lines at end
938
+ (goto-char (point-min))
939
+ (when (re-search-forward "\n+\\'" nil t)
940
+ (replace-match "\n" t t))
941
+ (when sign-off (git-append-sign-off committer-name committer-email)))))
942
+
943
+(defun git-commit-file ()
944
+ "Commit the marked file(s), asking for a commit message."
945
+ (interactive)
946
+ (unless git-status (error "Not in git-status buffer."))
947
+ (let ((buffer (get-buffer-create "*git-commit*"))
948
+ (coding-system (git-get-commits-coding-system))
949
+ author-name author-email subject date)
950
+ (when (eq 0 (buffer-size buffer))
951
+ (when (file-readable-p ".dotest/info")
952
+ (with-temp-buffer
953
+ (insert-file-contents ".dotest/info")
954
+ (goto-char (point-min))
955
+ (when (re-search-forward "^Author: \\(.*\\)\nEmail: \\(.*\\)$" nil t)
956
+ (setq author-name (match-string 1))
957
+ (setq author-email (match-string 2)))
958
+ (goto-char (point-min))
959
+ (when (re-search-forward "^Subject: \\(.*\\)$" nil t)
960
+ (setq subject (match-string 1)))
961
+ (goto-char (point-min))
962
+ (when (re-search-forward "^Date: \\(.*\\)$" nil t)
963
+ (setq date (match-string 1)))))
964
+ (git-setup-log-buffer buffer author-name author-email subject date))
965
(log-edit #'git-do-commit nil #'git-log-edit-files buffer)
966
(setq font-lock-keywords (font-lock-compile-keywords git-log-edit-font-lock-keywords))
967
(setq buffer-file-coding-system coding-system)