Skip to content

Commit

Permalink
ez: implement send --dry-run-to
Browse files Browse the repository at this point in the history
Sometimes it is useful to be able to send the series out to someone for
a quick one-over review (e.g. to your mentor, boss, colleague) before
actually sending it out to the actual maintainers.

It is now possible to do so with:

    b4 send --dry-run-to addr@example.com

This will not trigger a tag-and-reroll and will include a DRYRUN into
the patch prefixes to clearly indicate that it's not the final
submission that should be used for review.

Suggested-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Link: https://lore.kernel.org/f5c38763b4d42cfafdaac24d83ec18b81dfc073a.camel@suse.com
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=218302
Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
  • Loading branch information
mricon committed Dec 22, 2023
1 parent 28563f0 commit 4e03211
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 36 deletions.
20 changes: 12 additions & 8 deletions b4/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,16 +310,20 @@ def setup_parser() -> argparse.ArgumentParser:

# b4 send
sp_send = subparsers.add_parser('send', help='Submit your work for review on the mailing lists')
sp_send.add_argument('-d', '--dry-run', dest='dryrun', action='store_true', default=False,
help='Do not send, just dump out raw smtp messages to the stdout')
sp_send.add_argument('-o', '--output-dir',
help='Do not send, write raw messages to this directory (forces --dry-run)')
sp_send.add_argument('--reflect', action='store_true', default=False,
help='Send everything to yourself instead of the actual recipients')
sp_send_g = sp_send.add_mutually_exclusive_group()
sp_send_g.add_argument('-d', '--dry-run', dest='dryrun', action='store_true', default=False,
help='Do not send, just dump out raw smtp messages to the stdout')
sp_send_g.add_argument('-o', '--output-dir',
help='Do not send, write raw messages to this directory (forces --dry-run)')
sp_send_g.add_argument('--dry-run-to', nargs='+', metavar='ADDR',
help='Like --dry-run, but sends out via email to specified recipients')
sp_send_g.add_argument('--reflect', action='store_true', default=False,
help='Send everything to yourself instead of the actual recipients')

