5959
6060(defcustom git-committer-name nil
6161 " User name to use for commits.
62- The default is to fall back to `add-log-full-name' and then `user-full-name' ."
62+ The default is to fall back to the repository config, then to `add-log-full-name' and then to `user-full-name' ."
6363 :group 'git
6464 :type '(choice (const :tag " Default" nil )
6565 (string :tag " Name" )))
6666
6767(defcustom git-committer-email nil
6868 " Email address to use for commits.
69- The default is to fall back to `add-log-mailing-address' and then `user-mail-address' ."
69+ The default is to fall back to the git repository config, then to `add-log-mailing-address' and then to `user-mail-address' ."
7070 :group 'git
7171 :type '(choice (const :tag " Default" nil )
7272 (string :tag " Email" )))
@@ -148,6 +148,12 @@ The default is to fall back to `add-log-mailing-address' and then `user-mail-add
148148 (append (git-get-env-strings env) (list " git" ) args))
149149 (apply #'call-process " git" nil buffer nil args)))
150150
151+ (defun git-call-process-env-string (env &rest args )
152+ " Wrapper for call-process that sets environment strings, and returns the process output as a string."
153+ (with-temp-buffer
154+ (and (eq 0 (apply #' git-call-process-env t env args))
155+ (buffer-string ))))
156+
151157(defun git-run-process-region (buffer start end program args )
152158 " Run a git process with a buffer region as input."
153159 (let ((output-buffer (current-buffer ))
@@ -189,13 +195,15 @@ The default is to fall back to `add-log-mailing-address' and then `user-mail-add
189195
190196(defun git-get-string-sha1 (string )
191197 " Read a SHA1 from the specified string."
192- (let ((pos (string-match " [0-9a-f]\\ {40\\ }" string)))
193- (and pos (substring string pos (match-end 0 )))))
198+ (and string
199+ (string-match " [0-9a-f]\\ {40\\ }" string)
200+ (match-string 0 string)))
194201
195202(defun git-get-committer-name ()
196203 " Return the name to use as GIT_COMMITTER_NAME."
197204 ; copied from log-edit
198205 (or git-committer-name
206+ (git-repo-config " user.name" )
199207 (and (boundp 'add-log-full-name ) add-log-full-name)
200208 (and (fboundp 'user-full-name ) (user-full-name ))
201209 (and (boundp 'user-full-name ) user-full-name)))
@@ -204,6 +212,7 @@ The default is to fall back to `add-log-mailing-address' and then `user-mail-add
204212 " Return the email address to use as GIT_COMMITTER_EMAIL."
205213 ; copied from log-edit
206214 (or git-committer-email
215+ (git-repo-config " user.email" )
207216 (and (boundp 'add-log-mailing-address ) add-log-mailing-address)
208217 (and (fboundp 'user-mail-address ) (user-mail-address ))
209218 (and (boundp 'user-mail-address ) user-mail-address)))
@@ -259,18 +268,17 @@ The default is to fall back to `add-log-mailing-address' and then `user-mail-add
259268(defun git-rev-parse (rev )
260269 " Parse a revision name and return its SHA1."
261270 (git-get-string-sha1
262- (with-output-to-string
263- (with-current-buffer standard-output
264- (git-call-process-env t nil " rev-parse" rev)))))
271+ (git-call-process-env-string nil " rev-parse" rev)))
272+
273+ (defun git-repo-config (key )
274+ " Retrieve the value associated to KEY in the git repository config file."
275+ (let ((str (git-call-process-env-string nil " repo-config" key)))
276+ (and str (car (split-string str " \n " )))))
265277
266278(defun git-symbolic-ref (ref )
267279 " Wrapper for the git-symbolic-ref command."
268- (car
269- (split-string
270- (with-output-to-string
271- (with-current-buffer standard-output
272- (git-call-process-env t nil " symbolic-ref" ref)))
273- " \n " )))
280+ (let ((str (git-call-process-env-string nil " symbolic-ref" ref)))
281+ (and str (car (split-string str " \n " )))))
274282
275283(defun git-update-ref (ref val &optional oldval )
276284 " Update a reference by calling git-update-ref."
@@ -285,11 +293,7 @@ The default is to fall back to `add-log-mailing-address' and then `user-mail-add
285293(defun git-write-tree (&optional index-file )
286294 " Call git-write-tree and return the resulting tree SHA1 as a string."
287295 (git-get-string-sha1
288- (with-output-to-string
289- (with-current-buffer standard-output
290- (git-call-process-env t
291- (if index-file `((" GIT_INDEX_FILE" . , index-file )) nil )
292- " write-tree" )))))
296+ (git-call-process-env-string (and index-file `((" GIT_INDEX_FILE" . , index-file ))) " write-tree" )))
293297
294298(defun git-commit-tree (buffer tree head )
295299 " Call git-commit-tree with buffer as input and return the resulting commit SHA1."
@@ -763,6 +767,16 @@ The default is to fall back to `add-log-mailing-address' and then `user-mail-add
763767 (git-setup-diff-buffer
764768 (apply #'git-run-command-buffer " *git-diff*" " diff-index" " -p" " -M" " HEAD" " --" (git-get-filenames files )))))
765769
770+ (defun git-diff-file-merge-head (arg )
771+ " Diff the marked file(s) against the first merge head (or the nth one with a numeric prefix)."
772+ (interactive " p" )
773+ (let ((files (git-marked-files))
774+ (merge-heads (git-get-merge-heads)))
775+ (unless merge-heads (error " No merge in progress " ))
776+ (git-setup-diff-buffer
777+ (apply #'git-run-command-buffer " *git-diff*" " diff-index" " -p" " -M"
778+ (or (nth (1- arg) merge-heads) " HEAD" ) " --" (git-get-filenames files )))))
779+
766780(defun git-diff-unmerged-file (stage )
767781 " Diff the marked unmerged file(s) against the specified stage."
768782 (let ((files (git-marked-files)))
@@ -955,6 +969,7 @@ The default is to fall back to `add-log-mailing-address' and then `user-mail-add
955969 (define-key diff-map " =" 'git-diff-file )
956970 (define-key diff-map " e" 'git-diff-file-idiff )
957971 (define-key diff-map " E" 'git-find-file-imerge )
972+ (define-key diff-map " h" 'git-diff-file-merge-head )
958973 (define-key diff-map " m" 'git-diff-file-mine )
959974 (define-key diff-map " o" 'git-diff-file-other )
960975 (setq git-status-mode-map map)))
0 commit comments