aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--b4/__init__.py19
-rw-r--r--b4/command.py2
-rw-r--r--b4/mbox.py7
-rw-r--r--b4/pr.py16
4 files changed, 28 insertions, 16 deletions
diff --git a/b4/__init__.py b/b4/__init__.py
index 05bd9bb..432a8cd 100644
--- a/b4/__init__.py
+++ b/b4/__init__.py
@@ -2021,6 +2021,15 @@ def git_temp_worktree(gitdir=None, commitish=None):
@contextmanager
def git_temp_clone(gitdir=None):
"""Context manager that creates a temporary shared clone."""
+ if gitdir is None:
+ topdir = git_get_toplevel()
+ if topdir and os.path.isdir(os.path.join(topdir, '.git')):
+ gitdir = os.path.join(topdir, '.git')
+
+ if not gitdir:
+ logger.critical('Current directory is not a git checkout. Try using -g.')
+ return None
+
with TemporaryDirectory() as dfn:
gitargs = ['clone', '--mirror', '--shared', gitdir, dfn]
git_run_command(None, gitargs)
@@ -2352,6 +2361,16 @@ def git_branch_contains(gitdir, commit_id):
return lines
+def git_get_toplevel(path=None):
+ topdir = None
+ # Are we in a git tree and if so, what is our toplevel?
+ gitargs = ['rev-parse', '--show-toplevel']
+ lines = git_get_command_lines(path, gitargs)
+ if len(lines) == 1:
+ topdir = lines[0]
+ return topdir
+
+
def format_addrs(pairs):
addrs = set()
for pair in pairs:
diff --git a/b4/command.py b/b4/command.py
index 1e571a6..0c87df9 100644
--- a/b4/command.py
+++ b/b4/command.py
@@ -143,8 +143,6 @@ def cmd():
help='Convert a pull request into an mbox full of patches')
sp_pr.add_argument('-o', '--output-mbox', dest='outmbox', default=None,
help='Save exploded messages into this mailbox (default: msgid.mbx)')
- sp_pr.add_argument('-p', '--public-inbox', dest='pi', default=None,
- help='Append exploded messages into this public-inbox repository')
sp_pr.add_argument('-l', '--retrieve-links', action='store_true', dest='getlinks', default=False,
help='Attempt to retrieve any Link: URLs (use with -e)')
sp_pr.add_argument('-f', '--from-addr', dest='mailfrom', default=None,
diff --git a/b4/mbox.py b/b4/mbox.py
index 200cf1c..459fb9a 100644
--- a/b4/mbox.py
+++ b/b4/mbox.py
@@ -143,12 +143,7 @@ def mbox_to_am(mboxfile, cmdargs):
logger.critical(' Msg From: %s <%s>', fname, femail)
logger.critical('NOTE: Rerun with -S to apply them anyway')
- topdir = None
- # Are we in a git tree and if so, what is our toplevel?
- gitargs = ['rev-parse', '--show-toplevel']
- lines = b4.git_get_command_lines(None, gitargs)
- if len(lines) == 1:
- topdir = lines[0]
+ topdir = b4.git_get_toplevel()
if cmdargs.threeway:
if not topdir:
diff --git a/b4/pr.py b/b4/pr.py
index a491014..ef390a2 100644
--- a/b4/pr.py
+++ b/b4/pr.py
@@ -21,7 +21,6 @@ from email import utils, charset
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
-# from email.mime.message import MIMEMessage
charset.add_charset('utf-8', None)
@@ -51,7 +50,7 @@ def format_addrs(pairs):
def git_get_commit_id_from_repo_ref(repo, ref):
# We only handle git and http/s URLs
if not (repo.find('git://') == 0 or repo.find('http://') == 0 or repo.find('https://') == 0):
- logger.debug('%s uses unsupported protocol', repo)
+ logger.info('%s uses unsupported protocol', repo)
return None
logger.debug('getting commit-id from: %s %s', repo, ref)
@@ -286,6 +285,11 @@ def explode(gitdir, lmsg, mailfrom=None, retrieve_links=True):
config = b4.get_main_config()
linked_ids = set()
+ if retrieve_links:
+ # Insert the pull request itself into linked_ids, so we preserve it as part
+ # of the archived threads.
+ linked_ids.add(lmsg.msgid)
+
with b4.git_format_patches(gitdir, lmsg.pr_base_commit, 'FETCH_HEAD', prefixes=prefixes) as pdir:
if pdir is None:
sys.exit(1)
@@ -380,7 +384,7 @@ def explode(gitdir, lmsg, mailfrom=None, retrieve_links=True):
if amsgid not in seen_msgids:
seen_msgids.add(amsgid)
logger.debug('Added linked: %s', amsg.get('Subject'))
- tmbx.add(amsg.as_bytes(policy=b4.emlpolicy))
+ tmbx.add(amsg.as_string(policy=b4.emlpolicy).encode())
ambx.close()
os.unlink(savefile)
@@ -442,10 +446,6 @@ def main(cmdargs):
lmsg.pr_tip_commit = lmsg.pr_remote_tip_commit
if cmdargs.explode:
- if cmdargs.pi:
- logger.critical('Saving to public-inbox not supported yet.')
- sys.exit(1)
-
savefile = cmdargs.outmbox
if savefile is None:
savefile = '%s.mbx' % lmsg.msgid
@@ -459,7 +459,7 @@ def main(cmdargs):
if msgs:
smbx = mailbox.mbox(savefile)
for msg in msgs:
- smbx.add(msg.as_bytes(policy=b4.emlpolicy))
+ smbx.add(msg.as_string(policy=b4.emlpolicy).encode())
smbx.close()
logger.info('---')
logger.info('Saved %s', savefile)