diff options
Diffstat (limited to 'git-email.el')
-rw-r--r-- | git-email.el | 62 |
1 files changed, 45 insertions, 17 deletions
diff --git a/git-email.el b/git-email.el index 21a49a5..0a6cd37 100644 --- a/git-email.el +++ b/git-email.el @@ -91,6 +91,11 @@ in you git config. If the variable is not set, the 'to' address will be empty." :type '(string) :group 'git-email) +(defcustom git-email-revision-limit 100 + "How many revisions to show when in `git-email-format-patch'." + :type 'int + :group 'git-email) + ;; Compile warnings (declare-function dired-get-filename "dired.el") (declare-function dired-map-over-marks "dired.el") @@ -184,6 +189,42 @@ If no marks are found, return the filename at point." (when (mapcar 'git-email--check-file files) files))) +(defun git-email--get-revision () + "Let the user choose a git revision from the minibuffer." + (interactive) + (let* ((default-directory (cdr (project-current))) + ;; Last element is an empty string + (revs (butlast (split-string + (shell-command-to-string + (concat + "git log --no-color --date=short " + "--pretty='format:%h %d %s'" + " --abbrev-commit -n " + (int-to-string git-email-revision-limit))) + "\n"))) + ;; Colorize + (colored-revs + (mapcar (lambda (rev) (concat + (propertize + (replace-regexp-in-string "\\([a-f0-9]+\\) .*$" + "\\1" rev) + 'face 'log-view-commit-body) + (propertize + (replace-regexp-in-string "[a-f0-9]+ \\(.*$\\)" + "\\1" rev) + 'face 'default))) + revs)) + ;; Sort the candidates correctly. + ;; See https://emacs.stackexchange.com/a/41808. + (sorted-revs + (lambda (string pred action) + (if (eq action 'metadata) + '(metadata (display-sort-function . identity) + (cycle-sort-function . identity)) + (complete-with-action + action colored-revs string pred))))) + (substring (completing-read "Revision: " sorted-revs) 0 7))) + ;;;###autoload (defun git-email-apply-patch (project) "Apply the patch in the current buffer using 'git am' in PROJECT." @@ -209,20 +250,7 @@ With optional ARGS (\\[universal-argument]) you can specify extra arguments to give to 'git format-patch'. By default, the arguments in `git-email-format-patch-default-args' will be used." (interactive "P") - (let* ((default-directory (cdr (project-current))) - (revs (split-string (shell-command-to-string - "git log --format='%h %d %s'") - "\n")) - ;; Sort the candidates correctly. - ;; See https://emacs.stackexchange.com/a/41808. - (sorted-revs - (lambda (string pred action) - (if (eq action 'metadata) - '(metadata (display-sort-function . identity) - (cycle-sort-function . identity)) - (complete-with-action - action revs string pred)))) - (rev (substring (completing-read "Revision: " sorted-revs) 0 7)) + (let* ((rev (git-email--get-revision)) ;; Extra arguments. (args (if args (apply @@ -230,13 +258,13 @@ arguments in `git-email-format-patch-default-args' will be used." (lambda (a) (concat a " ")) (list (completing-read-multiple "Args: " - git-email-format-patch-extra-args)))) + git-email-format-patch-extra-args)))) git-email-format-patch-default-args)) ;; List of patches generated, the last element is an empty string ;; so remove it. Reverse the list so we edit the cover letter first. (files (nreverse (butlast (split-string (shell-command-to-string - (concat "git format-patch " args " " rev)) - "\n"))))) + (concat "git format-patch " args " " rev)) + "\n"))))) (dolist (file files) (run-hooks 'git-email-pre-compose-email-hook) (git-email--compose-email file) |