From: Lucas De Marchi <lucas.demarchi@intel.com>
To: tools@kernel.org
Cc: Lucas De Marchi <lucas.demarchi@intel.com>
Subject: [PATCH 2/2] Allow negative number in parse_int_range()
Date: Thu, 2 May 2024 12:12:05 -0700 [thread overview]
Message-ID: <20240502191205.3964106-2-lucas.demarchi@intel.com> (raw)
In-Reply-To: <20240502191205.3964106-1-lucas.demarchi@intel.com>
This is useful when applying patches and sending a thank you note
following that, which can now be done with `b4 ty -t -1`.
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
---
docs/maintainer/am-shazam.rst | 4 ++++
docs/maintainer/ty.rst | 6 ++++--
src/b4/__init__.py | 12 +++++++++---
3 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/docs/maintainer/am-shazam.rst b/docs/maintainer/am-shazam.rst
index 2d672c3..416a941 100644
--- a/docs/maintainer/am-shazam.rst
+++ b/docs/maintainer/am-shazam.rst
@@ -128,6 +128,10 @@ The following flags are common to both commands:
b4 am -P _ <msgid>
+ This picks just the last patch from a series::
+
+ b4 am -P -1 <msgid>
+
This picks all patches where the subject matches "iscsi"::
b4 am -P *iscsi*
diff --git a/docs/maintainer/ty.rst b/docs/maintainer/ty.rst
index 3b205c2..3945b08 100644
--- a/docs/maintainer/ty.rst
+++ b/docs/maintainer/ty.rst
@@ -92,8 +92,10 @@ Optional flags
``-t THANKFOR, --thank-for THANKFOR``
From the listing generated by ``--list``, specify which thank-you
notes should be sent. This command accepts comma-separated values and
- ranges, including open-ended ranges, e.g.: ``-t 1,3,5-7,9-``. It also
- accepts ``all``.
+ ranges, including open-ended ranges, e.g.: ``-t 1,3,5-7,9-``. When using
+ a sing number, it's possible to use negative values to refer to the
+ latest patch series, e.g.: ``-t -1`` refers to the last patch series.
+ It also accepts ``all``.
``-d DISCARD, --discard DISCARD``
From the listing generated by ``--list``, specify which thank-you
diff --git a/src/b4/__init__.py b/src/b4/__init__.py
index b3f1c90..fc0a759 100644
--- a/src/b4/__init__.py
+++ b/src/b4/__init__.py
@@ -3545,9 +3545,15 @@ def parse_int_range(intrange: str, upper: int) -> Iterator[int]:
# Remove all whitespace
intrange = re.sub(r'\s', '', intrange)
for n in intrange.split(','):
- if n.isdigit():
- yield int(n)
- elif n.find('<') == 0 and len(n) > 1 and n[1:].isdigit():
+ # Allow single numbers to be negative
+ try:
+ i = int(n)
+ if i < 0 and abs(i) <= upper:
+ yield upper + i + 1
+ except ValueError:
+ pass
+
+ if n.find('<') == 0 and len(n) > 1 and n[1:].isdigit():
yield from range(1, int(n[1:]))
elif n.find('-') > 0:
nr = n.split('-')
--
2.43.0
next prev parent reply other threads:[~2024-05-02 19:11 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-02 19:12 [PATCH 1/2] Make upper non-optional in parse_int_range() Lucas De Marchi
2024-05-02 19:12 ` Lucas De Marchi [this message]
2024-05-23 20:33 ` Konstantin Ryabitsev
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240502191205.3964106-2-lucas.demarchi@intel.com \
--to=lucas.demarchi@intel.com \
--cc=tools@kernel.org \
/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.
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).