From: Kyle Meyer <kyle@kyleam.com>
To: Ihor Radchenko <yantar92@gmail.com>
Cc: piem@inbox.kyleam.com
Subject: [PATCH] piem-inboxes: Support mapping inbox to multiple coderepos
Date: Thu, 5 May 2022 21:40:17 -0400 [thread overview]
Message-ID: <20220506014017.14259-1-kyle@kyleam.com> (raw)
In-Reply-To: <87pml6871p.fsf@kyleam.com>
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
next prev parent reply other threads:[~2022-05-06 1:40 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-24 7:48 [FR] Support multiple repositories associated with the same ML Ihor Radchenko
2022-04-24 22:12 ` Kyle Meyer
2022-04-26 9:19 ` Applying the same patch multiple times (was: [FR] Support multiple repositories associated with the same ML) Ihor Radchenko
2022-04-27 3:49 ` Applying the same patch multiple times Kyle Meyer
2022-04-27 12:46 ` Ihor Radchenko
2022-05-07 14:19 ` Kyle Meyer
2022-05-06 1:40 ` Kyle Meyer [this message]
2022-05-06 2:10 ` [PATCH] piem-inboxes: Support mapping inbox to multiple coderepos Ihor Radchenko
2022-05-06 3:28 ` Kyle Meyer
2022-05-07 5:21 ` Ihor Radchenko
2022-05-07 14:18 ` Kyle Meyer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://git.kyleam.com/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220506014017.14259-1-kyle@kyleam.com \
--to=kyle@kyleam.com \
--cc=piem@inbox.kyleam.com \
--cc=yantar92@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.kyleam.com/piem/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).