@matheusbsbs / matheus-bagliano / commits / 14b4f2dbd1
Fork 0

git.el: Set the default commit coding system from the repository config.

If not otherwise specified, take the default coding system for commits from the 'i18n.commitencoding' repository configuration value. Also set the buffer-file-coding-system variable in the log buffer to make the selected coding system visible on the modeline. Signed-off-by: Alexandre Julliard <julliard@winehq.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Alexandre Julliard committed Feb 28, 2007 at 20:59 UTC 14b4f2dbd10c0c5f25ed7804eb5e803637231b32
1 file changed +18 -6
contrib/emacs/git.el
+18 -6
@@ -75,10 +75,11 @@ then to `add-log-mailing-address' and then to `user-mail-address'."
75 :type '(choice (const :tag "Default" nil)
76 (string :tag "Email")))
77
78 -(defcustom git-commits-coding-system 'utf-8
78 +(defcustom git-commits-coding-system nil
79 "Default coding system for the log message of git commits."
80 :group 'git
81 - :type 'coding-system)
81 + :type '(choice (const :tag "From repository config" nil)
82 + (coding-system)))
83
84 (defcustom git-append-signed-off-by nil
85 "Whether to append a Signed-off-by line to the commit message before editing."
@@ -236,6 +237,15 @@ and returns the process output as a string."
237 (and (fboundp 'user-mail-address) (user-mail-address))
238 (and (boundp 'user-mail-address) user-mail-address)))
239
240 +(defun git-get-commits-coding-system ()
241 + "Return the coding system to use for commits."
242 + (let ((repo-config (git-config "i18n.commitencoding")))
243 + (or git-commits-coding-system
244 + (and repo-config
245 + (fboundp 'locale-charset-to-coding-system)
246 + (locale-charset-to-coding-system repo-config))
247 + 'utf-8)))
248 +
249 (defun git-escape-file-name (name)
250 "Escape a file name if necessary."
251 (if (string-match "[\n\t\"\\]" name)
@@ -327,7 +337,7 @@ and returns the process output as a string."
337 "Call git-commit-tree with buffer as input and return the resulting commit SHA1."
338 (let ((author-name (git-get-committer-name))
339 (author-email (git-get-committer-email))
330 - author-date log-start log-end args)
340 + author-date log-start log-end args coding-system-for-write)
341 (when head
342 (push "-p" args)
343 (push head args))
@@ -350,12 +360,12 @@ and returns the process output as a string."
360 (push "-p" args)
361 (push (match-string 1) args))))
362 (setq log-start (point-min)))
353 - (setq log-end (point-max)))
363 + (setq log-end (point-max))
364 + (setq coding-system-for-write buffer-file-coding-system))
365 (git-get-string-sha1
366 (with-output-to-string
367 (with-current-buffer standard-output
357 - (let ((coding-system-for-write git-commits-coding-system)
358 - (env `(("GIT_AUTHOR_NAME" . ,author-name)
368 + (let ((env `(("GIT_AUTHOR_NAME" . ,author-name)
369 ("GIT_AUTHOR_EMAIL" . ,author-email)
370 ("GIT_COMMITTER_NAME" . ,(git-get-committer-name))
371 ("GIT_COMMITTER_EMAIL" . ,(git-get-committer-email)))))
@@ -888,6 +898,7 @@ and returns the process output as a string."
898 (let ((buffer (get-buffer-create "*git-commit*"))
899 (merge-heads (git-get-merge-heads))
900 (dir default-directory)
901 + (coding-system (git-get-commits-coding-system))
902 (sign-off git-append-signed-off-by))
903 (with-current-buffer buffer
904 (when (eq 0 (buffer-size))
@@ -912,6 +923,7 @@ and returns the process output as a string."
923 (git-get-committer-name) (git-get-committer-email)))))))
924 (log-edit #'git-do-commit nil #'git-log-edit-files buffer)
925 (setq font-lock-keywords (font-lock-compile-keywords git-log-edit-font-lock-keywords))
926 + (setq buffer-file-coding-system coding-system)
927 (re-search-forward (regexp-quote (concat git-log-msg-separator "\n")) nil t)))
928
929 (defun git-find-file ()