sp_send.add_argument('--no-trailer-to-cc', action='store_true', default=False,
help='Do not add any addresses found in the cover or patch trailers to To: or Cc:')
sp_send.add_argument('--to', nargs='+', help='Addresses to add to the To: list')
sp_send.add_argument('--cc', nargs='+', help='Addresses to add to the Cc: list')
sp_send.add_argument('--to', nargs='+', metavar='ADDR', help='Addresses to add to the To: list')
sp_send.add_argument('--cc', nargs='+', metavar='ADDR', help='Addresses to add to the Cc: list')
sp_send.add_argument('--not-me-too', action='store_true', default=False,
help='Remove yourself from the To: or Cc: list')
sp_send.add_argument('--resend', metavar='vN', nargs='?', const='latest',
Expand Down
62 changes: 42 additions & 20 deletions b4/ez.py
Original file line number Diff line number Diff line change
Expand Up @@ -1170,11 +1170,14 @@ def get_mailfrom() -> Tuple[str, str]:
return usercfg.get('name'), usercfg.get('email')


def get_prep_branch_as_patches(movefrom: bool = True, thread: bool = True, addtracking: bool = True
def get_prep_branch_as_patches(movefrom: bool = True, thread: bool = True, addtracking: bool = True,
prefixes: Optional[List[str]] = None
) -> Tuple[List, List, str, List[Tuple[str, email.message.Message]]]:
cover, tracking = load_cover(strip_comments=True)

prefixes = tracking['series'].get('prefixes', list())
if prefixes is None:
prefixes = list()
prefixes += tracking['series'].get('prefixes', list())
start_commit = get_series_start()
change_id = tracking['series'].get('change-id')
revision = tracking['series'].get('revision')
Expand Down Expand Up @@ -1356,8 +1359,13 @@ def cmd_send(cmdargs: argparse.Namespace) -> None:
logger.critical(' Stash or commit them first.')
sys.exit(1)

if cmdargs.dry_run_to:
prefixes = ['DRYRUN']

This comment has been minimized.

Copy link
@miquelraynal

miquelraynal Feb 6, 2024

Hello, first thanks a lot for this contribution which makes total sense!

I however find this prefix a bit misleading, "dry run" really means "nothing sent". I understand the idea of saying "we don't send upstream" but it kind of deviates too much from the original Git term IMHO, so I would really prefer another prefix. "INTERNAL" or "REVIEW" or "DOWNSTREAM" maybe?

else:
prefixes = None

try:
todests, ccdests, tag_msg, patches = get_prep_branch_as_patches()
todests, ccdests, tag_msg, patches = get_prep_branch_as_patches(prefixes=prefixes)
except RuntimeError as ex:
logger.critical('CRITICAL: Failed to convert range to patches: %s', ex)
sys.exit(1)
Expand All @@ -1379,7 +1387,7 @@ def cmd_send(cmdargs: argparse.Namespace) -> None:
excludes = set()
pccs = dict()

if cmdargs.no_trailer_to_cc:
if cmdargs.dry_run_to or cmdargs.no_trailer_to_cc:
todests = list()
ccdests = list()
else:
Expand Down Expand Up @@ -1413,27 +1421,30 @@ def cmd_send(cmdargs: argparse.Namespace) -> None:
excludes.add(myemail)

tos = set()
if cmdargs.to:
tos.update(cmdargs.to)
if config.get('send-series-to'):
tos.add(config.get('send-series-to'))
if tos:
for pair in utils.getaddresses(list(tos)):
if pair[1] in seen:
continue
seen.add(pair[1])
todests.append(pair)
ccs = set()
if cmdargs.cc:
ccs.update(cmdargs.cc)
if config.get('send-series-cc'):
ccs.add(config.get('send-series-cc'))
if cmdargs.dry_run_to:
tos.update(cmdargs.dry_run_to)
else:
if cmdargs.to:
tos.update(cmdargs.to)
if config.get('send-series-to'):
tos.add(config.get('send-series-to'))
if cmdargs.cc:
ccs.update(cmdargs.cc)
if config.get('send-series-cc'):
ccs.add(config.get('send-series-cc'))
if ccs:
for pair in utils.getaddresses(list(ccs)):
if pair[1] in seen:
continue
seen.add(pair[1])
ccdests.append(pair)
if tos:
for pair in utils.getaddresses(list(tos)):
if pair[1] in seen:
continue
seen.add(pair[1])
todests.append(pair)

allto = list()
allcc = list()
Expand All @@ -1447,7 +1458,8 @@ def cmd_send(cmdargs: argparse.Namespace) -> None:
alldests.update(set([x[1] for x in allcc]))

if not len(alldests):
logger.critical('CRITICAL: Could not find any destination addresses (try: b4 prep --auto-to-cc).')
logger.critical('CRITICAL: Could not find any destination addresses')
logger.critical(' try b4 prep --auto-to-cc or b4 send --to addr')
sys.exit(1)

if not len(allto):
Expand All @@ -1474,6 +1486,11 @@ def cmd_send(cmdargs: argparse.Namespace) -> None:
logger.debug('No sendemail configs found, will use the default web endpoint')
endpoint = DEFAULT_ENDPOINT

# Cannot currently use endpoint with --dry-run-to
if endpoint and cmdargs.dry_run_to:
logger.critical('CRITICAL: cannot use the web endpoint with --dry-run-to')
sys.exit(1)

# Give the user the last opportunity to bail out
if not cmdargs.dryrun:
logger.info('---')
Expand Down Expand Up @@ -1507,6 +1524,8 @@ def cmd_send(cmdargs: argparse.Namespace) -> None:
fromaddr = sconfig.get('from')
if cmdargs.reflect:
logger.info(' - send the above messages to just %s (REFLECT MODE)', fromaddr)
elif cmdargs.dry_run_to:
logger.info(' - send the above messages to the DRY-RUN recipients listed')
else:
logger.info(' - send the above messages to actual listed recipients')
logger.info(' - with envelope-from: %s', fromaddr)
Expand All @@ -1528,7 +1547,7 @@ def cmd_send(cmdargs: argparse.Namespace) -> None:
else:
logger.info(' - via SMTP server %s', smtpserver)

if not (cmdargs.reflect or cmdargs.resend):
if not (cmdargs.reflect or cmdargs.resend or cmdargs.dry_run_to):
logger.info(' - tag and reroll the series to the next revision')
logger.info('')
if cmdargs.reflect:
Expand Down Expand Up @@ -1645,6 +1664,9 @@ def cmd_send(cmdargs: argparse.Namespace) -> None:
if cmdargs.resend:
logger.debug('Not updating cover/tracking on resend')
return
if cmdargs.dry_run_to:
logger.debug('Not updating cover/tracking on --dry-run-to')
return

reroll(mybranch, tag_msg, cl_msgid)

Expand Down
15 changes: 11 additions & 4 deletions man/b4.5
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ Enroll current branch, using the passed tag, branch, or commit as fork base
.INDENT 0.0
.TP
.B usage:
b4 send [\-h] [\-d] [\-o OUTPUT_DIR] [\-\-reflect] [\-\-no\-trailer\-to\-cc] [\-\-to TO [TO ...]] [\-\-cc CC [CC ...]] [\-\-not\-me\-too] [\-\-resend [RESEND]] [\-\-no\-sign] [\-\-web\-auth\-new] [\-\-web\-auth\-verify VERIFY_TOKEN]
b4 send [\-h] [\-d | \-o OUTPUT_DIR | \-\-dry\-run\-to ADDR [ADDR ...] | \-\-reflect] [\-\-no\-trailer\-to\-cc] [\-\-to ADDR [ADDR ...]] [\-\-cc ADDR [ADDR ...]] [\-\-not\-me\-too] [\-\-resend [vN]] [\-\-no\-sign] [\-\-web\-auth\-new] [\-\-web\-auth\-verify VERIFY_TOKEN]
.TP
.B options:
.INDENT 7.0
Expand All @@ -618,6 +618,13 @@ show this help message and exit
.TP
.B \-d\fP,\fB \-\-dry\-run
Do not send, just dump out raw smtp messages to the stdout
.UNINDENT
.INDENT 7.0
.TP
.B \-\-dry\-run\-to ADDR [ADDR ...]
Like \-\-dry\-run, but sends out via email to specified recipients
.UNINDENT
.INDENT 7.0
.TP
.BI \-o \ OUTPUT_DIR\fR,\fB \ \-\-output\-dir \ OUTPUT_DIR
Do not send, write raw messages to this directory (forces \-\-dry\-run)
Expand All @@ -630,10 +637,10 @@ Do not add any addresses found in the cover or patch trailers to To: or Cc:
.UNINDENT
.INDENT 7.0
.TP
.B \-\-to TO [TO ...]
.B \-\-to ADDR [ADDR ...]
Addresses to add to the To: list
.TP
.B \-\-cc CC [CC ...]
.B \-\-cc ADDR [ADDR ...]
Addresses to add to the Cc: list
.UNINDENT
.INDENT 7.0
Expand All @@ -643,7 +650,7 @@ Remove yourself from the To: or Cc: list
.UNINDENT
.INDENT 7.0
.TP
.B \-\-resend [RESEND]
.B \-\-resend [vN]
Resend a previously sent version of the series
.UNINDENT
.INDENT 7.0
Expand Down
13 changes: 9 additions & 4 deletions man/b4.5.rst
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,15 @@ Enroll existing branch:
b4 send
~~~~~~~
usage:
b4 send [-h] [-d] [-o OUTPUT_DIR] [--reflect] [--no-trailer-to-cc] [--to TO [TO ...]] [--cc CC [CC ...]] [--not-me-too] [--resend [RESEND]] [--no-sign] [--web-auth-new] [--web-auth-verify VERIFY_TOKEN]
b4 send [-h] [-d | -o OUTPUT_DIR | --dry-run-to ADDR [ADDR ...] | --reflect] [--no-trailer-to-cc] [--to ADDR [ADDR ...]] [--cc ADDR [ADDR ...]] [--not-me-too] [--resend [vN]] [--no-sign] [--web-auth-new] [--web-auth-verify VERIFY_TOKEN]

options:
-h, --help show this help message and exit
-d, --dry-run Do not send, just dump out raw smtp messages to the stdout

--dry-run-to ADDR [ADDR ...]
Like --dry-run, but sends out via email to specified recipients

-o OUTPUT_DIR, --output-dir OUTPUT_DIR
Do not send, write raw messages to this directory (forces --dry-run)

Expand All @@ -407,15 +411,16 @@ options:
--no-trailer-to-cc
Do not add any addresses found in the cover or patch trailers to To: or Cc:

--to TO [TO ...]
--to ADDR [ADDR ...]
Addresses to add to the To: list
--cc CC [CC ...]

--cc ADDR [ADDR ...]
Addresses to add to the Cc: list

--not-me-too
Remove yourself from the To: or Cc: list

--resend [RESEND]
--resend [vN]
Resend a previously sent version of the series

--no-sign
Expand Down

0 comments on commit 4e03211

Please sign in to comment.