diff options
Diffstat (limited to 'gdb/contrib')
| -rwxr-xr-x | gdb/contrib/check-whitespace-pre-commit.py | 52 | ||||
| -rwxr-xr-x | gdb/contrib/check-whitespace-pre-commit.sh | 19 |
2 files changed, 52 insertions, 19 deletions
diff --git a/gdb/contrib/check-whitespace-pre-commit.py b/gdb/contrib/check-whitespace-pre-commit.py new file mode 100755 index 0000000..9d82f77 --- /dev/null +++ b/gdb/contrib/check-whitespace-pre-commit.py @@ -0,0 +1,52 @@ +#! /usr/bin/env python3 + +# Copyright (C) 2025 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 <http://www.gnu.org/licenses/>. + +import re +import subprocess +import sys + +re_clean = re.compile( + "(^(gdb/testsuite/|gdbsupport/|gdbserver/)|[.](m4|ac|def|[chly])$|NEWS)" +) +re_clean_exclude = re.compile("^(gdb/symfile.c|gdb/cli/cli-cmds.c)$") + +clean = [] +other = [] +for f in sys.argv[1:]: + m = re_clean.search(f) + if m and re_clean_exclude.search(f): + m = None + if m: + clean.append(f) + else: + other.append(f) + +if other: + cmd = ["git", "--no-pager", "diff", "--staged", "--check"] + other + res = subprocess.run(cmd) + if res.returncode != 0: + sys.exit(res.returncode) + +if clean: + cmd = ["git", "hash-object", "-t", "tree", "/dev/null"] + res = subprocess.run(cmd, capture_output=True, text=True) + if res.returncode != 0: + sys.exit(res.returncode) + null_tree = res.stdout.rstrip("\n") + + cmd = ["git", "diff-index", "--cached", "--check", null_tree] + clean + res = subprocess.run(cmd) + sys.exit(res.returncode) diff --git a/gdb/contrib/check-whitespace-pre-commit.sh b/gdb/contrib/check-whitespace-pre-commit.sh deleted file mode 100755 index db45dc2..0000000 --- a/gdb/contrib/check-whitespace-pre-commit.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh - -# Copyright (C) 2025 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 <http://www.gnu.org/licenses/>. - -set -e - -git --no-pager diff --staged --check "$@" |
