From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id r7Z1DsvifWpvbiMAWB0awg (envelope-from ) for ; Thu, 13 Aug 2026 11:29:15 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=ivpck5bj; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Yu6COBy/; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=YbEWWzON; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=6hcDvyTB; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id EA9D01E166; Thu, 13 Aug 2026 11:29:14 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 449781E09B for ; Thu, 13 Aug 2026 11:29:12 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4D04D4BA902C for ; Thu, 13 Aug 2026 15:29:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4D04D4BA902C Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=ivpck5bj; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Yu6COBy/; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=YbEWWzON; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=6hcDvyTB Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id D87314BA79BA for ; Thu, 13 Aug 2026 15:28:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D87314BA79BA Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D87314BA79BA Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786634925; cv=none; b=YyH5sYIw58WwLQwYbm43ULRNlFxZ7UD2bJMkijQbzVdf8Si/W8lDBz8M+ZcflkLnNy02QKAkdXoEeUjg09kPQdMpukI5N/YI2FNqJzP8HyTfkg3BxbBPiPnobqKADq2Uh9tJ+RtPCZBTEBrezr2EfS8Va6e7/7SGl1J4y9SsV90= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786634925; c=relaxed/simple; bh=VqrKGvVrAWsSKJ0NU2MshqDj91njm95mPynj1UybErA=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=CC4dw27amOX40SziH1mw4B70AoO5nf4Baa+pFdd97sP0NFyxMrMel1eJXLCFx4xBD+x5ckStzxlkw1VPfvag8kImgBO8EVOeuBHRUABhvIyaGvEo4TBhUPi5K1Dy7LSRwa+x3BMaVwDMY5whnDQRPxFtUosvrAZOCerMTV1gJNU= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=ivpck5bj; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Yu6COBy/; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=YbEWWzON; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=6hcDvyTB DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D87314BA79BA Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 8E4008289F for ; Thu, 13 Aug 2026 15:28:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1786634918; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=xrIJVnl7PREEs6EZzjhVBlrMtQYu1EA16rTXppPK9Fo=; b=ivpck5bjpH2EHKQwArpPCwn5P6PPHKYRVfNd04o2xZhqxh7hqAIHD1EocFNKWftPpsa+Wg +17fIIXbrPPf68NFCnFI/3tV/IGf/Weq1iZU6o8IqPGFmQ2vNSVl/vOJhjNzVkRws63SB3 sFZ1Wu6mNEjOlpiJ1HXn+Qxjknzweyc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1786634918; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=xrIJVnl7PREEs6EZzjhVBlrMtQYu1EA16rTXppPK9Fo=; b=Yu6COBy/U/5speax51LIzDzZbp8snuBesR4Rk1D+aCce5KIwMhLPA9m+se41Gu8gy2P9cK qJkbvaJOZnP0MdAA== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1786634914; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=xrIJVnl7PREEs6EZzjhVBlrMtQYu1EA16rTXppPK9Fo=; b=YbEWWzON5QEZc08cLtowotOruowVEMAfszXu7XGhVLunG4FzEu3u7KhJTdltj3WIfh/2eM ZiAhgDlhbWZYlnnoh3wlLvaWHgG8lO7kLEeoz1LBgJdzSWvIK/11CHIJeBQkB5yeb9DjxZ nf45Ejc3m/WQOjMpWds3E70Gr+l7tfo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1786634914; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=xrIJVnl7PREEs6EZzjhVBlrMtQYu1EA16rTXppPK9Fo=; b=6hcDvyTBSGFGGH392vCTfkv1WqLgOoI0LKI/zsD6sUbDOCq+e+fOHvEMEAZxBQJflhqqRy HWynnwwjKOWwOLCQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 781AF77EB1 for ; Thu, 13 Aug 2026 15:28:34 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 6LvbG6LifWrGfAAAD6G6ig (envelope-from ) for ; Thu, 13 Aug 2026 15:28:34 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH] [pre-commit] Don't allow pre-release revisions Date: Thu, 13 Aug 2026 17:28:34 +0200 Message-ID: <20260813152834.2591696-1-tdevries@suse.de> X-Mailer: git-send-email 2.51.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.996]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; TO_MATCH_ENVRCPT_ALL(0.00)[]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; FROM_HAS_DN(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCVD_TLS_ALL(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; RCVD_COUNT_TWO(0.00)[2]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:mid] X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org Pre-commit has a convenient autoupdate command. The default behavior is: update to the latest tagged version. For most tools this is fine, and not too frequent. Isort however also tags pre-releases, so that has resulted in more frequent updates: ... $ git log .pre-commit-config.yaml | grep "Bump isort" [pre-commit] Bump isort to 9.0.0b1 [pre-commit] Bump isort to 9.0.0a3 [pre-commit] Bump isort to 9.0.0a2 [pre-commit] Bump isort to 8.0.1 [pre-commit] Bump isort to 8.0.0 ... Add a script gdb/contrib/pre-commit.py that for --config-check checks the revision numbers of all repos, and errors out when finding something like 9.0.0b1: ... $ ./gdb/contrib/pre-commit.py --config-check Revision 9.0.0b1 for repo https://github.com/pycqa/isort not allowed. ... Add a corresponding pre-commit check, and revert isort back to the last stable release: 8.0.1, to make the check pass. Consequently, pre-commit autoupdate now breaks the pre-commit check: ... $ pre-commit autoupdate [https://github.com/psf/black-pre-commit-mirror] already up to date! [https://github.com/pycqa/flake8] already up to date! [https://github.com/pycqa/isort] updating 8.0.1 -> 9.0.0b2 [https://github.com/codespell-project/codespell] already up to date! [https://github.com/nmoroze/tclint] already up to date! [https://github.com/adrienverge/yamllint.git] already up to date! $ ./gdb/contrib/pre-commit.py --config-check Revision 9.0.0b2 for repo https://github.com/pycqa/isort not allowed. ... so add gdb/contrib/pre-commit.py --autoupdate that can be used instead: ... $ ./gdb/contrib/pre-commit.py --autoupdate [https://github.com/psf/black-pre-commit-mirror] already up to date! [https://github.com/pycqa/flake8] already up to date! [https://github.com/pycqa/isort] updating 8.0.1 -> 9.0.0b2 Revision 9.0.0b2 for repo https://github.com/pycqa/isort not allowed. [https://github.com/codespell-project/codespell] already up to date! [https://github.com/nmoroze/tclint] already up to date! [https://github.com/adrienverge/yamllint.git] already up to date! ... The script could be extended to check that frozen revs stay frozen, but that's currently not needed. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34393 --- .pre-commit-config.yaml | 9 ++- gdb/contrib/pre-commit.py | 154 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 162 insertions(+), 1 deletion(-) create mode 100755 gdb/contrib/pre-commit.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3cccec45ef7..7b97b9a0ce8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -70,7 +70,7 @@ repos: files: *gdb_python_files args: [--config, gdb/setup.cfg] - repo: https://github.com/pycqa/isort - rev: 9.0.0b1 + rev: 8.0.1 hooks: - id: isort types_or: *gdb_python_types @@ -147,6 +147,13 @@ repos: language: unsupported_script entry: gdb/contrib/check-file-mode.sh files: *gdb_files + - id: &id5 pre-commit-config-check + name: *id5 + language: python + entry: gdb/contrib/pre-commit.py + args: [--config-check] + additional_dependencies: ["pyyaml"] + files: '^\.pre-commit-config.yaml$' # Local Variables: # indent-tabs-mode: nil diff --git a/gdb/contrib/pre-commit.py b/gdb/contrib/pre-commit.py new file mode 100755 index 00000000000..9ab746c7355 --- /dev/null +++ b/gdb/contrib/pre-commit.py @@ -0,0 +1,154 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2026 Free Software Foundation, Inc. +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import re +import subprocess +import sys + +import yaml + + +def get_repos(cfg): + with open(cfg, "r") as f: + data = yaml.safe_load(f) + repos = data.get("repos") + if not repos: + raise RuntimeError("repos missing") + return repos + + +def config_check_repo(repo): + name = repo.get("repo") + if not name: + raise RuntimeError("no repo") + if name == "local": + # Skip local repo, there's no revision to check. + return True + + # Get the revision. + rev = repo["rev"] + if not rev or rev == "": + raise RuntimeError("empty revision") + + # Normalize revision: skip 'v' prefix. + if rev[0].lower() == "v": + rev = rev[1:] + + # Check version number. Don't allow pre-releases like 9.0.0b1. + # We currently only need to support x.y.z, but that could change. + if not re.fullmatch(r"\d+[.]\d+[.]\d+", rev): + print("Revision %s for repo %s not allowed." % (rev, name)) + return False + + return True + + +def config_check(cfg): + for repo in get_repos(cfg): + if not config_check_repo(repo): + sys.exit(1) + + +def run_cmd(cmd, **kwargs): + res = subprocess.run(cmd, **kwargs) + if res.returncode != 0: + raise RuntimeError( + "command %s failed with exit status %s" % (cmd, res.returncode) + ) + return res + + +def autoupdate_repo(cfg, repo): + name = repo["repo"] + if name == "local": + # Skip local repo, there's no revision to update. + return + + cmd = ["pre-commit", "autoupdate", "--repo", name] + run_cmd(cmd) + + cmd = ["git", "status", "--porcelain", cfg] + res = run_cmd(cmd, capture_output=True, text=True) + if res.stdout == "": + # No autoupdate changes. + return + + rev = repo["rev"] + + # Config has changed, refresh repo. + found = False + for new_repo in get_repos(cfg): + if new_repo["repo"] == name: + found = True + break + if not found: + raise RuntimeError("Repo not found in updated %s" % cfg) + repo = new_repo + + new_rev = repo["rev"] + + if not config_check_repo(repo): + # Reject autoupdate for this repo. + cmd = ["git", "checkout", "-f", cfg] + # Capture and ignore output. + run_cmd(cmd, capture_output=True, text=True) + return + + # Commit autoupdate for this repo. + try: + name_for_msg = repo["hooks"][0]["id"] + except (KeyError, IndexError): + name_for_msg = name + msg = "Update %s: %s -> %s" % (name_for_msg, rev, new_rev) + cmd = ["git", "commit", "-m", msg, cfg] + run_cmd(cmd) + + +def autoupdate(cfg): + for repo in get_repos(cfg): + autoupdate_repo(cfg, repo) + + +def usage(): + print("Usage: pre-commit.py --config-check []") + print(" --autoupdate") + sys.exit(1) + + +def main(): + if len(sys.argv) < 2: + usage() + + cfg = ".pre-commit-config.yaml" + + if sys.argv[1] == "--config-check": + if len(sys.argv) not in [2, 3]: + usage() + if len(sys.argv) == 3: + cfg = sys.argv[2] + config_check(cfg) + return + + if sys.argv[1] == "--autoupdate": + if len(sys.argv) != 2: + usage() + autoupdate(cfg) + return + + usage() + + +main() base-commit: 1686e21559a7812ebbc05f57372cc30880768bf7 -- 2.51.0