aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-05-28 12:00:38 -0400
committerKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-05-28 12:00:38 -0400
commit5e9931c213685938c79d855856a16ff9131772d5 (patch)
treeb459a24de3bb3d3507e0380235ce1f7110277a75
parenta926bac9e6c222e1bfe87ce79d925083c5879060 (diff)
downloadb4-5e9931c213685938c79d855856a16ff9131772d5.tar.gz
Add --no-cover and -o - to output to stdout
By request, provide a way to output the results of b4 am to stdout. This way it can be piped straight to "git am". E.g.: b4 diff 20200526205322.23465-1-mic@digikod.net -o - | git am Requested-by: Rob Herring <robh@kernel.org> Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rw-r--r--b4/__init__.py6
-rw-r--r--b4/command.py4
-rw-r--r--b4/diff.py2
-rw-r--r--b4/mbox.py37
-rw-r--r--man/b4.537
-rw-r--r--man/b4.5.rst38
6 files changed, 69 insertions, 55 deletions
diff --git a/b4/__init__.py b/b4/__init__.py
index a462fe9..5858a0d 100644
--- a/b4/__init__.py
+++ b/b4/__init__.py
@@ -200,7 +200,7 @@ class LoreMailbox:
if reused:
continue
# Try to backfill from that project
- tmp_mbox = mkstemp()[1]
+ tmp_mbox = mkstemp('b4-backfill-mbox')[1]
get_pi_thread_by_msgid(patch.msgid, tmp_mbox, useproject=projmap[entry[1]])
mbx = mailbox.mbox(tmp_mbox)
was = len(self.msgid_map)
@@ -2003,7 +2003,9 @@ def get_pi_thread_by_msgid(msgid, savefile, useproject=None, nocache=False):
logger.debug('t_mbx_url=%s', t_mbx_url)
logger.critical('Grabbing thread from %s', projurl.split('://')[1])
- in_mbxf = get_pi_thread_by_url(t_mbx_url, '%s-loose' % savefile, nocache=nocache)
+
+ tmp_mbox = mkstemp('b4-lookup-mbox')[1]
+ in_mbxf = get_pi_thread_by_url(t_mbx_url, tmp_mbox, nocache=nocache)
if not in_mbxf:
return None
in_mbx = mailbox.mbox(in_mbxf)
diff --git a/b4/command.py b/b4/command.py
index d0d084e..ffa58ef 100644
--- a/b4/command.py
+++ b/b4/command.py
@@ -17,7 +17,7 @@ def cmd_mbox_common_opts(sp):
sp.add_argument('msgid', nargs='?',
help='Message ID to process, or pipe a raw message')
sp.add_argument('-o', '--outdir', default='.',
- help='Output into this directory')
+ help='Output into this directory (or use - to output mailbox contents to stdout)')
sp.add_argument('-p', '--use-project', dest='useproject', default=None,
help='Use a specific project instead of guessing (linux-mm, linux-hardening, etc)')
sp.add_argument('-c', '--check-newer-revisions', dest='checknewer', action='store_true', default=False,
@@ -111,6 +111,8 @@ def cmd():
sp_am.add_argument('-3', '--prep-3way', dest='threeway', action='store_true', default=False,
help='Prepare for a 3-way merge '
'(tries to ensure that all index blobs exist by making a fake commit range)')
+ sp_am.add_argument('--no-cover', dest='nocover', action='store_true', default=False,
+ help='Do not save the cover letter (on by default when using -o -)')
sp_am.set_defaults(func=cmd_am)
# b4 attest
diff --git a/b4/diff.py b/b4/diff.py
index 33a8b0c..7e9125b 100644
--- a/b4/diff.py
+++ b/b4/diff.py
@@ -57,7 +57,7 @@ def diff_same_thread_series(cmdargs):
lmbx.add_message(msg)
mbx.close()
- os.unlink(mboxfile)
+ os.unlink(savefile)
if wantvers and len(wantvers) == 1:
upper = max(lmbx.series.keys())
diff --git a/b4/mbox.py b/b4/mbox.py
index 50e1471..3e69a32 100644
--- a/b4/mbox.py
+++ b/b4/mbox.py
@@ -15,6 +15,7 @@ import re
import time
import json
import fnmatch
+import shutil
import urllib.parse
import xml.etree.ElementTree
@@ -29,6 +30,8 @@ logger = b4.logger
def mbox_to_am(mboxfile, cmdargs):
config = b4.get_main_config()
outdir = cmdargs.outdir
+ if outdir == '-':
+ cmdargs.nocover = True
wantver = cmdargs.wantver
wantname = cmdargs.wantname
covertrailers = cmdargs.covertrailers
@@ -60,11 +63,16 @@ def mbox_to_am(mboxfile, cmdargs):
slug = lser.get_slug(extended=True)
gitbranch = lser.get_slug(extended=False)
- am_filename = os.path.join(outdir, '%s.mbx' % slug)
- am_cover = os.path.join(outdir, '%s.cover' % slug)
+ if outdir != '-':
+ am_filename = os.path.join(outdir, '%s.mbx' % slug)
+ am_cover = os.path.join(outdir, '%s.cover' % slug)
- if os.path.exists(am_filename):
- os.unlink(am_filename)
+ if os.path.exists(am_filename):
+ os.unlink(am_filename)
+ else:
+ # Create a temporary file that we will remove later
+ am_filename = mkstemp('b4-am-stdout')[1]
+ am_cover = None
logger.info('---')
if cmdargs.cherrypick:
@@ -96,6 +104,7 @@ def mbox_to_am(mboxfile, cmdargs):
cherrypick = list(b4.parse_int_range(cmdargs.cherrypick, upper=len(lser.patches)-1))
else:
cherrypick = None
+
logger.critical('Writing %s', am_filename)
mbx = mailbox.mbox(am_filename)
am_mbx = lser.save_am_mbox(mbx, noaddtrailers=cmdargs.noaddtrailers,
@@ -144,7 +153,7 @@ def mbox_to_am(mboxfile, cmdargs):
if not lser.complete:
logger.critical('WARNING: Thread incomplete!')
- if lser.has_cover:
+ if lser.has_cover and not cmdargs.nocover:
lser.save_cover(am_cover)
top_msgid = None
@@ -218,9 +227,13 @@ def mbox_to_am(mboxfile, cmdargs):
logger.critical(' git am %s', am_filename)
am_mbx.close()
- thanks_record_am(lser, cherrypick=cherrypick)
+ if cmdargs.outdir == '-':
+ logger.info('---')
+ with open(am_filename, 'r') as fh:
+ shutil.copyfileobj(fh, sys.stdout)
+ os.unlink(am_filename)
- return am_filename
+ thanks_record_am(lser, cherrypick=cherrypick)
def thanks_record_am(lser, cherrypick=None):
@@ -461,7 +474,9 @@ def main(cmdargs):
msgid = b4.get_msgid(cmdargs)
wantname = cmdargs.wantname
outdir = cmdargs.outdir
- if wantname:
+ if outdir == '-':
+ savefile = mkstemp('b4-mbox')[1]
+ elif wantname:
savefile = os.path.join(outdir, wantname)
else:
# Save it into msgid.mbox
@@ -493,3 +508,9 @@ def main(cmdargs):
mbx = mailbox.mbox(threadmbox)
logger.critical('Saved %s', threadmbox)
logger.critical('%s messages in the thread', len(mbx))
+ mbx.close()
+ if cmdargs.outdir == '-':
+ logger.info('---')
+ with open(threadmbox, 'r') as fh:
+ shutil.copyfileobj(fh, sys.stdout)
+ os.unlink(threadmbox)
diff --git a/man/b4.5 b/man/b4.5
index 9ea05d0..95876b8 100644
--- a/man/b4.5
+++ b/man/b4.5
@@ -86,11 +86,10 @@ msgid Message ID to process, or pipe a raw message
show this help message and exit
.TP
.BI \-o \ OUTDIR\fP,\fB \ \-\-outdir \ OUTDIR
-Output into this directory
+Output into this directory (or use \- to output mailbox contents to stdout)
.TP
.BI \-p \ USEPROJECT\fP,\fB \ \-\-use\-project \ USEPROJECT
-Use a specific project instead of guessing (linux\-mm,
-linux\-hardening, etc)
+Use a specific project instead of guessing (linux\-mm, linux\-hardening, etc)
.TP
.B \-c\fP,\fB \-\-check\-newer\-revisions
Check if newer patch revisions exist
@@ -99,8 +98,7 @@ Check if newer patch revisions exist
Filename to name the mbox file
.TP
.BI \-m \ LOCALMBOX\fP,\fB \ \-\-use\-local\-mbox \ LOCALMBOX
-Instead of grabbing a thread from lore, process this
-mbox file
+Instead of grabbing a thread from lore, process this mbox file
.TP
.B \-C\fP,\fB \-\-no\-cache
Do not use local cache
@@ -124,11 +122,10 @@ msgid Message ID to process, or pipe a raw message
show this help message and exit
.TP
.BI \-o \ OUTDIR\fP,\fB \ \-\-outdir \ OUTDIR
-Output into this directory
+Output into this directory (or use \- to output mailbox contents to stdout)
.TP
.BI \-p \ USEPROJECT\fP,\fB \ \-\-use\-project \ USEPROJECT
-Use a specific project instead of guessing (linux\-mm,
-linux\-hardening, etc)
+Use a specific project instead of guessing (linux\-mm, linux\-hardening, etc)
.TP
.B \-c\fP,\fB \-\-check\-newer\-revisions
Check if newer patch revisions exist
@@ -137,8 +134,7 @@ Check if newer patch revisions exist
Filename to name the mbox file
.TP
.BI \-m \ LOCALMBOX\fP,\fB \ \-\-use\-local\-mbox \ LOCALMBOX
-Instead of grabbing a thread from lore, process this
-mbox file
+Instead of grabbing a thread from lore, process this mbox file
.TP
.B \-C\fP,\fB \-\-no\-cache
Do not use local cache
@@ -165,16 +161,16 @@ Add a lore.kernel.org/r/ link to every patch
Save mbox patches in a quilt\-ready folder
.TP
.BI \-P \ CHERRYPICK\fP,\fB \ \-\-cherry\-pick \ CHERRYPICK
-Cherry\-pick a subset of patches (e.g. "\-P 1\-2,4,6\-",
-"\-P _" to use just the msgid specified,
-or "\-P *globbing*" to match on commit subject)
+Cherry\-pick a subset of patches (e.g. "\-P 1\-2,4,6\-", "\-P _" to use just the msgid specified, or "\-P *globbing*" to match on commit subject)
.TP
.B \-g\fP,\fB \-\-guess\-base
Try to guess the base of the series (if not specified)
.TP
.B \-3\fP,\fB \-\-prep\-3way
-Prepare for a 3\-way merge (tries to ensure that all
-index blobs exist by making a fake commit range)
+Prepare for a 3\-way merge (tries to ensure that all index blobs exist by making a fake commit range)
+.TP
+.B \-\-no\-cover
+Do not save the cover letter (on by default when using \-o \-)
.UNINDENT
.UNINDENT
.sp
@@ -198,12 +194,10 @@ show this help message and exit
Use a custom From field
.TP
.B \-n\fP,\fB \-\-no\-submit
-Do not submit attestation, just save the message ready
-to send
+Do not submit attestation, just save the message ready to send
.TP
.BI \-o \ OUTPUT\fP,\fB \ \-\-output \ OUTPUT
-Save attestation message in this file if not
-submitting it
+Save attestation message in this file if not submitting it
.UNINDENT
.UNINDENT
.sp
@@ -236,8 +230,7 @@ Check if pull request has already been applied
Convert a pull request into an mbox full of patches
.TP
.BI \-o \ OUTMBOX\fP,\fB \ \-\-output\-mbox \ OUTMBOX
-Save exploded messages into this mailbox (default:
-msgid.mbx)
+Save exploded messages into this mailbox (default: msgid.mbx)
.UNINDENT
.UNINDENT
.sp
@@ -323,6 +316,8 @@ Save diff into this file instead of outputting to stdout
.B \-c\fP,\fB \-\-color
Force color output even when writing to file
.UNINDENT
+.IP "System Message: WARNING/2 (b4.5.rst:, line 201)"
+Option list ends without a blank line; unexpected unindent.
.INDENT 0.0
.TP
.B \-m AMBOX AMBOX, \-\-compare\-am\-mboxes AMBOX AMBOX
diff --git a/man/b4.5.rst b/man/b4.5.rst
index d8e28f6..a27241a 100644
--- a/man/b4.5.rst
+++ b/man/b4.5.rst
@@ -53,17 +53,15 @@ positional arguments:
optional arguments:
-h, --help show this help message and exit
-o OUTDIR, --outdir OUTDIR
- Output into this directory
+ Output into this directory (or use - to output mailbox contents to stdout)
-p USEPROJECT, --use-project USEPROJECT
- Use a specific project instead of guessing (linux-mm,
- linux-hardening, etc)
+ Use a specific project instead of guessing (linux-mm, linux-hardening, etc)
-c, --check-newer-revisions
Check if newer patch revisions exist
-n WANTNAME, --mbox-name WANTNAME
Filename to name the mbox file
-m LOCALMBOX, --use-local-mbox LOCALMBOX
- Instead of grabbing a thread from lore, process this
- mbox file
+ Instead of grabbing a thread from lore, process this mbox file
-C, --no-cache Do not use local cache
*Example*: b4 mbox 20200313231252.64999-1-keescook@chromium.org
@@ -79,17 +77,15 @@ positional arguments:
optional arguments:
-h, --help show this help message and exit
-o OUTDIR, --outdir OUTDIR
- Output into this directory
+ Output into this directory (or use - to output mailbox contents to stdout)
-p USEPROJECT, --use-project USEPROJECT
- Use a specific project instead of guessing (linux-mm,
- linux-hardening, etc)
+ Use a specific project instead of guessing (linux-mm, linux-hardening, etc)
-c, --check-newer-revisions
Check if newer patch revisions exist
-n WANTNAME, --mbox-name WANTNAME
Filename to name the mbox file
-m LOCALMBOX, --use-local-mbox LOCALMBOX
- Instead of grabbing a thread from lore, process this
- mbox file
+ Instead of grabbing a thread from lore, process this mbox file
-C, --no-cache Do not use local cache
-v WANTVER, --use-version WANTVER
Get a specific version of the patch/series
@@ -103,14 +99,14 @@ optional arguments:
-l, --add-link Add a lore.kernel.org/r/ link to every patch
-Q, --quilt-ready Save mbox patches in a quilt-ready folder
-P CHERRYPICK, --cherry-pick CHERRYPICK
- Cherry-pick a subset of patches (e.g. "-P 1-2,4,6-",
- "-P _" to use just the msgid specified,
- or "-P \*globbing\*" to match on commit subject)
+ Cherry-pick a subset of patches (e.g. "-P 1-2,4,6-", "-P _" to use just the msgid specified, or "-P \*globbing\*" to match on commit subject)
-g, --guess-base
Try to guess the base of the series (if not specified)
-3, --prep-3way
- Prepare for a 3-way merge (tries to ensure that all
- index blobs exist by making a fake commit range)
+ Prepare for a 3-way merge (tries to ensure that all index blobs exist by making a fake commit range)
+ --no-cover
+ Do not save the cover letter (on by default when using -o -)
+
*Example*: b4 am 20200313231252.64999-1-keescook@chromium.org
@@ -126,11 +122,10 @@ optional arguments:
-h, --help show this help message and exit
-f SENDER, --from SENDER
Use a custom From field
- -n, --no-submit Do not submit attestation, just save the message ready
- to send
+ -n, --no-submit
+ Do not submit attestation, just save the message ready to send
-o OUTPUT, --output OUTPUT
- Save attestation message in this file if not
- submitting it
+ Save attestation message in this file if not submitting it
*Example*: b4 attest -n -o output/xxxx-attestation.patch output/\*.patch
@@ -151,8 +146,7 @@ optional arguments:
-c, --check Check if pull request has already been applied
-e, --explode Convert a pull request into an mbox full of patches
-o OUTMBOX, --output-mbox OUTMBOX
- Save exploded messages into this mailbox (default:
- msgid.mbx)
+ Save exploded messages into this mailbox (default: msgid.mbx)
*Example*: b4 pr 202003292120.2BDCB41@keescook
@@ -208,7 +202,7 @@ optional arguments:
-m AMBOX AMBOX, --compare-am-mboxes AMBOX AMBOX
Compare two mbx files prepared with "b4 am"
-*Example*: b4 diff
+*Example*: b4 diff 20200526205322.23465-1-mic@digikod.net
CONFIGURATION
-------------