@matheusbsbs / matheus-bagliano / commits / 3844814755
Fork 0

git.el: Avoid appending a signoff line that is already present.

Also avoid inserting an extra newline if other signoff lines are present. 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:21 UTC 38448147553917c584a353ed6c39ad55b037f694
1 file changed +18 -6
contrib/emacs/git.el
+18 -6
@@ -891,6 +891,18 @@ and returns the process output as a string."
891 (with-current-buffer log-edit-parent-buffer
892 (git-get-filenames (git-marked-files-state 'added 'deleted 'modified))))
893
894 +(defun git-append-sign-off (name email)
895 + "Append a Signed-off-by entry to the current buffer, avoiding duplicates."
896 + (let ((sign-off (format "Signed-off-by: %s <%s>" name email))
897 + (case-fold-search t))
898 + (goto-char (point-min))
899 + (unless (re-search-forward (concat "^" (regexp-quote sign-off)) nil t)
900 + (goto-char (point-min))
901 + (unless (re-search-forward "^Signed-off-by: " nil t)
902 + (setq sign-off (concat "\n" sign-off)))
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)
@@ -899,6 +911,8 @@ and returns the process output as a string."
911 (merge-heads (git-get-merge-heads))
912 (dir default-directory)
913 (coding-system (git-get-commits-coding-system))
914 + (committer-name (git-get-committer-name))
915 + (committer-email (git-get-committer-email))
916 (sign-off git-append-signed-off-by))
917 (with-current-buffer buffer
918 (when (eq 0 (buffer-size))
@@ -907,7 +921,7 @@ and returns the process output as a string."
921 (insert
922 (propertize
923 (format "Author: %s <%s>\n%s"
910 - (git-get-committer-name) (git-get-committer-email)
924 + committer-name committer-email
925 (if merge-heads
926 (format "Parent: %s\n%s\n"
927 (git-rev-parse "HEAD")
@@ -916,11 +930,9 @@ and returns the process output as a string."
930 'face 'git-header-face)
931 (propertize git-log-msg-separator 'face 'git-separator-face)
932 "\n")
919 - (cond ((file-readable-p ".git/MERGE_MSG")
920 - (insert-file-contents ".git/MERGE_MSG"))
921 - (sign-off
922 - (insert (format "\n\nSigned-off-by: %s <%s>\n"
923 - (git-get-committer-name) (git-get-committer-email)))))))
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))))
936 (log-edit #'git-do-commit nil #'git-log-edit-files buffer)
937 (setq font-lock-keywords (font-lock-compile-keywords git-log-edit-font-lock-keywords))
938 (setq buffer-file-coding-system coding-system)