Abstract out a magit-log-edit-toggle-field function.
This commit is contained in:
parent
5744d3ec98
commit
40fca42d92
1 changed files with 21 additions and 15 deletions
36
magit.el
36
magit.el
|
@ -3142,6 +3142,23 @@ Prefix arg means justify as well."
|
|||
(defun magit-log-edit-get-field (name)
|
||||
(cdr (assq name (magit-log-edit-get-fields))))
|
||||
|
||||
(defun magit-log-edit-toggle-field (name default)
|
||||
"Toggle the log-edit field named NAME.
|
||||
If it's currently unset, set it to DEFAULT (t or nil).
|
||||
|
||||
Return nil if the field is toggled off, and non-nil if it's
|
||||
toggled on. When it's toggled on for the first time, return
|
||||
'first."
|
||||
(let* ((fields (magit-log-edit-get-fields))
|
||||
(cell (assq name fields)) yesp)
|
||||
(if cell
|
||||
(progn
|
||||
(setq yesp (equal (cdr cell) "yes"))
|
||||
(rplacd cell (if yesp "no" "yes")))
|
||||
(setq fields (acons name (if default "yes" "no") fields))
|
||||
(setq yesp (if default 'first)))
|
||||
(magit-log-edit-set-fields fields)))
|
||||
|
||||
(defun magit-log-edit-setup-author-env (author)
|
||||
(cond (author
|
||||
;; XXX - this is a bit strict, probably.
|
||||
|
@ -3220,26 +3237,15 @@ Prefix arg means justify as well."
|
|||
"Toggle whether this will be an amendment to the previous commit.
|
||||
\(i.e., whether eventual commit does 'git commit --amend')"
|
||||
(interactive)
|
||||
(let* ((fields (magit-log-edit-get-fields))
|
||||
(cell (assq 'amend fields)))
|
||||
(if cell
|
||||
(rplacd cell (if (equal (cdr cell) "yes") "no" "yes"))
|
||||
(setq fields (acons 'amend "yes" fields))
|
||||
(magit-log-edit-append
|
||||
(magit-format-commit "HEAD" "%s%n%n%b")))
|
||||
(magit-log-edit-set-fields fields)))
|
||||
(when (eq (magit-log-edit-toggle-field 'amend t) 'first)
|
||||
(magit-log-edit-append
|
||||
(magit-format-commit "HEAD" "%s%n%n%b"))))
|
||||
|
||||
(defun magit-log-edit-toggle-signoff ()
|
||||
"Toggle whether this commit will include a signoff.
|
||||
\(i.e., whether eventual commit does 'git commit --signoff')"
|
||||
(interactive)
|
||||
(let* ((fields (magit-log-edit-get-fields))
|
||||
(cell (assq 'sign-off fields)))
|
||||
(if cell
|
||||
(rplacd cell (if (equal (cdr cell) "yes") "no" "yes"))
|
||||
(setq fields (acons 'sign-off (if magit-commit-signoff "no" "yes")
|
||||
fields)))
|
||||
(magit-log-edit-set-fields fields)))
|
||||
(magit-log-edit-toggle-field 'sign-off (not magit-commit-signoff)))
|
||||
|
||||
(defun magit-pop-to-log-edit (operation)
|
||||
(let ((dir default-directory)
|
||||
|
|
Loading…
Reference in a new issue