git.el: Add a commit description to the reflog.
Add a description of the commit to the reflog using the first line of the log message, the same way the git-commit script does it. Signed-off-by: Alexandre Julliard <julliard@winehq.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Alexandre Julliard committed
Apr 19, 2007 at 13:16 UTC
413689d36f9b98c57bff9510ac4cdfb40e4ef9fc
1 file changed
+28
-14
contrib/emacs/git.el
+28
-14
@@ -345,9 +345,15 @@ and returns the process output as a string."
345
(let ((str (git-call-process-env-string nil "symbolic-ref" ref)))
346
(and str (car (split-string str "\n")))))
347
348
-(defun git-update-ref (ref val &optional oldval)
348
+(defun git-update-ref (ref newval &optional oldval reason)
349
"Update a reference by calling git-update-ref."
350
- (apply #'git-call-process-env nil nil "update-ref" ref val (if oldval (list oldval))))
350
+ (let ((args (and oldval (list oldval))))
351
+ (push newval args)
352
+ (push ref args)
353
+ (when reason
354
+ (push reason args)
355
+ (push "-m" args))
356
+ (eq 0 (apply #'git-call-process-env nil nil "update-ref" args))))
357
358
(defun git-read-tree (tree &optional index-file)
359
"Read a tree into the index file."
@@ -364,8 +370,10 @@ and returns the process output as a string."
370
"Call git-commit-tree with buffer as input and return the resulting commit SHA1."
371
(let ((author-name (git-get-committer-name))
372
(author-email (git-get-committer-email))
373
+ (subject "commit (initial): ")
374
author-date log-start log-end args coding-system-for-write)
375
(when head
376
+ (setq subject "commit: ")
377
(push "-p" args)
378
(push head args))
379
(with-current-buffer buffer
@@ -384,22 +392,29 @@ and returns the process output as a string."
392
(goto-char (point-min))
393
(while (re-search-forward "^Parent: +\\([0-9a-f]+\\)" nil t)
394
(unless (string-equal head (match-string 1))
395
+ (setq subject "commit (merge): ")
396
(push "-p" args)
397
(push (match-string 1) args))))
398
(setq log-start (point-min)))
399
(setq log-end (point-max))
400
+ (goto-char log-start)
401
+ (when (re-search-forward ".*$" nil t)
402
+ (setq subject (concat subject (match-string 0))))
403
(setq coding-system-for-write buffer-file-coding-system))
392
- (git-get-string-sha1
393
- (with-output-to-string
394
- (with-current-buffer standard-output
395
- (let ((env `(("GIT_AUTHOR_NAME" . ,author-name)
396
- ("GIT_AUTHOR_EMAIL" . ,author-email)
397
- ("GIT_COMMITTER_NAME" . ,(git-get-committer-name))
398
- ("GIT_COMMITTER_EMAIL" . ,(git-get-committer-email)))))
399
- (when author-date (push `("GIT_AUTHOR_DATE" . ,author-date) env))
400
- (apply #'git-run-command-region
401
- buffer log-start log-end env
402
- "commit-tree" tree (nreverse args))))))))
404
+ (let ((commit
405
+ (git-get-string-sha1
406
+ (with-output-to-string
407
+ (with-current-buffer standard-output
408
+ (let ((env `(("GIT_AUTHOR_NAME" . ,author-name)
409
+ ("GIT_AUTHOR_EMAIL" . ,author-email)
410
+ ("GIT_COMMITTER_NAME" . ,(git-get-committer-name))
411
+ ("GIT_COMMITTER_EMAIL" . ,(git-get-committer-email)))))
412
+ (when author-date (push `("GIT_AUTHOR_DATE" . ,author-date) env))
413
+ (apply #'git-run-command-region
414
+ buffer log-start log-end env
415
+ "commit-tree" tree (nreverse args))))))))
416
+ (and (git-update-ref "HEAD" commit head subject)
417
+ commit))))
418
419
(defun git-empty-db-p ()
420
"Check if the git db is empty (no commit done yet)."
@@ -662,7 +677,6 @@ and returns the process output as a string."
677
(if (or (not (string-equal tree head-tree))
678
(yes-or-no-p "The tree was not modified, do you really want to perform an empty commit? "))
679
(let ((commit (git-commit-tree buffer tree head)))
665
- (git-update-ref "HEAD" commit head)
680
(condition-case nil (delete-file ".git/MERGE_HEAD") (error nil))
681
(condition-case nil (delete-file ".git/MERGE_MSG") (error nil))
682
(with-current-buffer buffer (erase-buffer))