From 6ca672ed87a6f8812fa408ea0b3161e68ce2351e Mon Sep 17 00:00:00 2001 From: Konstantin Ryabitsev Date: Tue, 19 May 2020 18:21:53 -0400 Subject: Display range-diff by default Don't make developers do copy-pasting unnecessarily. Switch to outputting the diff by default, with flag options to save to file or just show what needs to be done. Additionally, adds caching to lookups and remember previously generated fake-am ranges so we don't continuously generate loose objects on repeat runs. Signed-off-by: Konstantin Ryabitsev --- b4/__init__.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'b4/__init__.py') diff --git a/b4/__init__.py b/b4/__init__.py index 064f8b8..414f669 100644 --- a/b4/__init__.py +++ b/b4/__init__.py @@ -1844,7 +1844,13 @@ def save_strict_thread(in_mbx, out_mbx, msgid): logger.info('Reduced thread to strict matches only (%s->%s)', len(in_mbx), len(out_mbx)) -def get_pi_thread_by_url(t_mbx_url, savefile): +def get_pi_thread_by_url(t_mbx_url, savefile, nocache=False): + cachedir = get_cache_dir() + cachefile = os.path.join(cachedir, '%s.pi.mbx' % urllib.parse.quote_plus(t_mbx_url)) + if os.path.exists(cachefile) and not nocache: + logger.debug('Using cached copy: %s', cachefile) + shutil.copyfile(cachefile, savefile) + return savefile session = get_requests_session() resp = session.get(t_mbx_url) if resp.status_code != 200: @@ -1858,22 +1864,13 @@ def get_pi_thread_by_url(t_mbx_url, savefile): with open(savefile, 'wb') as fh: logger.debug('Saving %s', savefile) fh.write(t_mbox) + shutil.copyfile(savefile, cachefile) return savefile def get_pi_thread_by_msgid(msgid, savefile, useproject=None, nocache=False): qmsgid = urllib.parse.quote_plus(msgid) config = get_main_config() - cachedir = get_cache_dir() - base = msgid - if useproject: - base = '%s-%s' % (useproject, msgid) - cachefile = os.path.join(cachedir, '%s.pi.mbx' % urllib.parse.quote_plus(base)) - if os.path.exists(cachefile) and not nocache: - logger.debug('Using cached copy: %s', cachefile) - shutil.copyfile(cachefile, savefile) - return savefile - # Grab the head from lore, to see where we are redirected midmask = config['midmask'] % qmsgid loc = urllib.parse.urlparse(midmask) @@ -1894,7 +1891,7 @@ 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) + in_mbxf = get_pi_thread_by_url(t_mbx_url, '%s-loose' % savefile, nocache=nocache) if not in_mbxf: return None in_mbx = mailbox.mbox(in_mbxf) @@ -1903,7 +1900,6 @@ def get_pi_thread_by_msgid(msgid, savefile, useproject=None, nocache=False): in_mbx.close() out_mbx.close() os.unlink(in_mbxf) - shutil.copyfile(savefile, cachefile) return savefile -- cgit v1.2.3