Skip to contentSkip to conversation

Add --dry-run (-n) option to b4 ty

RFC PATCH New Michael Ellerman 1 participant 1 message May 14, 2020

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 Add --dry-run (-n) option to b4 ty

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

b4/command.py +2 -0
index 6d516a3..1e120bf 100644
@@ -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()
b4/ty.py +9 -6
index 44f4451..9c9c35e 100644
@@ -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)
 
 
Signature · 1 line
2.25.1