From patchwork Fri Nov 29 16:17:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 102136 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 4E9C33858C42 for ; Fri, 29 Nov 2024 16:21:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4E9C33858C42 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=KRQlXwq1; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=uQwE0eg5; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=KRQlXwq1; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=uQwE0eg5 X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by sourceware.org (Postfix) with ESMTPS id 453833858D26 for ; Fri, 29 Nov 2024 16:16:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 453833858D26 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 453833858D26 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:2 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732896963; cv=none; b=lQ2hioSzzSGvmMVFjQcz3+m8iaQImx9GQmQ3m9vc9QeOzN6cBQWZ3aSMsvWXDChxBKA6dbbu5DNAUrC5FOVqhi6UG+epixRdmwDRFk+bxxBszwmiOR8CuHK7vga8we74RQ7Hlb6qEK4D77xrgDvmVEXS6o5yBxMArEgmdboq1ck= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732896963; c=relaxed/simple; bh=gbqbSiJeJBAJ8576b4KVvSf9+ZdjvXoNp5oCd9T+Gck=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-Id:MIME-Version; b=LI5cyxqpp2VudHbeOv/axA1P30RQ7aeUJamH7HIRKwoCzl3FbV/yrM1eOay3DXb8voWGnVI5WDAnWSSU37i/Ob2xAvUsf0xvzFdqEC1s651pCK42h2OoIkQQXSeg/fepwiDBr50uKelsiPK+3YMr0mylzaaZ8b606D4hos1I0wI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 453833858D26 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-out2.suse.de (Postfix) with ESMTPS id 429A51F449 for ; Fri, 29 Nov 2024 16:16:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1732896962; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ptNrIhK8+LGCYtSgs1kVWGgSl24x5Y98PL+xZPchl4s=; b=KRQlXwq1SdbX8BZltIMVHKKNb37o+myJc/ltLcC7cOB4WI7Mz7iCrfn9gY261REqrhvWXb dQpsNCFyBx0Pt6yjxcLIgyLX4HhhIlaYwJf+OfQiz/tgszaZD6KptfSyge6ZQdIEvxbVlj XAdAspc+uT5+VA5hynBZYMJhBfeP+6U= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1732896962; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ptNrIhK8+LGCYtSgs1kVWGgSl24x5Y98PL+xZPchl4s=; b=uQwE0eg5bztuYNM3SutCP3ISr4Bhehzidr3AL57whnFjR2Br/E/YqP9oH6mntIJA9ZM1dc lPpE5UWfJfW2ZnAg== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1732896962; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ptNrIhK8+LGCYtSgs1kVWGgSl24x5Y98PL+xZPchl4s=; b=KRQlXwq1SdbX8BZltIMVHKKNb37o+myJc/ltLcC7cOB4WI7Mz7iCrfn9gY261REqrhvWXb dQpsNCFyBx0Pt6yjxcLIgyLX4HhhIlaYwJf+OfQiz/tgszaZD6KptfSyge6ZQdIEvxbVlj XAdAspc+uT5+VA5hynBZYMJhBfeP+6U= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1732896962; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ptNrIhK8+LGCYtSgs1kVWGgSl24x5Y98PL+xZPchl4s=; b=uQwE0eg5bztuYNM3SutCP3ISr4Bhehzidr3AL57whnFjR2Br/E/YqP9oH6mntIJA9ZM1dc lPpE5UWfJfW2ZnAg== 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 2B9A013A7D for ; Fri, 29 Nov 2024 16:16:02 +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 wBw9CcLoSWe9VgAAD6G6ig (envelope-from ) for ; Fri, 29 Nov 2024 16:16:02 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [RFC 1/2] [gdb/contrib] Add codespell.sh Date: Fri, 29 Nov 2024 17:17:06 +0100 Message-Id: <20241129161707.25292-2-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20241129161707.25292-1-tdevries@suse.de> References: <20241129161707.25292-1-tdevries@suse.de> MIME-Version: 1.0 X-Spam-Level: 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)[-1.000]; MIME_GOOD(-0.10)[text/plain]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid,imap1.dmz-prg2.suse.org:helo]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -2.80 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, KAM_SHORT, RCVD_IN_DNSWL_NONE, 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 Add a new script gdb/contrib/codespell.sh. It has two purposes: - it allows us to add a codespell hook to .pre-commit-config.yaml with more flexibility that just a plain codespell hook, and - it allows us easy access on the command line to a codespell version that matches the one used in the pre-commit hook. Usage is slightly different than regular codespell: ... $ ./gdb/contrib/codespell.sh Usage: codespell.sh codespell.sh -- codespell.sh -- -- where are: --always-pass: use exit status 0 if spell check fails --staged : Only check staged changes ... Simple usage is the same as codespell (though output is not colored): ... $ echo adres >> gdb/gdb.c $ codespell gdb/gdb.c gdb/gdb.c:40: adres ==> address $ ./gdb/contrib/codespell.sh gdb/gdb.c gdb/gdb.c:40: adres ==> address ... Using a codespell command line option requires a "--" separator: ... $ codespell -C0 gdb/gdb.c > adres gdb/gdb.c:40: adres ==> address $ ./gdb/contrib/codespell.sh -C0 -- gdb/gdb.c > adres gdb/gdb.c:40: adres ==> address ... And using a local option requires another "--" separator: ... $ codespell -C0 gdb/gdb.c; echo $? > adres gdb/gdb.c:40: adres ==> address 65 $ ./gdb/contrib/codespell.sh -C0 -- gdb/gdb.c; echo $? > adres gdb/gdb.c:40: adres ==> address 65 $ ./gdb/contrib/codespell.sh --always-pass -- -C0 -- gdb/gdb.c; echo $? > adres gdb/gdb.c:40: adres ==> address 0 ... Finally, the --staged functionality allows us to do a spell check on just the staged part rather than an entire file: ... $ git add gdb/gdb.c $ ./gdb/contrib/codespell.sh --staged -- -- gdb/gdb.c gdb/gdb.c: adres ==> address ... Note that the line number is missing in the output. Verified with shellcheck. --- gdb/contrib/codespell.sh | 249 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 249 insertions(+) create mode 100755 gdb/contrib/codespell.sh diff --git a/gdb/contrib/codespell.sh b/gdb/contrib/codespell.sh new file mode 100755 index 00000000000..a1ac62ad3f8 --- /dev/null +++ b/gdb/contrib/codespell.sh @@ -0,0 +1,249 @@ +#!/bin/bash + +# Script to call codespell using pre-commit. + +# Copyright (C) 2024 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 . + +usage () +{ + local prog + prog=$(basename "$0") + + echo "Usage: $prog " + echo " $prog -- " + echo " $prog -- -- " + echo "where are:" + echo " --always-pass: use exit status 0 if spell check fails" + echo " --staged : Only check staged changes" +} + +parse_local_args () +{ + while [ $# -gt 0 ]; do + case " $1 " in + " --always-pass ") + always_pass=true + ;; + " --staged ") + staged=true + ;; + *) + echo "Don't know how to handle local arg: $1" + exit 1 + ;; + esac + + shift + done +} + +parse_args () +{ + if [ $# -eq 0 ]; then + usage + exit 1 + fi + + local args1 + declare -a args1 + local args2 + declare -a args2 + local args3 + declare -a args3 + + args1=() + args2=() + args3=() + + dash_dash=0 + while [ $# -gt 0 ]; do + case " $1 " in + " -- ") + dash_dash=$((dash_dash + 1)) + if [ $dash_dash -eq 3 ]; then + usage + exit 1 + fi + ;; + *) + if [ $dash_dash -eq 0 ]; then + args1=("${args1[@]}" "$1") + elif [ $dash_dash -eq 1 ]; then + args2=("${args2[@]}" "$1") + else + args3=("${args3[@]}" "$1") + fi + ;; + esac + + shift + done + + if [ $dash_dash -eq 2 ]; then + parse_local_args "${args1[@]}" + args=("${args2[@]}") + files=("${args3[@]}") + elif [ $dash_dash -eq 1 ]; then + args=("${args1[@]}") + files=("${args2[@]}") + else + files=("${args1[@]}") + fi +} + +python_list () +{ + echo -n "[ " + + local first + first=true + for arg in "$@"; do + if $first; then + first=false + else + echo -n ", " + fi + echo -n "\"$arg\"" + done + + echo -n " ]" +} + +gen_cfg () +{ + cat > "$1" < "$1" < "$tmp" + done + files=("${staged_parts[@]}") + fi + + local status + if pre-commit \ + run \ + -c "$cfg" \ + codespell \ + --files "${files[@]}" \ + > "$output" \ + 2>&1; then + status=0 + else + status=$? + fi + + if [ $status -eq 0 ]; then + exit 0 + fi + + local exit_code + exit_code=$(grep "\- exit code: " "$output" | sed 's/.*: //') + + if [ "$exit_code" = "" ]; then + echo "error: Could not find exit code" + cat "$output" + exit 1 + fi + + if [ "$exit_code" -eq 65 ]; then + # Spell check failed. Filter out pre-commit output. + if $staged; then + # Map staged_parts files back to original files. + for f in "${files[@]}"; do + sed -i "s%^.*$f:[0-9][0-9]*: %${org_files[$f]}: %" "$output" + done + fi + awk -f "$awk_prog" "$output" + + if $always_pass; then + exit 0 + fi + else + # Something else went wrong, show full output. + cat "$output" + fi + + exit "$exit_code" +} + +main "$@" From patchwork Fri Nov 29 16:17:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 102134 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 7B58D3858CDB for ; Fri, 29 Nov 2024 16:18:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7B58D3858CDB 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=u1Jflj/2; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Rg6PaB9c; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=u1Jflj/2; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Rg6PaB9c 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 5F54D3858C60 for ; Fri, 29 Nov 2024 16:16:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5F54D3858C60 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 5F54D3858C60 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=1732896963; cv=none; b=hhm64nzV2rDa9muAcDbVsMCioj2TE6GA9KYeWo9rOq353zMXY9LaWfTvWAw/KaCP14pHrTU2NJpkwYIV7KNvqVTEbennGCmEvCnvNUqf75u3TANTGvUL2dluDCgvmtsZq9coptNjlOikFkQOEyArqDSBzO7x3R5znopOy9rzIo8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732896963; c=relaxed/simple; bh=5oO48pkP0u47seqddnkF/BPNweO9KnEsztQT7H4tx5s=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-Id:MIME-Version; b=S7k96jpG+JTKHkitJHStzp1SE9labvd7KJwikrrqz1TSETTVzgt6VgOrjNGAdKFSwfnrchvOxZkQlLRA1SnJpM3BqZ/AQBbcLdB14sgnbXgyY53jT3Sh7ppHSh/2omcPNNyGwPt0nSa5JWCPSPA2DNl5OU22sHnArw7KFrgRp2w= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5F54D3858C60 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 6151A21125 for ; Fri, 29 Nov 2024 16:16:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1732896962; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aSA9B8YFPjbZ1zpBz5RkUdtVHskAFbg5d+SyHmkZDhc=; b=u1Jflj/2Ab4mqR8InNj9u8PojAtYH/xhEmWUVTwhpvO+o2YynrfkRGwo6u+nQu83SgG7Pv k3JxkEdnQlTY2qD6AGPmCDgYaewv+1sb8+JH77K9cKtzQWwEXIUrrA/8f6BpX32ydKxlbU rcBUKjR+Wbgb4RkNdt46sE81WDtaiuU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1732896962; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aSA9B8YFPjbZ1zpBz5RkUdtVHskAFbg5d+SyHmkZDhc=; b=Rg6PaB9ckals5b7By0wBM2WM9I+ZfjcZbmzOUH0ManLc/07I/55Pu0WFtSwSi/dL7LMNtA yhrZY0h7nyN+XpBQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1732896962; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aSA9B8YFPjbZ1zpBz5RkUdtVHskAFbg5d+SyHmkZDhc=; b=u1Jflj/2Ab4mqR8InNj9u8PojAtYH/xhEmWUVTwhpvO+o2YynrfkRGwo6u+nQu83SgG7Pv k3JxkEdnQlTY2qD6AGPmCDgYaewv+1sb8+JH77K9cKtzQWwEXIUrrA/8f6BpX32ydKxlbU rcBUKjR+Wbgb4RkNdt46sE81WDtaiuU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1732896962; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aSA9B8YFPjbZ1zpBz5RkUdtVHskAFbg5d+SyHmkZDhc=; b=Rg6PaB9ckals5b7By0wBM2WM9I+ZfjcZbmzOUH0ManLc/07I/55Pu0WFtSwSi/dL7LMNtA yhrZY0h7nyN+XpBQ== 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 49A2F13AA5 for ; Fri, 29 Nov 2024 16:16:02 +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 AGudEMLoSWe9VgAAD6G6ig (envelope-from ) for ; Fri, 29 Nov 2024 16:16:02 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [RFC 2/2] [precommit] Add codespell Date: Fri, 29 Nov 2024 17:17:07 +0100 Message-Id: <20241129161707.25292-3-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20241129161707.25292-1-tdevries@suse.de> References: <20241129161707.25292-1-tdevries@suse.de> MIME-Version: 1.0 X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[99.99%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid,imap1.dmz-prg2.suse.org:helo]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; RCVD_TLS_ALL(0.00)[] X-Spam-Level: X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, 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 Add a pre-commit codespell hook. We use a custom one (gdb/contrib/codespell.sh) rather than the regular one because: - it allows us downgrade detected spelling mistakes from errors aborting a commit, to warnings that can be inspected after the commit has finished, and - it allows us to check only the staged part of a file rather than the entire file, greatly reducing noise. Both of these items are intended to avoid disrupting developer workflow as much as possible, while giving useful information. To demonstrate usage, consider gdb/ada-lang.c, which is not codespell clean: ... $ ./gdb/contrib/codespell.sh gdb/ada-lang.c gdb/ada-lang.c:847: Olt ==> Old gdb/ada-lang.c:858: Onot ==> Note, Not gdb/ada-lang.c:1533: alpha-numeric ==> alphanumeric gdb/ada-lang.c:3047: arithmetics ==> arithmetic gdb/ada-lang.c:5440: re-use ==> reuse gdb/ada-lang.c:9353: swith ==> switch gdb/ada-lang.c:9771: separatly ==> separately gdb/ada-lang.c:11749: suport ==> support gdb/ada-lang.c:11756: suport ==> support gdb/ada-lang.c:13655: statics ==> statistics ... Now let's introduce a typo: ... $ echo "This is the wrong adres" >> gdb/ada-lang.c ... and commit it: ... $ git commit -a -m typo black................................................(no files to check)Skipped flake8...............................................(no files to check)Skipped isort................................................(no files to check)Skipped gdb/scripts/codespell.sh --always-pass --staged..........................Passed - hook id: codespell - duration: 0.29s > This is the wrong adres gdb/ada-lang.c: adres ==> address [precommit/codespell-2 47baee9867b] typo 1 file changed, 1 insertion(+) ... As we can see: - the commit succeeded, - the introduced typo was noticed, and - only the introduced typo was noticed. The current implementation of gdb/contrib/codespell.sh --staged fails to print the line number, so I've added -C0 to make the context clear, which get us the first line here: ... > This is the wrong adres gdb/ada-lang.c: adres ==> address ... --- .pre-commit-config.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 070631c0f16..b1b4c2677b3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -59,3 +59,12 @@ repos: - id: isort types_or: [file] files: 'gdb/.*\.py(\.in)?$' + - repo: local + hooks: + - id: codespell + name: gdb/scripts/codespell.sh --always-pass --staged + language: script + entry: ./gdb/contrib/codespell.sh + args: [ "--always-pass", "--staged", "--", "-C0", "--" ] + files: '^(gdb|gdbsupport|gdbserver)/' + verbose: true