All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] Add --dry-run (-n) option to b4 ty
@ 2020-05-14  5:30 Michael Ellerman
  0 siblings, 0 replies; only message in thread
From: Michael Ellerman @ 2020-05-14  5:30 UTC (permalink / raw)
  To: tools

Currently `b4 ty -a` generates the thanks messages and also archives
the metadata for the associated commits (by renaming them to x.sent).

This means you can't run `b4 ty -a` just to see what it will do.

Although `b4 ty -l` exists, that only shows which series b4 knows
about, it doesn't show which commits b4 is able to match and generate
thanks for.

So add a --dry-run (-n) option that does everything except archive the
metadata, which allows a user to see what `b4 ty -a` can match and the
thanks that are generated without committing to sending.
---
 b4/command.py |  2 ++
 b4/ty.py      | 15 +++++++++------
 2 files changed, 11 insertions(+), 6 deletions(-)


This is RFC because I'm not sure if the plan is to eventually have b4 actually
invoke git send email (optionally), etc, and if so how this would interact with
that.

Another option would be to have `-a` behave like a dry run unless `-s` is also
specified, but that would be a backward incompatible UI change.

cheers

diff --git a/b4/command.py b/b4/command.py
index 6d516a3..1e120bf 100644
--- a/b4/command.py
+++ b/b4/command.py
@@ -160,6 +160,8 @@ logger = b4.logger
                        help='The branch to check against, instead of current')
     sp_ty.add_argument('--since', default='1.week',
                        help='The --since option to use when auto-matching patches (default=1.week)')
+    sp_ty.add_argument('-n', '--dry-run', action='store_true', dest='dry_run', default=False,
+                       help="Dry run, don't actually send or update b4 state.")
     sp_ty.set_defaults(func=cmd_ty)
 
     cmdargs = parser.parse_args()
diff --git a/b4/ty.py b/b4/ty.py
index 44f4451..9c9c35e 100644
--- a/b4/ty.py
+++ b/b4/ty.py
@@ -381,11 +381,11 @@ BRANCH_INFO = None
         sys.exit(0)
 
     logger.info('---')
-    send_messages(applied, cmdargs.gitdir, cmdargs.outdir, wantbranch, since=cmdargs.since)
+    send_messages(applied, cmdargs.gitdir, cmdargs.outdir, wantbranch, cmdargs.dry_run, since=cmdargs.since)
     sys.exit(0)
 
 
-def send_messages(listing, gitdir, outdir, branch, since='1.week'):
+def send_messages(listing, gitdir, outdir, branch, dry_run, since='1.week'):
     # Not really sending, but writing them out to be sent on your own
     # We'll probably gain ability to send these once the feature is
     # more mature and we're less likely to mess things up
@@ -434,9 +434,12 @@ BRANCH_INFO = None
         bout = msg.as_string(policy=b4.emlpolicy)
         with open(outfile, 'wb') as fh:
             fh.write(bout.encode('utf-8'))
-        logger.debug('Cleaning up: %s', jsondata['trackfile'])
-        fullpath = os.path.join(datadir, jsondata['trackfile'])
-        os.rename(fullpath, '%s.sent' % fullpath)
+
+        if not dry_run:
+            logger.debug('Cleaning up: %s', jsondata['trackfile'])
+            fullpath = os.path.join(datadir, jsondata['trackfile'])
+            os.rename(fullpath, '%s.sent' % fullpath)
+
     logger.info('---')
     if not outgoing:
         logger.info('No thanks necessary.')
@@ -505,7 +508,7 @@ BRANCH_INFO = None
         sys.exit(0)
 
     wantbranch = get_wanted_branch(cmdargs)
-    send_messages(listing, cmdargs.gitdir, cmdargs.outdir, wantbranch, cmdargs.since)
+    send_messages(listing, cmdargs.gitdir, cmdargs.outdir, wantbranch, cmdargs.dry_run, cmdargs.since)
     sys.exit(0)
 
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-05-14  5:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-14  5:30 [RFC PATCH] Add --dry-run (-n) option to b4 ty Michael Ellerman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.