From patchwork Sun Feb 22 15:42:44 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1925 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1771775022; bh=5coj6nBF1w90K3fcxlqw0vei9ruyyVojR7fZXzUhaXc=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=moHkXUF7Q7NgQjYEx7qKIu1Pz12dCCCXgFYkudBU4bjVbo4YumrvZtCYrXUCLwh81 2FFI0h+6RJkmyZVKM0oW+t9KWkGsM99JSoCPmoU2A4QsA+6HH417ZScWEabIfmQfNX +geLwgrRJchklstQ4+xRYFLxrPC3AcExTtiPzUh4VyfuiSoexHmCniUSCtvO1z9qQ1 8KfNePM8u9xsybNaVHRc7HrQZZcS49YCxGOyRDB7uPSwYNIm/fTlc99brXUgH00iQ1 k8t+BNQiRxvrO6M81xYlj6GcMfPBLNTY9NNuXFtqeFnU7tM+BxVj//5wmA//twqP1Y OwVU+9Hzol/mw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 36FEF69C78 for ; Sun, 22 Feb 2026 08:43:42 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id ahC2ijpIJKyS for ; Sun, 22 Feb 2026 08:43:42 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1771775022; bh=5coj6nBF1w90K3fcxlqw0vei9ruyyVojR7fZXzUhaXc=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=moHkXUF7Q7NgQjYEx7qKIu1Pz12dCCCXgFYkudBU4bjVbo4YumrvZtCYrXUCLwh81 2FFI0h+6RJkmyZVKM0oW+t9KWkGsM99JSoCPmoU2A4QsA+6HH417ZScWEabIfmQfNX +geLwgrRJchklstQ4+xRYFLxrPC3AcExTtiPzUh4VyfuiSoexHmCniUSCtvO1z9qQ1 8KfNePM8u9xsybNaVHRc7HrQZZcS49YCxGOyRDB7uPSwYNIm/fTlc99brXUgH00iQ1 k8t+BNQiRxvrO6M81xYlj6GcMfPBLNTY9NNuXFtqeFnU7tM+BxVj//5wmA//twqP1Y OwVU+9Hzol/mw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 24CBD69D36 for ; Sun, 22 Feb 2026 08:43:42 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1771775020; bh=xRq+QP98MhqIKl9wSkCc57e3Tkd51FnKWuMYz8DlRNc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CCROp1YIWInkfp5/E/hGgB8HdlGUwl09MyC3su1zKmX+f70RsPMzStO1zZdF8/TBW PGZMxddAhyYHTjWTMdFctDHw7bWxkMWtqwTs9Ok9MeXU9JoFZYlS0xCSvXSbA+x22I AmkvAztxiviV6YwpMSovZepb5ZZ111cRYdJmyugA/6QuJzVRAT5l2tSGNscO9d/+eu hoK6rFHBleFQfasg3AKPEdmH14ZryBjIyFhV7BSZAMdzmDBdRhs6tblUZyy4nSZb0y mAL2s2G/8LtnH8sbeLjEV3oBzd5h93bFm+rU7LJuEVY/EZPOvX4Us5nKX0sAN2ZwGB VTBLHAvdj3D4A== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E8FFE69C78; Sun, 22 Feb 2026 08:43:40 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id R4CQqH_4rZ9N; Sun, 22 Feb 2026 08:43:40 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1771775016; bh=lZY9TH1+Q7GSt3zZN8OK0f0dABuOMvAOyOVdfwS/S3k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xp1MP4gJXGEGlpq3cE6C6M7DjC4eGgGg8zd/iyOryo6Jtq7jkXfChgEC+SPHScSVz 9RTl+D+nQCRmZ3T9X1gSap5q9inuv0P1IM3f+MACwJWujTrb8QwC1FxqWa0OjTCebb azieWx7uGOOvKzZVcsFoXFZLT2USCWDOI4Ma3cMm9Nt/ZHT/kGdPGNqghykaw8FrbG kqOcpMKf3G3W8bQMqBCxnVfoMkV+/07LpbBNInUFbWJPqza5xMy2lURH3j0kUixDTX 9AN3Pcy1tc7SlEHSOoIf0GmO2m44ZWof6YCyXoS8VPVVD/3VjBpqmMKGfICrq7w43l 0bT2ucVgo3B0w== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 7414A69C5C; Sun, 22 Feb 2026 08:43:36 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sun, 22 Feb 2026 08:42:44 -0700 Message-ID: <20260222154303.2851319-5-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260222154303.2851319-1-sjg@u-boot.org> References: <20260222154303.2851319-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: YM4MVW6JYE2SFC6OBJCMTCWTS6WKJJ6O X-Message-ID-Hash: YM4MVW6JYE2SFC6OBJCMTCWTS6WKJJ6O X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass , "Claude Opus 4 . 6" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 04/16] pickman: Refactor decompose_mega_merge() into smaller helpers List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass The three phases of decompose_mega_merge() all follow the same pattern: run git log, parse the output, filter out commits already in the database. Extract two helpers to reduce the duplication: - _mega_preadd(): pre-add the mega-merge commit as 'skipped' in the DB - _mega_get_batch(): common git-log/parse/filter pattern shared by all three phases This makes each phase a single call to _mega_get_batch() instead of repeated inline blocks. Co-developed-by: Claude Opus 4.6 Signed-off-by: Simon Glass --- tools/pickman/control.py | 96 ++++++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 43 deletions(-) diff --git a/tools/pickman/control.py b/tools/pickman/control.py index d3cb8a8fff4..19cd2813b64 100644 --- a/tools/pickman/control.py +++ b/tools/pickman/control.py @@ -964,6 +964,49 @@ def detect_sub_merges(merge_hash): return [line for line in out.split('\n') if line] +def _mega_preadd(dbs, merge_hash): + """Pre-add a mega-merge commit to the database as 'skipped'. + + This prevents the mega-merge from appearing as an orphan commit. + Does nothing if the commit already exists in the database. + """ + if dbs.commit_get(merge_hash): + return + + source_id = None + sources = dbs.source_get_all() + if sources: + source_id = dbs.source_get_id(sources[0][0]) + if source_id: + info = run_git(['log', '-1', '--format=%s|%an', merge_hash]) + parts = info.split('|', 1) + subject = parts[0] + author = parts[1] if len(parts) > 1 else '' + dbs.commit_add(merge_hash, source_id, subject, author, + status='skipped') + dbs.commit() + + +def _mega_get_batch(dbs, exclude_ref, include_ref): + """Fetch a batch of unprocessed commits between two refs. + + Runs git log for the range ^exclude_ref include_ref, parses the + output and filters out commits already in the database. + + Returns: + list: CommitInfo tuples for unprocessed commits, may be empty + """ + log_output = run_git([ + 'log', '--reverse', '--format=%H|%h|%an|%s|%P', + f'^{exclude_ref}', include_ref + ]) + if not log_output: + return [] + + all_commits = parse_log_output(log_output, has_parents=True) + return [c for c in all_commits if not dbs.commit_get(c.hash)] + + def decompose_mega_merge(dbs, prev_commit, merge_hash, sub_merges): """Return the next unprocessed batch from a mega-merge @@ -990,60 +1033,27 @@ def decompose_mega_merge(dbs, prev_commit, merge_hash, sub_merges): first_parent = parents[0] second_parent = parents[1] - # Pre-add the mega-merge commit itself as skipped - if not dbs.commit_get(merge_hash): - source_id = None - sources = dbs.source_get_all() - if sources: - source_id = dbs.source_get_id(sources[0][0]) - if source_id: - info = run_git(['log', '-1', '--format=%s|%an', merge_hash]) - parts = info.split('|', 1) - subject = parts[0] - author = parts[1] if len(parts) > 1 else '' - dbs.commit_add(merge_hash, source_id, subject, author, - status='skipped') - dbs.commit() + _mega_preadd(dbs, merge_hash) # Phase 1: mainline commits before the merge - log_output = run_git([ - 'log', '--reverse', '--format=%H|%h|%an|%s|%P', - f'{prev_commit}..{first_parent}' - ]) - if log_output: - all_commits = parse_log_output(log_output, has_parents=True) - commits = [c for c in all_commits if not dbs.commit_get(c.hash)] - if commits: - return commits, first_parent + commits = _mega_get_batch(dbs, prev_commit, first_parent) + if commits: + return commits, first_parent # Phase 2: sub-merge batches prev_sub = first_parent for sub_hash in sub_merges: - # Get commits for this sub-merge - log_output = run_git([ - 'log', '--reverse', '--format=%H|%h|%an|%s|%P', - f'^{prev_sub}', sub_hash - ]) - if log_output: - all_commits = parse_log_output(log_output, has_parents=True) - commits = [c for c in all_commits if not dbs.commit_get(c.hash)] - if commits: - return commits, None + commits = _mega_get_batch(dbs, prev_sub, sub_hash) + if commits: + return commits, None prev_sub = sub_hash # Phase 3: remainder after the last sub-merge last_sub = sub_merges[-1] if sub_merges else first_parent - log_output = run_git([ - 'log', '--reverse', '--format=%H|%h|%an|%s|%P', - f'^{last_sub}', second_parent - ]) - if log_output: - all_commits = parse_log_output(log_output, has_parents=True) - commits = [c for c in all_commits if not dbs.commit_get(c.hash)] - if commits: - return commits, None + commits = _mega_get_batch(dbs, last_sub, second_parent) + if commits: + return commits, None - # All done return [], None