From patchwork Fri May 1 10:59:57 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2248 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=1777633272; bh=dNClcfk6E6GmCXcD1KprZOKyVav9cH1YZiFnPOVbELY=; 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=azmG2hY5k8pni8hwdKvvs/ClQ57U3rcjxlXBMP90w+BEiq3B9dTZYDIysytTDByUs 2+nEWH75esKsuIK4PCGmq6ZwXx7ix3Q2cwgcLJ+PI906mDhZ0zByYmj9H2IF/Oo+Zq Zw4m4JkbwoHB5oVOLFeaZoPalyIhLykK3gttMpxM= Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4A21E6A836 for ; Fri, 1 May 2026 05:01:12 -0600 (MDT) 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 yo7SdHxIiJbI for ; Fri, 1 May 2026 05:01:12 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1777633272; bh=dNClcfk6E6GmCXcD1KprZOKyVav9cH1YZiFnPOVbELY=; 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=azmG2hY5k8pni8hwdKvvs/ClQ57U3rcjxlXBMP90w+BEiq3B9dTZYDIysytTDByUs 2+nEWH75esKsuIK4PCGmq6ZwXx7ix3Q2cwgcLJ+PI906mDhZ0zByYmj9H2IF/Oo+Zq Zw4m4JkbwoHB5oVOLFeaZoPalyIhLykK3gttMpxM= Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 316FD6A833 for ; Fri, 1 May 2026 05:01:12 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1777633270; bh=CPxxMGWdOGYf0tXvT7sGV9uh1JRQ/D7s/wPZtUoUNbk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qZlpq8JEO5yEFHrDckk8tAB+ZQQVwbC9wLgyiSuUVXbqxAJ/B85Vz24yd1aHd3f1H Lkj+bJRRhq7MvJf+J6hj4AIUw5xBfS7WKUl7tUI8buuytEAgnCN3t/vTInEA3SYHT8 yobNLMmyyI1Oi7swyVYPnbaJ4b7dK9D4n0qP8Vqc= Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9B0836A836; Fri, 1 May 2026 05:01:10 -0600 (MDT) 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 WwY2QM1u5ja7; Fri, 1 May 2026 05:01:10 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1777633266; bh=TzLzMF3mhAK3xZqkcTy0tUrppAGewU8QOTtkCEw0SRI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sbdKIA4Iz+54QAsPSTjYVNHc6WKFV34GaMmKLaUe9y5QePPomOuBuI6jpqtuVRwGw fZzgRE70eO8GfyLAt25koiNIYngJbZC8hEWDxLtIBdmRtPM6zHSL24q07dX9Y9oDZ6 96OLYbGlCmd6wFRL7UWpOfeqtfzbZvAYg99SeHMo= Received: from u-boot.org (unknown [174.51.25.52]) by mail.u-boot.org (Postfix) with ESMTPSA id 391256A7AF; Fri, 1 May 2026 05:01:06 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Fri, 1 May 2026 04:59:57 -0600 Message-ID: <20260501110040.1874719-6-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260501110040.1874719-1-sjg@u-boot.org> References: <20260501110040.1874719-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: HSTPBJUXTSNYKUJZQXZVRJYZKOT3E57E X-Message-ID-Hash: HSTPBJUXTSNYKUJZQXZVRJYZKOT3E57E 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 X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 05/29] patman: Use gitutil helpers in review.py 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 review.py runs a handful of git commands directly through command.output() and command.run_one(): a 'diff --stat' for the review prompt, checkout/stash/stash-pop for branch-and-stash bookkeeping around an apply, a 'rev-parse --verify' to choose between the upstream's '/next' and '/master' branches, and 'rev-parse --abbrev-ref HEAD' to remember the current branch. The helpers added in 'u_boot_pylib: Add gitutil helpers for repo-aware git operations' cover all of these. Switch each call site to the corresponding helper: - diff_stat() for the review-prompt diffstat - checkout_branch() and stash_pop() for the cleanup path - ref_exists() for the upstream-branch probe - current_branch() and stash_save(include_untracked=True) for the pre-apply bookkeeping review.py no longer assembles 'git ...' argv lists itself. Signed-off-by: Simon Glass --- tools/patman/review.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/tools/patman/review.py b/tools/patman/review.py index f0fa4e865e4..09614c85ed7 100644 --- a/tools/patman/review.py +++ b/tools/patman/review.py @@ -983,9 +983,8 @@ async def _review_single_patch(ctx, cmt, seq, all_commits): commit_msg = body else: commit_msg = (cmt.subject + '\n' + body).strip() - ctx.diffstat = command.output('git', 'diff', '--stat', - f'{cmt.hash}~..{cmt.hash}', - cwd=ctx.repo_path).strip() + ctx.diffstat = gitutil.diff_stat(f'{cmt.hash}~..{cmt.hash}', + ctx.repo_path).strip() previous_review = ctx.previous_reviews.get(seq) prompt = _build_review_prompt(ctx, cmt.hash, seq, all_commits, @@ -1134,9 +1133,9 @@ def _git_restore(orig_branch, had_stash, repo_path): try: if orig_branch and repo_path: - command.output('git', 'checkout', orig_branch, cwd=repo_path) + gitutil.checkout_branch(orig_branch, repo_path) if had_stash: - command.output('git', 'stash', 'pop', cwd=repo_path) + gitutil.stash_pop(repo_path) except command.CommandExc: pass @@ -1582,9 +1581,7 @@ def _get_upstream_branch(args, cser): ups = cser.db.upstream_get_default() if ups: branch = f'{ups}/next' - ret = command.run_one('git', 'rev-parse', '--verify', branch, - capture=True, raise_on_error=False) - if ret.return_code: + if not gitutil.ref_exists(branch): branch = f'{ups}/master' return branch return 'origin/master' @@ -1607,9 +1604,9 @@ def _apply_and_check(ctx, link): ctx.upstream_branch, repo_path) if success: - applied = command.output('git', 'rev-list', '--count', - f'{ctx.upstream_branch}..{branch_name}', cwd=repo_path).strip() - if int(applied) == 0: + applied = gitutil.count_revs( + repo_path, f'{ctx.upstream_branch}..{branch_name}') + if not applied: success = False if not success: @@ -1774,10 +1771,9 @@ def do_review(args, pwork, cser): try: ctx.upstream_branch = _get_upstream_branch(args, cser) ctx.repo_path = gitutil.get_top_level() - orig_branch = command.output('git', 'rev-parse', '--abbrev-ref', - 'HEAD', cwd=ctx.repo_path).strip() + orig_branch = gitutil.current_branch(ctx.repo_path) try: - stash_out = command.output('git', 'stash', cwd=ctx.repo_path) + stash_out = gitutil.stash_save(ctx.repo_path) if 'No local changes' not in stash_out: had_stash = True except command.CommandExc: