From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:203:b4db::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms12 with LMTPS id GNfRIIl8dGISNQAAsNZ9tg (envelope-from ); Fri, 06 May 2022 01:40:25 +0000 Received: from out1.migadu.com ([2001:41d0:2:863f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id OBLwH4l8dGKzGwAA9RJhRA (envelope-from ); Fri, 06 May 2022 03:40:25 +0200 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=1651801225; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=naANAy+TiA7iROwwtYQHfbMsRE7/z09zr11RCY590CU=; b=ZYcB6BGgU5GmCd2zYn2ijZBjNBfNB/8/HqqPAytD01QalKimSIiNhIodaNEUkb4m8eHEvX MTDi+0T/serY0jxE50kIuculzLwB6tlNWjGhfcl3pV3UFitMlFpaAWhvU3Vai8TvAdfUQm 0T4AvR7L2bua7d4wNREdfRBHf2m/mCLE5+3o9S9Mkz07eRI5v0jsfJh1UKoTzP1Kb0DeGi roatX6nBPt+UpfCx76cA/bMN6Zptg4finTofJzG8Aymq6Asnp0w0l6TD65xUXdclpjAkGD VFliW/Mj3m835LMIWhSetjYfcIrvBm4nBQ/BodGkSCmxlHBqJjYYiw4n9l3F8Q== From: Kyle Meyer To: Ihor Radchenko Cc: piem@inbox.kyleam.com Subject: [PATCH] piem-inboxes: Support mapping inbox to multiple coderepos Date: Thu, 5 May 2022 21:40:17 -0400 Message-Id: <20220506014017.14259-1-kyle@kyleam.com> In-Reply-To: <87pml6871p.fsf@kyleam.com> References: <87pml6871p.fsf@kyleam.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: kyleam.com X-TUID: DA5+hCjKa+En An inbox may regularly receive patches for multiple repos. Allow an inbox's :coderepo to be a list, and teach piem-inbox-coderepo to select a target repo by prompting the caller with the configured list. --- Documentation/piem.texi | 5 ++++- TODO | 4 ---- piem.el | 46 +++++++++++++++++++++++++++-------------- tests/piem-tests.el | 29 ++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 20 deletions(-) diff --git a/Documentation/piem.texi b/Documentation/piem.texi index fc9f795b..26962a4b 100644 --- a/Documentation/piem.texi +++ b/Documentation/piem.texi @@ -163,7 +163,10 @@ Registering inboxes that contains code related to that archive (in the example above, a local clone of @url{https://git.kernel.org/pub/scm/git/git.git/}). This information is required to apply patches from an archive to a local code -repository (@pxref{Applying patches}). +repository (@pxref{Applying patches}). To map an inbox to more than one +repository (e.g., if the inbox receives patches for multiple projects, +or if you use a few dedicated Git worktrees for different types of +patches), set @code{:coderepo} to a list of locations. @findex piem-merged-inboxes @vindex piem-get-inboxes-from-config diff --git a/TODO b/TODO index 97d2d7f6..e6a90ea6 100644 --- a/TODO +++ b/TODO @@ -2,10 +2,6 @@ A (sparse and likely stale) to-do list for piem -*-outline-*- * general -** piem-inboxes: support mapping inbox to multiple coderepos -A catchall inbox may be used for small projects without a dedicated -address. - ** "report inbox" command for debugging ** "show message ID at point" command diff --git a/piem.el b/piem.el index 22d82120..f91e3e64 100644 --- a/piem.el +++ b/piem.el @@ -58,10 +58,6 @@ (defgroup piem () :link '(info-link "(piem)Top") :group 'tools) -;; TODO: Decide how to deal with inboxes that map to more than one -;; coderepo. This is important to support for people that want to -;; use a catchall inbox for small projects which they don't think -;; (yet) need a dedicated address. (defcustom piem-inboxes nil "List of public-inbox-archived projects. @@ -77,6 +73,12 @@ (defcustom piem-inboxes nil differs from public-inbox-config's coderepo, which is a link to another section that must point to the repository's git directory. + + To map an inbox to multiple repositories, you can set this + to a list of strings. When a function (e.g., `piem-am') + needs a single coderepo, you will be prompted to select a + repository, with the first value in this list offered as + the default. :url A URL hosting HTTPS archives. This value must end with a slash. :maildir @@ -100,8 +102,7 @@ (defcustom piem-inboxes nil ;; `piem--merge-config-inboxes' so that the value can also be set in ;; ~/.public-inbox/config. :type '(alist :key-type string - :value-type - (plist :value-type string)) + :value-type plist) :set (lambda (var val) (set var val) (when (fboundp 'piem-clear-merged-inboxes) @@ -398,16 +399,23 @@ (defun piem--merge-config-inboxes () (let* ((inbox-name (match-string 1 key)) (inbox-item (assoc inbox-name cfg-inboxes)) (prop-name (intern (concat ":" (match-string 2 key)))) - (prop-pair (list prop-name (car val)))) - (when-let ((coderepo + (prop-pair (list prop-name + (if (eq prop-name :coderepo) + val + (car val))))) + (when-let ((coderepos (and (eq prop-name :coderepo) - (car (gethash - (format "coderepo.%s.dir" (car val)) - pi-cfg))))) + (mapcar + (lambda (v) + (car (gethash (format "coderepo.%s.dir" v) + pi-cfg))) + val)))) (setq prop-pair (list :coderepo - (replace-regexp-in-string - "/\\.git/?\\'" "" coderepo)))) + (mapcar + (lambda (r) + (replace-regexp-in-string "/\\.git/?\\'" "" r)) + coderepos)))) (if inbox-item (setcdr inbox-item (nconc prop-pair (cdr inbox-item))) (push (cons inbox-name prop-pair) cfg-inboxes))))) @@ -516,8 +524,16 @@ (defun piem-inbox-get (key &optional inbox) (defun piem-inbox-coderepo (&optional inbox) "Return the code repository of current buffer's inbox." - (when-let ((repo (piem-inbox-get :coderepo inbox))) - (file-name-as-directory (expand-file-name repo)))) + (when-let ((inbox (or inbox (piem-inbox))) + (repos (piem-inbox-get :coderepo inbox))) + (when (stringp repos) + (setq repos (list repos))) + (let ((repo (if (= (length repos) 1) + (car repos) + (completing-read "Code repository: " repos + nil t nil nil (car repos))))) + (unless (string-blank-p repo) + (file-name-as-directory (expand-file-name repo)))))) (defun piem-inbox-maildir-directory (&optional inbox) "Return the maildir for INBOX. diff --git a/tests/piem-tests.el b/tests/piem-tests.el index 444ed5f7..79d8591e 100644 --- a/tests/piem-tests.el +++ b/tests/piem-tests.el @@ -49,6 +49,21 @@ (defvar piem-tests-sample-pi-config " dir = /code/foo/.git ") +(defvar piem-tests-sample-pi-config-multiple-coderepos " +[publicinbox \"foo\"] + address = foo@example.com + url = https://example.com/foo + inboxdir = /inboxes/foo + coderepo = foo.git + coderepo = bar.git + +[coderepo \"foo.git\"] + dir = /code/foo/.git + +[coderepo \"bar.git\"] + dir = /code/bar/.git +") + (ert-deftest piem-merged-inboxes:from-config-disabled () (let ((piem-get-inboxes-from-config nil) (piem-inboxes nil)) @@ -78,6 +93,20 @@ (ert-deftest piem-merged-inboxes:from-config () (piem-clear-merged-inboxes) (should-not (piem-inbox-get :address "foo"))))) +(ert-deftest piem-merged-inboxes:from-config-multiple-coderepos () + (piem-clear-merged-inboxes) + (let ((piem-get-inboxes-from-config t) + (piem-inboxes nil)) + (piem-tests-with-pi-config piem-tests-sample-pi-config-multiple-coderepos + (cl-letf (((symbol-function 'completing-read) + (lambda (&rest _) "/code/foo"))) + (should (equal (piem-inbox-coderepo "foo") + "/code/foo/"))) + (cl-letf (((symbol-function 'completing-read) + (lambda (&rest _) "/code/bar"))) + (should (equal (piem-inbox-coderepo "foo") + "/code/bar/")))))) + (ert-deftest piem-merged-inboxes:override-config () (piem-clear-merged-inboxes) (let ((piem-get-inboxes-from-config t) base-commit: 6f196480a040c0f57bb0a11ecae97e5b427a9d0f -- 2.35.1