From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:403:4ea1::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms12 with LMTPS id 6JITJmL0zGFpRwAAsNZ9tg (envelope-from ); Wed, 29 Dec 2021 23:50:58 +0000 Received: from out0.migadu.com ([2001:41d0:2:267::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id cALtImL0zGGruQAAG6o9tA (envelope-from ); Thu, 30 Dec 2021 00:50:58 +0100 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kyleam.com; s=key1; t=1640821858; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h5Uq8qm/tfqJDIiN+vrDFZI4nXkK+6SN3ar1MmjI0EM=; b=P2Lhayq7pgd0Nq1PuDhiL1ydahLV2qnGky/1+9TeER45m5wUS7NeFUfQeXTlA0CDpfTYUr sRMVNSCc6as3dVbibZq7CKzMlwF75zfJif0NKms0dL/jkqaY73XDh+fZbE21Gr8dtiB3wF Jz6iNSwS8B73JHyfdqhK2E/qwq08WM1754CcXNLrzqSWjhqEFdnphgukajCf4vVfdBJD3G hGUQTwVd7C1Hid+ptKKxyqlL6DshJYmr6sYcpAUFtyAEDRYdJkqssk5RT5Kczld0yyX1Kf s1tEexTKLX3m+deQ65L0nm/U1ISVdas0yLWPBwdqNvPYmuIhorokvs0aNWDdpw== From: Kyle Meyer To: piem@inbox.kyleam.com Subject: [RFC PATCH 03/14] am: Extract git-am logic to dedicated function Date: Wed, 29 Dec 2021 18:50:25 -0500 Message-Id: <20211229235036.372313-4-kyle@kyleam.com> In-Reply-To: <20211229235036.372313-1-kyle@kyleam.com> References: <20211229235036.372313-1-kyle@kyleam.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: kyleam.com X-TUID: nA2+lpoDrsSZ Another command will need the same code. --- piem.el | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/piem.el b/piem.el index ac81c217..4b0457a2 100644 --- a/piem.el +++ b/piem.el @@ -913,6 +913,26 @@ (defun piem-am--read-worktree (coderepo branch) (user-error "Worktree directory already exists")) dir)) +(defun piem--git-am (mbox format dir) + (setq dir (or dir default-directory)) + (let ((interactivep (eq (car-safe mbox) :interactive)) + (args (cons (concat "--patch-format=" (or format "mboxrd")) + piem-am-args))) + (when interactivep + (setq mbox (cdr mbox))) + (if (bufferp mbox) + (unwind-protect + (apply #'piem-process-call-with-buffer-input + dir mbox piem-git-executable "am" args) + (when interactivep + (kill-buffer mbox))) + (apply #'piem-process-call dir piem-git-executable "am" + (append args (list mbox))))) + (if (and piem-use-magit + (fboundp 'magit-status-setup-buffer)) + (magit-status-setup-buffer dir) + (dired dir))) + ;;;###autoload (defun piem-am (mbox &optional format info coderepo toggle-worktree) "Feed an am-ready mbox to `git am'. @@ -975,20 +995,7 @@ (defun piem-am (mbox &optional format info coderepo toggle-worktree) (and use-worktree (list am-directory)) (and (not (string-blank-p base)) (list base))))) - (let ((args (cons (concat "--patch-format=" format) - piem-am-args))) - (if (bufferp mbox) - (unwind-protect - (apply #'piem-process-call-with-buffer-input - am-directory mbox piem-git-executable "am" args) - (when interactivep - (kill-buffer mbox))) - (apply #'piem-process-call am-directory piem-git-executable "am" - (append args (list mbox))))) - (if (and piem-use-magit - (fboundp 'magit-status-setup-buffer)) - (magit-status-setup-buffer am-directory) - (dired am-directory)))) + (piem--git-am mbox format am-directory))) (defvar-local piem-edit-patch--coderepo nil) (defvar-local piem-edit-patch--format nil) -- 2.34.0