diff --git a/src/b4/dig.py b/src/b4/dig.py index e5577a2..71e4fc7 100644 --- a/src/b4/dig.py +++ b/src/b4/dig.py @@ -25,6 +25,55 @@ try_diff_algos: List[str] = [ ] +def has_stable_header(msg: EmailMessage) -> bool: + """Check if the message has an X-stable header.""" + for header_name in msg.keys(): + if header_name.lower() == 'x-stable': + return True + return False + + +def filter_stable_messages(lmbx: b4.LoreMailbox) -> None: + """Remove messages with X-stable header from a LoreMailbox.""" + # Filter msgid_map + stable_msgids = [] + for msgid, lmsg in lmbx.msgid_map.items(): + if has_stable_header(lmsg.msg): + logger.debug('Ignoring -stable message: %s', lmsg.full_subject) + stable_msgids.append(msgid) + + for msgid in stable_msgids: + del lmbx.msgid_map[msgid] + + # Filter followups + lmbx.followups = [lmsg for lmsg in lmbx.followups + if not has_stable_header(lmsg.msg)] + + # Filter unknowns + lmbx.unknowns = [lmsg for lmsg in lmbx.unknowns + if not has_stable_header(lmsg.msg)] + + # Filter covers + stable_cover_revs = [] + for rev, lmsg in lmbx.covers.items(): + if has_stable_header(lmsg.msg): + stable_cover_revs.append(rev) + + for rev in stable_cover_revs: + del lmbx.covers[rev] + + # Filter series patches + for rev, lser in list(lmbx.series.items()): + original_count = len([p for p in lser.patches if p is not None]) + lser.patches = [p if p is None or not has_stable_header(p.msg) else None + for p in lser.patches] + filtered_count = len([p for p in lser.patches if p is not None]) + + # Remove series if all patches were filtered out + if filtered_count == 0: + del lmbx.series[rev] + + def dig_commit(cmdargs: argparse.Namespace) -> None: config = b4.get_main_config() cfg_llval = config.get('linkmask', '') @@ -101,6 +150,12 @@ def dig_commit(cmdargs: argparse.Namespace) -> None: lmbx = b4.get_series_by_patch_id(patch_id) if lmbx: logger.info('Found matching series by patch-id') + filter_stable_messages(lmbx) + # Check if we still have any series after filtering + if not lmbx.series: + logger.debug('All series filtered out due to X-stable header') + lmbx = None + continue break if not lmbx: @@ -111,6 +166,9 @@ def dig_commit(cmdargs: argparse.Namespace) -> None: logger.info('Found %s matching messages', len(msgs)) lmbx = b4.LoreMailbox() for msg in msgs: + if has_stable_header(msg): + logger.debug('Ignoring -stable message: %s', msg.get('subject', '')) + continue lmbx.add_message(msg) else: logger.error('Could not find anything matching commit %s', commit) @@ -147,6 +205,9 @@ def dig_commit(cmdargs: argparse.Namespace) -> None: q_msgs = b4.get_pi_search_results(q, full_threads=True) if q_msgs: for q_msg in q_msgs: + if has_stable_header(q_msg): + logger.debug('Ignoring -stable message: %s', q_msg.get('subject', '')) + continue lmbx.add_message(q_msg) break