From patchwork Thu Apr 10 13:45:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 110194 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D3F65386480D for ; Thu, 10 Apr 2025 13:46:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D3F65386480D 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=Fumwy0VR; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=oQwCOv5p; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=Fumwy0VR; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=oQwCOv5p X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org 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 718FB386480D for ; Thu, 10 Apr 2025 13:45:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 718FB386480D 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 718FB386480D Authentication-Results: server2.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=1744292719; cv=none; b=BLD6LssW0lhxq8nBF91zt6ME/bbBMeocLOlw9IX2Jg1WJje1v+9Yil6xpwT2bSYF1NTtB/93WGSLkalHQlyOc7e5FFdV9aZlRcf9HlFlEY/4HLzzo3Oh27jnQq0/Vo2Z5z4VZqmREKmLWoFngnpyScib+WtputNWUwQyXY6Zp0E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1744292719; c=relaxed/simple; bh=HWy7sc/rv9X72cjSqCgMw0H+39uomn9CaO4N107V25U=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=gl2CFMJfvwIgk6X8PhlCAutuua1Hj4k1bYM28clAmrOh7GHycyYgNfDblp75BMVAxhcoRn6JHvPD73KK+46wABhY8I1jAc+mKb9UvFdilvBS1XGzRb64zEPNXeht39I6BN7Ne+Si6SaR0IbK9uJ5wOf/20CIMILXWzCx2fuvVTM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 718FB386480D Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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 373FA2116B for ; Thu, 10 Apr 2025 13:45:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1744292718; 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=1BXyL2OwbhuFq+Gtq0T/fvO0w9ZKF0rIhLPsXfxzdzs=; b=Fumwy0VRACebYZkg/YBBsScW01i92AsD2VXsQ1x8BcHI7sydLxVj91FfURDov6CP3PN1SQ 9HmCN7I+nm5jto8FouKcxgAX2+cbT7OBiil0OU/oUSzHj4cRJv6wpyGcAfnDmnmd6ikxod qMSGo9nnemrZLYuRwJwDsSg0zCvGmMs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1744292718; 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=1BXyL2OwbhuFq+Gtq0T/fvO0w9ZKF0rIhLPsXfxzdzs=; b=oQwCOv5patZo5FZd4YAFSbGqhEulEeYBK2xPn1hZbjfWzpH4h3F6bCA4+FOZpxMHEDwax5 LPoauoRfm583eQBQ== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=Fumwy0VR; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=oQwCOv5p DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1744292718; 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=1BXyL2OwbhuFq+Gtq0T/fvO0w9ZKF0rIhLPsXfxzdzs=; b=Fumwy0VRACebYZkg/YBBsScW01i92AsD2VXsQ1x8BcHI7sydLxVj91FfURDov6CP3PN1SQ 9HmCN7I+nm5jto8FouKcxgAX2+cbT7OBiil0OU/oUSzHj4cRJv6wpyGcAfnDmnmd6ikxod qMSGo9nnemrZLYuRwJwDsSg0zCvGmMs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1744292718; 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=1BXyL2OwbhuFq+Gtq0T/fvO0w9ZKF0rIhLPsXfxzdzs=; b=oQwCOv5patZo5FZd4YAFSbGqhEulEeYBK2xPn1hZbjfWzpH4h3F6bCA4+FOZpxMHEDwax5 LPoauoRfm583eQBQ== 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 21CC3132D8 for ; Thu, 10 Apr 2025 13:45:18 +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 bAPoBm7L92fWbQAAD6G6ig (envelope-from ) for ; Thu, 10 Apr 2025 13:45:18 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [RFC] [pre-commit] Add codespell-log commit-msg hook Date: Thu, 10 Apr 2025 15:45:33 +0200 Message-ID: <20250410134533.12142-1-tdevries@suse.de> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Rspamd-Queue-Id: 373FA2116B X-Spam-Level: X-Spamd-Result: default: False [-3.01 / 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)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_ONE(0.00)[1]; TO_MATCH_ENVRCPT_ALL(0.00)[]; ARC_NA(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.de:+]; ASN(0.00)[asn:25478, ipnet:::/0, country:RU]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; DNSWL_BLOCKED(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCVD_VIA_SMTP_AUTH(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,suse.de:mid] X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spam-Score: -3.01 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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~patchwork=sourceware.org@sourceware.org Now that we're using codespell to check spelling in gdb files, can we use codespell to bring this spelling warning: ... $ echo usuable | codespell - 1: usuable usuable ==> usable ... to: ... $ git commit -a -m "Usuable stuff" ... ? First, let's look at a straightforward commit-msg hook implementation: ... - id: codespell name: codespell-commit-msg verbose: true always_run: true stages: [commit-msg] ... installed using: ... $ pre-commit install -t commit-msg ... When trying the commit, we get: ... $ echo "/* bla */" >> gdb/gdb.c $ git commit -a -m "Usuable stuff" black................................................(no files to check)Skipped flake8...............................................(no files to check)Skipped isort................................................(no files to check)Skipped codespell............................................(no files to check)Skipped check-include-guards.................................(no files to check)Skipped black................................................(no files to check)Skipped flake8...............................................(no files to check)Skipped codespell............................................(no files to check)Skipped codespell-commit-msg.....................................................Failed - hook id: codespell - duration: 0.06s - exit code: 65 .git/COMMIT_EDITMSG:1: Usuable ==> Usable check-include-guards.................................(no files to check)Skipped $ ... The commit was aborted, but the commit message is still there: ... $ cat .git/COMMIT_EDITMSG Usuable stuff ... We can retry and edit the commit message to clean up the typo: ... $ git commit -e -F .git/COMMIT_EDITMSG -a ... but it's a bit cumbersome. Furthermore, say we fix a typo and want to document this in the ChangeLog, and do: ... $ git commit -m "Fixed typo: useable -> usable" -a ... This commit cannot succeed, unless we add a codespell ignore tag, which feels like taking it too far. Both these problems can be addressed by setting things up in such a way that the commit always succeeds, and codespell output is shown as a hint. Ideally, we'd tell to pre-commit to implement this using some setting, but there doesn't seem to be one. So we use some indirection. Instead of using native codespell, use a local hook that calls a script gdb/contrib/codespell-log.sh, which calls pre-commit, which calls codespell. Using this approach, we get: ... $ echo "/* bla */" >> gdb/gdb.c $ git commit -a -m "Usuable stuff" black................................................(no files to check)Skipped flake8...............................................(no files to check)Skipped isort................................................(no files to check)Skipped codespell............................................(no files to check)Skipped check-include-guards.................................(no files to check)Skipped black................................................(no files to check)Skipped flake8...............................................(no files to check)Skipped codespell............................................(no files to check)Skipped check-include-guards.................................(no files to check)Skipped codespell-log............................................................Passed - hook id: codespell-log - duration: 0.18s codespell-log-internal...................................................Failed - hook id: codespell - exit code: 65 .git/COMMIT_EDITMSG:1: Usuable ==> Usable [codespell/codespell-log-2 d081bd25a40] Usuable stuff 1 file changed, 1 insertion(+) $ ... This is obviously convoluted, but it works. Perhaps we can propose a pre-commit improvement (always_pass) and simplify this eventually. --- .pre-commit-config.yaml | 8 ++++++++ gdb/contrib/codespell-log.sh | 29 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100755 gdb/contrib/codespell-log.sh base-commit: d1458933830456e54223d9fc61f0d9b3a19256f5 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 488e7812f94..ffa3fa55101 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -38,6 +38,7 @@ # See https://pre-commit.com/hooks.html for more hooks minimum_pre_commit_version: 3.2.0 +default_install_hook_types: [pre-commit, commit-msg] repos: - repo: https://github.com/psf/black-pre-commit-mirror rev: 25.1.0 @@ -80,3 +81,10 @@ repos: # All gdb header files, but not headers in the test suite. files: '^(gdb(support|server)?)/.*\.h$' exclude: '.*/testsuite/.*' + - id: codespell-log + name: codespell-log + language: script + entry: gdb/contrib/codespell-log.sh + verbose: true + always_run: true + stages: [commit-msg] diff --git a/gdb/contrib/codespell-log.sh b/gdb/contrib/codespell-log.sh new file mode 100755 index 00000000000..380d34025ef --- /dev/null +++ b/gdb/contrib/codespell-log.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +gen_cfg () +{ + cat > "$1" <