From 528647fa3ab01b384a9a98a5d9529de7295ad716 Mon Sep 17 00:00:00 2001 From: Russell Sim Date: Mon, 19 Sep 2022 22:12:50 +0200 Subject: git-email-magit: base git-email-patch-send off magit-patch-create This bases the implementation of git-email-patch-send off the magit upstream magit-patch-create. This makes it more intuitive since it's not defining a different way to work with patches. This means by default you'll be presented with a revision range prompt with the expectation that you would use a range like upstream/master..master or something to calculate the patches to be created. This on the surface seems more complicated than just choosing a starting point, but it's more powerful and simple range selection can be done interactively using the log buffer. If you want to create a single patch thing can be done by pressing `C-SPC` in the magit log buffer on a single commit then proceeding with `W c s` or you can create any arbitrary interactive range via `C-SPC` and navigating around the log. Signed-off-by: Russell Sim --- git-email-magit.el | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/git-email-magit.el b/git-email-magit.el index fd4e001..f35117e 100644 --- a/git-email-magit.el +++ b/git-email-magit.el @@ -31,28 +31,36 @@ (require 'git-email) (require 'transient) +(require 'magit-process) (require 'magit-patch) -(require 'magit-log) -(defun git-email--escape-string (str) - "Escape STR if it has spaces in it." - (if (string-match-p "\s" str) - (format "\"%s\"" str) - str)) - -;;;###autoload -(defun git-email-magit-patch-send (args &optional commit) +(defun git-email-magit-patch-send (range args files) + "Send a set of patches via email." + ;; This is largely copied from magit-patch's `magit-patch-create' + ;; function. (interactive - (let ((args (transient-args 'magit-patch-create))) - (list (mapconcat #'git-email--escape-string - (seq-filter #'stringp args) - " ")))) - ;; For some reason, `git-email-format-patch' gets called before - ;; `magit-log-select' has retunred anything, leading to an error. - (if commit - (git-email-format-patch args commit nil) - (magit-log-select (lambda (commit) - (git-email-magit-patch-send args commit))))) + (if (not (eq transient-current-command 'magit-patch-create)) + (list nil nil nil) + (cons (if-let ((revs (magit-region-values 'commit))) + (if (length= revs 1) + (list "-1" (car revs)) + (concat (car (last revs)) "^.." (car revs))) + (let ((range (magit-read-range-or-commit + "Format range or commit"))) + (if (string-search ".." range) + range + (format "%s~..%s" range range)))) + (let ((args (transient-args 'magit-patch-create))) + (list (-filter #'stringp args) + (cdr (assoc "--" args))))))) + (let ((files (nreverse + (split-string + (magit--with-temp-process-buffer + (let* ((status (magit-process-git t "format-patch" range args "--" files)) + (output (buffer-string))) + output)))))) + (git-email--send-files files) + (mapc #'delete-file files))) (transient-append-suffix 'magit-patch-create "c" '(1 "s" "Send patch" git-email-magit-patch-send)) -- cgit v1.2.3