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 4FsAHqrHsF/dJwAAsNZ9tg (envelope-from ) for ; Sun, 15 Nov 2020 06:16:10 +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 uLnEGarHsF/GcAAAbx9fmQ (envelope-from ) for ; Sun, 15 Nov 2020 06:16:10 +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 0609F9402DD for ; Sun, 15 Nov 2020 06:16:10 +0000 (UTC) Received: from pb-smtp20.pobox.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id A72091075E3; Sun, 15 Nov 2020 01:16:08 -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=6sb16NmkLTwujizNs+cCP6SZ4 hc=; b=sNDdjRR5T3TyuL3x/ZsWRtrJ9ffJSSSec5IQTbbBBBxl9oHSCGNB+9YAq lxJdlD8xXMdUh2YzO9DKYk42T86oe+ND9SiG5Gcsv0uOEkJTH1EPTp7koLgV6/HR J48SkG+OxdgLiQpKOYby4rvGE7n0MZqCkbotcgFDG6/ox4t6Fc= Received: from pb-smtp20.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id A024F1075E2; Sun, 15 Nov 2020 01:16:08 -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=RmTO0RMzoiDrhD/5VGv8DF9qAJ8dxORcuTvgnMFS3uM=; b=DuojaAK0xiYma//3fp0PbGsaPs/sBGabSNRPvgs0ut+onS7oGiGVdTyiSiBCYGKWnLhL/GSJaJ5MdKHH726trTgbXn3vU3y88XJLxmx8IRmIDdfpiwGwIJO8SXaaexEnuCWf+V94dvRJfR1GI3J3t5U+OuJYnmj9CRKhmIsVjXI= 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 13BBD1075D9; Sun, 15 Nov 2020 01:16:06 -0500 (EST) (envelope-from kyle@kyleam.com) From: Kyle Meyer To: piem@inbox.kyleam.com Cc: zimoun Subject: [PATCH 5/6] am: Allow flipping worktree creation with prefix argument Date: Sun, 15 Nov 2020 01:15:17 -0500 Message-Id: <20201115061518.22191-6-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: 0B7EFED6-270A-11EB-8F4E-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=sNDdjRR5; dkim=fail (body hash did not verify) header.d=kyleam.com header.s=mesmtp header.b=DuojaAK0; 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: L/FDLbYv3e2V I tend to use a few dedicated worktrees for projects and am not interested in creating a worktree for each patch series I apply. However, I can imagine wanting to create one every now and then. Make it possible by adding a prefix argument to piem-am and piem-b4-am-from-mid that flips the meaning of piem-am-create-worktree. --- piem-b4.el | 15 +++++++++++---- piem.el | 18 ++++++++++++------ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/piem-b4.el b/piem-b4.el index 27ecf19..172236f 100644 --- a/piem-b4.el +++ b/piem-b4.el @@ -130,15 +130,21 @@ (defun piem-b4-am-ready-from-mid (mid &optional arg= s) (append args (list mid)))) =20 ;;;###autoload -(defun piem-b4-am-from-mid (mid &optional args) +(defun piem-b4-am-from-mid (mid &optional args toggle-worktree) "Get the thread for MID, extract an am-ready mbox, and apply it. + Try to get a thread for the Message-Id MID with `piem-mid-to-thread-functions', falling back to letting b4 download it. After calling `b4 am' with ARGS to prepare an -am-ready mbox, feed the result to `git am'." +am-ready mbox, feed the result to `git am'. + +When prefix argument TOGGLE-WORKTREE is non-nil, invert the +meaning of `piem-am-create-worktree'. With the default value, +this triggers the creation of a new worktree." (interactive (list (or (piem-mid) (read-string "Message ID: ")) - (transient-args 'piem-b4-am))) + (transient-args 'piem-b4-am) + current-prefix-arg)) (when-let ((badopt (cl-some (lambda (arg) (and (string-match @@ -158,7 +164,8 @@ (defun piem-b4-am-from-mid (mid &optional args) (with-temp-buffer (insert-file-contents (or cover mbox-file)) (piem-extract-mbox-info)) - coderepo) + coderepo + toggle-worktree) (when clean-fn (funcall clean-fn))))) =20 diff --git a/piem.el b/piem.el index ac9812c..0cb1093 100644 --- a/piem.el +++ b/piem.el @@ -663,7 +663,7 @@ (defun piem-am-read-worktree (coderepo branch) (replace-regexp-in-string "/" "-" branch)))))) =20 ;;;###autoload -(defun piem-am (mbox &optional format info coderepo) +(defun piem-am (mbox &optional format info coderepo toggle-worktree) "Feed an am-ready mbox to `git am'. =20 MBOX is a buffer whose contents are an am-ready mbox (obtained @@ -677,7 +677,11 @@ (defun piem-am (mbox &optional format info coderepo) for a list of possible properties). =20 CODEREPO, if given, indicates the code repository to operate -within. If not specified, the default directory is used." +within. If not specified, the default directory is used. + +When prefix argument TOGGLE-WORKTREE is non-nil, invert the +meaning of `piem-am-create-worktree'. With the default value, +this triggers the creation of a new worktree." (interactive (pcase-let ((`(,mbox . ,format) (or (piem-am-ready-mbox) @@ -689,10 +693,12 @@ (defun piem-am (mbox &optional format info coderepo= ) (list (cons :interactive mbox) format (piem-extract-mbox-info mbox) - (piem-inbox-coderepo-maybe-read)))) + (piem-inbox-coderepo-maybe-read) + current-prefix-arg))) (setq format (or format "mboxrd")) (let* ((default-directory (or coderepo default-directory)) (am-directory default-directory) + (use-worktree (xor piem-am-create-worktree toggle-worktree)) (interactivep (eq (car-safe mbox) :interactive))) (when interactivep (setq mbox (cdr mbox))) @@ -707,7 +713,7 @@ (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))))) - (when piem-am-create-worktree + (when use-worktree (setq am-directory (expand-file-name (funcall piem-am-read-worktree-function @@ -715,11 +721,11 @@ (defun piem-am (mbox &optional format info coderepo= ) (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 + (append (if use-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 use-worktree (list am-directory)) (and (not (string-blank-p base)) (list base))))) (let ((args (cons (concat "--patch-format=3D" format) --=20 2.29.2