From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms12 with LMTPS id 4IQhBtGrMF9tGQAAsNZ9tg (envelope-from ) for ; Mon, 10 Aug 2020 02:07:13 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id CJTpAdGrMF/6MwAAbx9fmQ (envelope-from ) for ; Mon, 10 Aug 2020 02:07:13 +0000 Received: from pb-smtp1.pobox.com (pb-smtp1.pobox.com [64.147.108.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id D3D3994053D for ; Mon, 10 Aug 2020 02:07:08 +0000 (UTC) Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 8EA1473744; Sun, 9 Aug 2020 22:07:06 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:mime-version:content-transfer-encoding; s=sasl; bh=ozEA3kv8uw+0g67O981xsgPUpl8=; b=HfRS2x8jepHyS6KflvDn psPhHHzGqpDCHj70Op15bGqZWDtxlj/PgijM21ekcpKw2Yo5aUidypWJAFzfHa6x FaH6BlRKj8fo+VsV0UWGSFKmpDfRFoUdg54PEgPMiARx6wHljoJNB0g57CHfTECh 1hrHaCmkRj566O4THWE4xf4= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 7401B73741; Sun, 9 Aug 2020 22:07:06 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=kyleam.com; h=from:to:subject:date:message-id:mime-version:content-transfer-encoding; s=mesmtp; bh=dZApiCWWT/lrZlDiRsIZQHmhsKOxa2pL9vq8uiPv4r8=; b=PMSPJWwq4JoEd8W3TDytWrtJctn9RQwXAydCyAiqvfhXS92IQL1JTMfgyUf/GvC82QgSAjwZX7p8PxkUoq3HX7xJIQCoYbITw6UtE2sH+DTWu6LCUf+egq6ctNpOa8QHmzcP2CGbREN5lyBpGeQja2h3UToJ/hagneMl+9QnpRc= Received: from localhost (unknown [45.33.91.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id CEF1F73740; Sun, 9 Aug 2020 22:07:05 -0400 (EDT) (envelope-from kyle@kyleam.com) From: Kyle Meyer To: piem@inbox.kyleam.com Subject: [PATCH] Explicitly specify --patch-format in git-am calls Date: Sun, 9 Aug 2020 22:07:04 -0400 Message-Id: <20200810020704.30150-1-kyle@kyleam.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Pobox-Relay-ID: 305AB734-DAAE-11EA-8B9C-01D9BED8090B-24757444!pb-smtp1.pobox.com Content-Transfer-Encoding: quoted-printable X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=pobox.com header.s=sasl header.b=HfRS2x8j; dkim=fail (body hash did not verify) header.d=kyleam.com header.s=mesmtp header.b=PMSPJWwq; dmarc=none; spf=pass (aspmx1.migadu.com: domain of kyle@kyleam.com designates 64.147.108.70 as permitted sender) smtp.mailfrom=kyle@kyleam.com X-Spam-Score: 2.50 X-TUID: b4bW2Rbc7+he The sources of mbox patches fed to git-am are 1) threads downloaded from a public-inbox HTTP instance, 2) mboxes generated via piem-mid-to-thread-functions, and 3) those generated via piem-am-ready-mbox-functions. The first source should always be mboxrd. For the second, piem-notmuch-mid-to-thread is currently the only function suitable for piem-mid-to-thread-functions, and it uses mboxrd. The third source is a mix between mbox and mboxrd. By default, git-am tries to auto-detect the patch format, but let's explicitly specify --patch-format to avoid any incorrect guesses. --- piem-b4.el | 1 + piem-gnus.el | 10 ++++---- piem-notmuch.el | 7 +++--- piem.el | 61 ++++++++++++++++++++++++++++++------------------- 4 files changed, 49 insertions(+), 30 deletions(-) diff --git a/piem-b4.el b/piem-b4.el index d1ec157..3381b01 100644 --- a/piem-b4.el +++ b/piem-b4.el @@ -126,6 +126,7 @@ (defun piem-b4-am-from-mid (mid &optional args) (piem-b4--get-am-files mid coderepo args)) (default-directory coderepo)) (piem-am mbox-file + nil (with-temp-buffer (insert-file-contents (or cover mbox-file)) (piem-extract-mbox-info)) diff --git a/piem-gnus.el b/piem-gnus.el index fcfb08e..9e42185 100644 --- a/piem-gnus.el +++ b/piem-gnus.el @@ -77,9 +77,10 @@ (defun piem-gnus-am-ready-mbox () (point-min) (point-max))))) gnus-article-mime-handles)))) (when patches - (lambda () - (dolist (patch patches) - (insert patch)))))) + (list (lambda () + (dolist (patch patches) + (insert patch))) + "mbox")))) (gnus-article-buffer (let ((patch (with-current-buffer gnus-article-buffer (save-restriction @@ -89,7 +90,8 @@ (defun piem-gnus-am-ready-mbox () (buffer-substring-no-properties (point-min) (point-max))))))) (when patch - (lambda () (insert patch)))))))) + (list (lambda () (insert patch)) + "mbox"))))))) =20 ;;;###autoload (define-minor-mode piem-gnus-mode diff --git a/piem-notmuch.el b/piem-notmuch.el index 1e4dbb2..c9c3bed 100644 --- a/piem-notmuch.el +++ b/piem-notmuch.el @@ -88,9 +88,10 @@ (defun piem-notmuch-am-ready-mbox () (plist-get part :content))) (plist-get body :content))))) (when patches - (lambda () - (dolist (patch patches) - (insert patch)))))))))) + (list (lambda () + (dolist (patch patches) + (insert patch))) + "mbox")))))))) =20 ;;;###autoload (define-minor-mode piem-notmuch-mode diff --git a/piem.el b/piem.el index 6dc531d..e70c259 100644 --- a/piem.el +++ b/piem.el @@ -91,14 +91,17 @@ (defcustom piem-mid-to-thread-functions nil Each function should accept one argument, the message ID. If the function knows how to create an mbox for the message ID, it should return a function that takes no arguments and inserts the -mbox's contents in the current buffer." +mbox's contents (in mboxrd format) in the current buffer." :type 'hook) =20 (defcustom piem-am-ready-mbox-functions nil "Functions tried to get an mbox to be fed to `git am'. The functions are called with no arguments. If a function knows how to create an mbox, it should return a function that takes no -arguments and inserts the mbox's contents in the current buffer." +arguments and inserts the mbox's contents in the current buffer. +The return value can also be (FUNCTION FORMAT), where FORMAT is +either \"mbox\" or \"mboxrd\" and maps to the --patch-format +value passed to `git am'. If unspecified, \"mboxrd\" is used." :type 'hook) =20 (defcustom piem-add-message-id-header nil @@ -333,13 +336,16 @@ (defun piem--insert-message-id-header (mid) (insert (format "Message-Id: <%s>\n" mid)))))))) =20 (defun piem-am-ready-mbox () - "Return buffer containing an am-ready mbox. -Callers are responsible for killing the buffer." - (when-let ((fn (run-hook-with-args-until-success - 'piem-am-ready-mbox-functions))) - (let ((buffer (generate-new-buffer " *piem am-ready mbox*")) - (mid (and piem-add-message-id-header (piem-mid))) - has-content) + "Generate a buffer containing an am-ready mbox. +The return value is (BUFFER FORMAT), where FORMAT is either +\"mbox\" or \"mboxrd\". Callers are responsible for killing the +buffer." + (when-let ((res (run-hook-with-args-until-success + 'piem-am-ready-mbox-functions))) + (pcase-let ((buffer (generate-new-buffer " *piem am-ready mbox*")) + (`(,fn ,format) (if (listp res) res (list res "mboxrd"))= ) + (mid (and piem-add-message-id-header (piem-mid))) + (has-content nil)) (with-current-buffer buffer (funcall fn) (setq has-content (< 1 (point-max))) @@ -347,7 +353,7 @@ (defun piem-am-ready-mbox () (goto-char (point-min)) (piem--insert-message-id-header mid))) (if has-content - buffer + (list buffer format) (kill-buffer buffer) nil)))) =20 @@ -524,24 +530,31 @@ (defun piem-name-branch-who-what-v (info) (defvar piem-am-args (list "--scissors" "--3way")) =20 ;;;###autoload -(defun piem-am (mbox &optional info coderepo) +(defun piem-am (mbox &optional format info coderepo) "Feed an am-ready mbox to `git am'. =20 MBOX is a buffer whose contents are an am-ready mbox (obtained -via `piem-am-ready-mbox' when called interactively). INFO is a -plist that with information to help choose a default branch name -or starting point (see `piem-default-branch-function' for a list -of possible properties). +via `piem-am-ready-mbox' when called interactively). FORMAT +controls the value passed as the --patch-format option of `git +am'. \"mbox\" and \"mboxrd\" are valid values, and \"mboxrd\" is +the default. + +INFO is a plist that with information to help choose a default +branch name or starting point (see `piem-default-branch-function' +for a list of possible properties). =20 If CODEREPO is given, switch to this directory before calling `git am'." (interactive - (let ((mbox (or (piem-am-ready-mbox) - (user-error - "Could not find am-ready mbox for current buffer")))= ) + (pcase-let ((`(,mbox ,format) + (or (piem-am-ready-mbox) + (user-error + "Could not find am-ready mbox for current buffer"))= )) (list mbox + format (piem-extract-mbox-info mbox) (piem-inbox-coderepo-maybe-read)))) + (setq format (or format "mboxrd")) (let ((default-directory (or coderepo default-directory))) (let ((new-branch (read-string "New branch (empty for detached): " @@ -559,11 +572,13 @@ (defun piem-am (mbox &optional info coderepo) (list "-b" new-branch)) (and (not (string-blank-p base)) (list base))))) - (if (bufferp mbox) - (apply #'piem-process-call-with-buffer-input - nil mbox piem-git-executable "am" piem-am-args) - (apply #'piem-process-call nil piem-git-executable "am" - (append piem-am-args (list mbox)))) + (let ((args (cons (concat "--patch-format=3D" format) + piem-am-args))) + (if (bufferp mbox) + (apply #'piem-process-call-with-buffer-input + nil mbox piem-git-executable "am" args) + (apply #'piem-process-call nil piem-git-executable "am" + (append args (list mbox))))) (if (and piem-use-magit (fboundp 'magit-status-setup-buffer)) (magit-status-setup-buffer) base-commit: 118643c2985c0113c179d734356fc1b9e082b4c5 --=20 2.27.0