From 34f5c6886f3e02558101a19cffb479c480ef646e Mon Sep 17 00:00:00 2001 From: Konstantin Ryabitsev Date: Fri, 14 May 2021 16:51:52 -0400 Subject: Don't try to read stdin multiple times With multiple entry points for calling get_msgid(), we may end up trying to read stdin multiple times. Call it once to ensure that this doesn't happen. Suggested-by: Morten Linderud Improved-by: Kyle Meyer Signed-off-by: Konstantin Ryabitsev Link: https://lore.kernel.org/tools/87im4fi55o.fsf@kyleam.com --- b4/mbox.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/b4/mbox.py b/b4/mbox.py index 69429e0..6d4c408 100644 --- a/b4/mbox.py +++ b/b4/mbox.py @@ -28,7 +28,7 @@ from tempfile import mkstemp logger = b4.logger -def mbox_to_am(mboxfile, cmdargs): +def mbox_to_am(mboxfile, cmdargs, msgid): config = b4.get_main_config() outdir = cmdargs.outdir if outdir == '-': @@ -82,7 +82,6 @@ def mbox_to_am(mboxfile, cmdargs): if cmdargs.cherrypick: cherrypick = list() if cmdargs.cherrypick == '_': - msgid = b4.get_msgid(cmdargs) # Only grab the exact msgid provided at = 0 for lmsg in lser.patches[1:]: @@ -499,17 +498,15 @@ def main(cmdargs): cmdargs.nocache = True savefile = mkstemp('b4-mbox')[1] + msgid = b4.get_msgid(cmdargs) if not cmdargs.localmbox: - msgid = b4.get_msgid(cmdargs) - threadfile = b4.get_pi_thread_by_msgid(msgid, savefile, useproject=cmdargs.useproject, nocache=cmdargs.nocache) if threadfile is None: os.unlink(savefile) return else: if os.path.exists(cmdargs.localmbox): - msgid = b4.get_msgid(cmdargs) if os.path.isdir(cmdargs.localmbox): in_mbx = mailbox.Maildir(cmdargs.localmbox) else: @@ -530,7 +527,7 @@ def main(cmdargs): get_extra_series(threadfile, direction=1) if cmdargs.subcmd == 'am': - mbox_to_am(threadfile, cmdargs) + mbox_to_am(threadfile, cmdargs, msgid) os.unlink(threadfile) return @@ -644,7 +641,6 @@ def main(cmdargs): if cmdargs.wantname: savefile = os.path.join(cmdargs.outdir, cmdargs.wantname) else: - msgid = b4.get_msgid(cmdargs) savefile = os.path.join(cmdargs.outdir, '%s.mbx' % msgid) mbx.close() -- cgit v1.2.3