]> git.ipfire.org Git - thirdparty/gcc.git/blob - contrib/gcc-changelog/git_check_commit.py
59405967e85b4fad270efb97c78b2e1952bc4550
[thirdparty/gcc.git] / contrib / gcc-changelog / git_check_commit.py
1 #!/usr/bin/env python3
2
3 # Copyright (C) 2020-2025 Free Software Foundation, Inc.
4 #
5 # This file is part of GCC.
6 #
7 # GCC is free software; you can redistribute it and/or modify it under
8 # the terms of the GNU General Public License as published by the Free
9 # Software Foundation; either version 3, or (at your option) any later
10 # version.
11 #
12 # GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 # for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with GCC; see the file COPYING3. If not see
19 # <http://www.gnu.org/licenses/>.
20
21 import argparse
22
23 from git_repository import parse_git_revisions
24
25 def nonzero_uint(value):
26 ivalue = int(value)
27 if ivalue <= 0:
28 raise argparse.ArgumentTypeError('%s is not a non-zero positive integer' % value)
29 return ivalue
30
31 parser = argparse.ArgumentParser(description='Check git ChangeLog format '
32 'of a commit')
33 parser.add_argument('revisions', default='HEAD', nargs='?',
34 help='Git revisions (e.g. hash~5..hash or just hash) - '
35 'if not specified: HEAD')
36 parser.add_argument('-g', '--git-path', default='.',
37 help='Path to git repository')
38 parser.add_argument('-p', '--print-changelog', action='store_true',
39 help='Print final changelog entires')
40 parser.add_argument('-v', '--verbose', action='store_true',
41 help='Print verbose information')
42 parser.add_argument('-n', '--num-commits', type=nonzero_uint, default=1,
43 help='Number of commits to check (i.e. shorthand for '
44 'hash~N..hash)')
45 args = parser.parse_args()
46
47 if args.num_commits > 1:
48 if '..' in args.revisions:
49 print('ERR: --num-commits and range of revisions are mutually exclusive')
50 exit(1)
51 args.revisions = '{0}~{1}..{0}'.format(args.revisions, args.num_commits)
52
53 retval = 0
54 for git_commit in parse_git_revisions(args.git_path, args.revisions):
55 res = 'OK' if git_commit.success else 'FAILED'
56 print('Checking %s: %s' % (git_commit.original_info.hexsha, res))
57 if git_commit.success:
58 if args.print_changelog:
59 git_commit.print_output()
60 if args.verbose and git_commit.warnings:
61 for warning in git_commit.warnings:
62 print('WARN: %s' % warning)
63 else:
64 if args.verbose and git_commit.warnings:
65 for warning in git_commit.warnings:
66 print('WARN: %s' % warning)
67 for error in git_commit.errors:
68 print('ERR: %s' % error)
69 if args.verbose and error.details:
70 print(error.details)
71 retval = 1
72
73 exit(retval)