Function: vc-git--mailinfo

vc-git--mailinfo is a byte-compiled function defined in vc-git.el.gz.

Signature

(vc-git--mailinfo PATCH-STRING)

Documentation

Pipe PATCH-STRING to git-mailinfo(1) and return an alist of its output.

The alist always contains an entry with key message. This contains the commit log message. In the case that there is also an alist entry with key "Subject", the first line of the commit message is missing from the message entry. To recover the full commit message, concatenate the "Subject" and message entries, interpolating two newline characters.

The alist also always contains an entry with key patch. This contains the patch extracted from PATCH-STRING. If there is text in PATCH-STRING occurring before the actual hunks but after the commit message, separated from the latter with a line consisting of three hyphens, then that extra text is included in this alist entry. (This space between the line of three hyphens and the hunks is conventionally used for a diffstat, and/or additional explanatory text submitted with the patch but not to be included in the commit log message.)

The remaining entries in the alist correspond to the information returned by git-mailinfo(1) on standard output. These specify the authorship and date information for the commit, and sometimes the first line of the commit message in an entry with key "Subject".

Source Code

;; Defined in /usr/src/emacs/lisp/vc/vc-git.el.gz
(defun vc-git--mailinfo (patch-string)
  "Pipe PATCH-STRING to git-mailinfo(1) and return an alist of its output.

The alist always contains an entry with key `message'.
This contains the commit log message.
In the case that there is also an alist entry with key \"Subject\", the
first line of the commit message is missing from the `message' entry.
To recover the full commit message, concatenate the \"Subject\" and
`message' entries, interpolating two newline characters.

The alist also always contains an entry with key `patch'.
This contains the patch extracted from PATCH-STRING.
If there is text in PATCH-STRING occurring before the actual hunks but
after the commit message, separated from the latter with a line
consisting of three hyphens, then that extra text is included in this
alist entry.  (This space between the line of three hyphens and the
hunks is conventionally used for a diffstat, and/or additional
explanatory text submitted with the patch but not to be included in the
commit log message.)

The remaining entries in the alist correspond to the information
returned by git-mailinfo(1) on standard output.  These specify the
authorship and date information for the commit, and sometimes the first
line of the commit message in an entry with key \"Subject\"."
  (let ((input-file (make-nearby-temp-file "git-mailinfo-input"))
        (msg-file (make-nearby-temp-file "git-mailinfo-msg"))
        (patch-file (make-nearby-temp-file "git-mailinfo-patch"))
        (coding-system-for-read (or coding-system-for-read
                                    vc-git-log-output-coding-system))
        res)
    (unwind-protect
        (with-temp-buffer
          (let ((coding-system-for-write
                 ;; Git expects Unix line endings here even on Windows.
                 (coding-system-change-eol-conversion
                  (or coding-system-for-write vc-git-commits-coding-system)
                  'unix)))
            (with-temp-file input-file
              (insert patch-string)))
          (let ((coding-system-for-write
                 ;; On MS-Windows, we must encode command-line arguments
                 ;; in the system codepage.
                 (if (eq system-type 'windows-nt)
                     locale-coding-system
                   coding-system-for-write)))
            (vc-git--call input-file t "mailinfo" msg-file patch-file))
          (goto-char (point-min))
          ;; git-mailinfo joins up any header continuation lines for us.
          (while (re-search-forward "^\\([^\t\n\s:]+\\):\\(.*\\)$" nil t)
            (push (cons (match-string 1) (string-trim (match-string 2)))
                  res))
          (erase-buffer)
          (insert-file-contents-literally patch-file)
          (push (cons 'patch (buffer-string)) res)
          (erase-buffer)
          (insert-file-contents-literally msg-file)
          (push (cons 'message (string-trim (buffer-string))) res))
      (dolist (file (list input-file msg-file patch-file))
        (when (file-exists-p file)
          (delete-file file))))
    res))