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 oAwPCJzHsF8ZKQAAsNZ9tg (envelope-from ) for ; Sun, 15 Nov 2020 06:15:56 +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 UO+3A5zHsF9CcwAAbx9fmQ (envelope-from ) for ; Sun, 15 Nov 2020 06:15:56 +0000 Received: from pb-smtp20.pobox.com (pb-smtp20.pobox.com [173.228.157.52]) (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 9EE159403AB for ; Sun, 15 Nov 2020 06:15:55 +0000 (UTC) Received: from pb-smtp20.pobox.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 4F9F51075B7; Sun, 15 Nov 2020 01:15:54 -0500 (EST) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=alaNJCRtZJCBMpqH8ID0dCZE6 j0=; b=Y5dLIbVsAvykuo02c0aZUDw+qkLYvNh/70K783XkxSHCus80p0g9ShsSp uFvyoEqu0l1j7Uoki6VBwsS8pK5lYK4uZX6i84ZtH1Ug+CEm/NIO7xkCsb+bbgka loV6K/blWK/Wg3sGcWV5Vj/wKJkCZRf9nIEyvt2L+HR09Ebqts= Received: from pb-smtp20.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 4A0811075B6; Sun, 15 Nov 2020 01:15:54 -0500 (EST) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=kyleam.com; h=from:to:cc:subject:date:message-id:in-reply-to:references:mime-version:content-transfer-encoding; s=mesmtp; bh=eXstco5xb8Sj8dmOLIYTLhr0p9GlQI0gWgnnfmY6B4M=; b=gXISeJVVFJxRH6NFLd3ZJ7ftXRBoj0r9S6cilgZwMRPBMjq3r0SHJoWPO3v8qG6qkR+83a1vbvEAk2RWOLCZamGG0ptbbStUU0q/SVYFX8TZLv7qltaXtAK54UlQwpUlyg1Wx05BJKNtNXIZOa4srQFyQhMvNkKQHwI7cvTD4I0= 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-smtp20.pobox.com (Postfix) with ESMTPSA id 8F1F31075B4; Sun, 15 Nov 2020 01:15:51 -0500 (EST) (envelope-from kyle@kyleam.com) From: Kyle Meyer To: piem@inbox.kyleam.com Cc: zimoun Subject: [PATCH 3/6] am: Support creating a new worktree Date: Sun, 15 Nov 2020 01:15:15 -0500 Message-Id: <20201115061518.22191-4-kyle@kyleam.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201115061518.22191-1-kyle@kyleam.com> References: <20201115061518.22191-1-kyle@kyleam.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 02DB3F4C-270A-11EB-A1A4-E43E2BB96649-24757444!pb-smtp20.pobox.com Content-Transfer-Encoding: quoted-printable X-Scanner: ns3122888.ip-94-23-21.eu Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=pobox.com header.s=sasl header.b=Y5dLIbVs; dkim=fail (body hash did not verify) header.d=kyleam.com header.s=mesmtp header.b=gXISeJVV; dmarc=none; spf=pass (aspmx1.migadu.com: domain of kyle@kyleam.com designates 173.228.157.52 as permitted sender) smtp.mailfrom=kyle@kyleam.com X-Spam-Score: 2.50 X-TUID: eTMsuYR9o6cX On the guix-patches list, simon described a workflow in which a new worktree is used to apply patches. Such a workflow is fairly straightforward to support in piem-am (and thus piem-b4-am-from-mid). Aside form reading the worktree from the caller, the main change needed is to replace 'git checkout (-b BRANCH|--detatched) [base]' with 'git worktree add (-b BRANCH|--detatched) PATH [base]'. Teach piem-am to use a worktree when piem-am-create-worktree is non-nil. Suggested-by: zimoun Ref: https://yhetil.org/guix-patches/86361cys9h.fsf@tournier.info --- piem.el | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/piem.el b/piem.el index a42ab3d..da7f9f8 100644 --- a/piem.el +++ b/piem.el @@ -154,6 +154,10 @@ (defcustom piem-default-branch-function The reported base commit of the patch, if any." :type 'function) =20 +(defcustom piem-am-create-worktree nil + "Whether to create a dedicated worktree for applying patches." + :type 'boolean) + (defcustom piem-maildir-directory nil "Inject public-inbox threads into this directory. If non-nil, this must be an existing Maildir directory." @@ -636,6 +640,20 @@ (defun piem-name-branch-who-what-v (info) =20 (defvar piem-am-args (list "--scissors" "--3way")) =20 +(defun piem-am-read-worktree (coderepo branch) + "Read a worktree to create for applying patches. +This function is intended to be used as a value of +`piem-am-read-worktree-function'. The worktree directory is +completed from the parent directory of CODEREPO. If BRANCH is +non-nil, it is used as for construct the default completion." + (let ((fname (directory-file-name coderepo))) + (read-directory-name + "Create worktree: " + (file-name-directory fname) nil nil + (and branch + (concat (file-name-nondirectory fname) "-" + (replace-regexp-in-string "/" "-" branch)))))) + ;;;###autoload (defun piem-am (mbox &optional format info coderepo) "Feed an am-ready mbox to `git am'. @@ -665,8 +683,9 @@ (defun piem-am (mbox &optional format info coderepo) (piem-extract-mbox-info mbox) (piem-inbox-coderepo-maybe-read)))) (setq format (or format "mboxrd")) - (let ((default-directory (or coderepo default-directory)) - (interactivep (eq (car-safe mbox) :interactive))) + (let* ((default-directory (or coderepo default-directory)) + (am-directory default-directory) + (interactivep (eq (car-safe mbox) :interactive))) (when interactivep (setq mbox (cdr mbox))) (let ((new-branch @@ -680,8 +699,18 @@ (defun piem-am (mbox &optional format info coderepo) (magit-list-local-branch-names))) (base (plist-get info :base-commit))) (if base (cons base cands) cands))))) - (apply #'piem-process-call nil piem-git-executable "checkout" - (append (if new-branch (list "-b" new-branch) (list "--deta= ch")) + (when piem-am-create-worktree + (setq am-directory + (expand-file-name + (piem-am-read-worktree default-directory new-branch))) + (when (file-exists-p am-directory) + (user-error "Worktree directory already exists"))) + (apply #'piem-process-call nil piem-git-executable + (append (if piem-am-create-worktree + (list "worktree" "add") + (list "checkout")) + (if new-branch (list "-b" new-branch) (list "--deta= ch")) + (and piem-am-create-worktree (list am-directory)) (and (not (string-blank-p base)) (list base))))) (let ((args (cons (concat "--patch-format=3D" format) @@ -689,15 +718,15 @@ (defun piem-am (mbox &optional format info coderepo= ) (if (bufferp mbox) (unwind-protect (apply #'piem-process-call-with-buffer-input - nil mbox piem-git-executable "am" args) + am-directory mbox piem-git-executable "am" args) (when interactivep (kill-buffer mbox))) - (apply #'piem-process-call nil piem-git-executable "am" + (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) - (dired ".")))) + (magit-status-setup-buffer am-directory) + (dired am-directory)))) =20 ;;;###autoload (autoload 'piem-dispatch "piem" nil t) (define-transient-command piem-dispatch () --=20 2.29.2