From 2bf9c383b2943eef1754e20db24419f8e269a8b7 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Thu, 5 May 2022 21:40:17 -0400 Subject: piem-inboxes: Support mapping inbox to multiple coderepos 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. Message-Id: <20220506014017.14259-1-kyle@kyleam.com> --- 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 fc9f795..26962a4 100644 --- a/Documentation/piem.texi +++ b/Documentation/piem.texi @@ -163,7 +163,10 @@ buffer can be mapped to an inbox in @code{piem-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 97d2d7f..e6a90ea 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 22d8212..f91e3e6 100644 --- a/piem.el +++ b/piem.el @@ -58,10 +58,6 @@ :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 @@ list that supports the following properties: 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 @@ configuration are considered." ;; `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 @@ files." (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 @@ returned by `piem-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 444ed5f..79d8591 100644 --- a/tests/piem-tests.el +++ b/tests/piem-tests.el @@ -49,6 +49,21 @@ 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 @@ (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) -- cgit v1.2.3