From 5495e23781c5223ad9caaa1cbe3a0d0500512812 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Sat, 6 Jun 2020 11:48:39 -0400 Subject: Extract patch information from a buffer rather than files piem-am will become a command that works with mboxes outside of -b4. In this context, it's easier and cleaner to deal with a buffer than temporary files. --- piem-b4.el | 7 +++++-- piem.el | 23 +++++++++++------------ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/piem-b4.el b/piem-b4.el index a5530e3..487b548 100644 --- a/piem-b4.el +++ b/piem-b4.el @@ -121,9 +121,12 @@ (read-directory-name "Git repository: "))) (`(,cover ,mbox-file) (piem-b4--get-am-files mid coderepo args)) - (info (piem-series-info cover mbox-file)) (default-directory coderepo)) - (piem-am mbox-file info coderepo))) + (piem-am mbox-file + (with-temp-buffer + (insert-file-contents (or cover mbox-file)) + (piem-extract-mbox-info)) + coderepo))) (define-infix-argument piem-b4-am:--outdir () :description "Output directory" diff --git a/piem.el b/piem.el index 7b51d34..80e8a35 100644 --- a/piem.el +++ b/piem.el @@ -242,18 +242,17 @@ the following information about the patch series: ;;;; Patch handling -(defun piem-series-info (cover patches) - "Collect information for a patch series. -COVER is an mbox with the cover letter, and PATCHES is an -am-ready mbox. If the series does not have a cover letter (e.g., -a one-patch series), COVER may be nil." - (with-temp-buffer - (insert-file-contents (or cover patches)) - (let ((info (save-restriction - (message-narrow-to-head) - (list :date (message-fetch-field "date") - :from (message-fetch-field "from") - :subject (message-fetch-field "subject"))))) +(defun piem-extract-mbox-info (&optional buffer) + "Collect information from message in BUFFER. +If BUFFER is nil, the current buffer is used. Any message after +the first will be ignored." + (with-current-buffer (or buffer (current-buffer)) + (let ((info (save-excursion + (save-restriction + (message-narrow-to-head) + (list :date (message-fetch-field "date") + :from (message-fetch-field "from") + :subject (message-fetch-field "subject")))))) (when (re-search-forward (rx line-start "base-commit: " (group (>= 40 hex-digit)) line-end) -- cgit v1.2.3