aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Sim <russell.sim@gmail.com>2022-09-19 22:12:50 +0200
committerYuchen Pei <id@ypei.org>2023-10-01 00:10:52 +1000
commit528647fa3ab01b384a9a98a5d9529de7295ad716 (patch)
treecb4f3070b097740e6f656be6cc8d83b1385010ed
parentb5ebade3a48dc0ce0c85699f25800808233c73be (diff)
git-email-magit: base git-email-patch-send off magit-patch-createHEADmaster
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 <russell.sim@gmail.com>
-rw-r--r--git-email-magit.el46
1 files 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))