discussion and development of piem
 help / color / mirror / code / Atom feed
* [PATCH] New customization: `piem-default-branch-prefix'
@ 2023-04-30 12:45 Ihor Radchenko
  2023-04-30 19:33 ` Kyle Meyer
  0 siblings, 1 reply; 3+ messages in thread
From: Ihor Radchenko @ 2023-04-30 12:45 UTC (permalink / raw)
  To: piem

[-- Attachment #1: Type: text/plain, Size: 456 bytes --]

Hi,

Upon using piem for some time, I am getting hundreds of generated
branches in my repos. It gets inconvenient after some time, especially
because the branches are not always clearly distinguishable.

I'd like to add a new customization that adds a custom prefix string to
the generated branch names. That way, I can easily see the branches
generated by piem in the list of branches, nicely grouped when sorting
alphabetically.

The patch is attached.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-New-customization-piem-default-branch-prefix.patch --]
[-- Type: text/x-patch, Size: 2525 bytes --]

From de962c6566aeea1861151c07e2eb8fee1419373e Mon Sep 17 00:00:00 2001
Message-Id: <de962c6566aeea1861151c07e2eb8fee1419373e.1682858544.git.yantar92@posteo.net>
From: Ihor Radchenko <yantar92@posteo.net>
Date: Sun, 30 Apr 2023 14:36:14 +0200
Subject: [PATCH] New customization: `piem-default-branch-prefix'

* piem.el (piem-default-branch-prefix): New custom option adding extra
prefix to the generated default branch name.  Only takes effect when
the default `piem-name-branch-who-what-v' is used as
`piem-default-branch-function'.
(piem-name-branch-who-what-v): Use the new customization.
---
 piem.el             | 9 ++++++++-
 tests/piem-tests.el | 8 +++++++-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/piem.el b/piem.el
index 63c358a..2334a3d 100644
--- a/piem.el
+++ b/piem.el
@@ -189,6 +189,12 @@ (defcustom piem-default-branch-function
       The reported base commit of the patch, if any."
   :type 'function)
 
+(defcustom piem-default-branch-prefix ""
+  "Optional prefix prepended to the generated branch name.
+Takes effect when `piem-default-branch-function' is set to
+`piem-name-branch-who-what-v'."
+  :type 'string)
+
 (defcustom piem-am-create-worktree nil
   "Whether to create a dedicated worktree for applying patches."
   :type 'boolean)
@@ -910,7 +916,8 @@ (defun piem-name-branch-who-what-v (info)
                               (zero-or-one (group "v" (one-or-more digit))))
                           subject)
                          (match-string 1 subject))))
-      (concat initials "/"
+      (concat piem-default-branch-prefix
+              initials "/"
               (piem--shorten-subject subject)
               (and version (concat "__" version))))))
 
diff --git a/tests/piem-tests.el b/tests/piem-tests.el
index 79d8591..ece762d 100644
--- a/tests/piem-tests.el
+++ b/tests/piem-tests.el
@@ -173,7 +173,13 @@ (ert-deftest piem-name-branch-who-what-v ()
                         :subject "[PATCH v3] Do a thing"))
                  "fb/do-thing__v3"))
   (should-not (piem-name-branch-who-what-v
-               (list :from "Foo Bar <xyz.com>"))))
+               (list :from "Foo Bar <xyz.com>")))
+  ;; Test extra prefix.
+  (let ((piem-default-branch-prefix "prefix/"))
+    (should (equal (piem-name-branch-who-what-v
+                    (list :from "Foo Bar <f@example.com>"
+                          :subject "[PATCH] Do a thing"))
+                   "prefix/fb/do-thing"))))
 
 (ert-deftest piem--insert-message-id-header ()
   (should-not
-- 
2.40.0


[-- Attachment #3: Type: text/plain, Size: 224 bytes --]


-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] New customization: `piem-default-branch-prefix'
  2023-04-30 12:45 [PATCH] New customization: `piem-default-branch-prefix' Ihor Radchenko
@ 2023-04-30 19:33 ` Kyle Meyer
  2023-04-30 20:11   ` Ihor Radchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Kyle Meyer @ 2023-04-30 19:33 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: piem

Ihor Radchenko writes:

> I'd like to add a new customization that adds a custom prefix string to
> the generated branch names. That way, I can easily see the branches
> generated by piem in the list of branches, nicely grouped when sorting
> alphabetically.

Thanks, but I'd prefer not to add an option for this case.  It's
straightforward for users that want to add a prefix to do so by defining
a light wrapper around piem-name-branch-who-what-v and pointing
piem-default-branch-function to it.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] New customization: `piem-default-branch-prefix'
  2023-04-30 19:33 ` Kyle Meyer
@ 2023-04-30 20:11   ` Ihor Radchenko
  0 siblings, 0 replies; 3+ messages in thread
From: Ihor Radchenko @ 2023-04-30 20:11 UTC (permalink / raw)
  To: Kyle Meyer; +Cc: piem

Kyle Meyer <kyle@kyleam.com> writes:

> Thanks, but I'd prefer not to add an option for this case.  It's
> straightforward for users that want to add a prefix to do so by defining
> a light wrapper around piem-name-branch-who-what-v and pointing
> piem-default-branch-function to it.

Sure. That's what I am doing now. Just thought that it might be a fairly
common need, and having customization would serve as a reminder about
such possibility.

Your call though, indeed.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-04-30 20:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-30 12:45 [PATCH] New customization: `piem-default-branch-prefix' Ihor Radchenko
2023-04-30 19:33 ` Kyle Meyer
2023-04-30 20:11   ` Ihor Radchenko

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).