]> git.ipfire.org Git - thirdparty/gcc.git/blame - contrib/gcc-changelog/git_check_commit.py
Add cutoff information to profile_info and use it when forcing non-zero value
[thirdparty/gcc.git] / contrib / gcc-changelog / git_check_commit.py
CommitLineData
c10aa1f0 1#!/usr/bin/env python3
81f86cb9 2
6441eb6d 3# Copyright (C) 2020-2025 Free Software Foundation, Inc.
c10aa1f0
ML
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
29abd09a 19# <http://www.gnu.org/licenses/>.
c10aa1f0
ML
20
21import argparse
22
23from git_repository import parse_git_revisions
24
0e12aa6c
KM
25def 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
c10aa1f0
ML
31parser = argparse.ArgumentParser(description='Check git ChangeLog format '
32 'of a commit')
e4f0e06b 33parser.add_argument('revisions', default='HEAD', nargs='?',
8300c346
TB
34 help='Git revisions (e.g. hash~5..hash or just hash) - '
35 'if not specified: HEAD')
c10aa1f0
ML
36parser.add_argument('-g', '--git-path', default='.',
37 help='Path to git repository')
38parser.add_argument('-p', '--print-changelog', action='store_true',
39 help='Print final changelog entires')
af1bfcc0
ML
40parser.add_argument('-v', '--verbose', action='store_true',
41 help='Print verbose information')
0e12aa6c
KM
42parser.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)')
c10aa1f0
ML
45args = parser.parse_args()
46
0e12aa6c
KM
47if 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
c10aa1f0 53retval = 0
8f67bf25 54for git_commit in parse_git_revisions(args.git_path, args.revisions):
e4f0e06b 55 res = 'OK' if git_commit.success else 'FAILED'
b05c4c2c 56 print('Checking %s: %s' % (git_commit.original_info.hexsha, res))
c10aa1f0 57 if git_commit.success:
c10aa1f0
ML
58 if args.print_changelog:
59 git_commit.print_output()
2b2cec58
TB
60 if args.verbose and git_commit.warnings:
61 for warning in git_commit.warnings:
62 print('WARN: %s' % warning)
c10aa1f0 63 else:
2b2cec58
TB
64 if args.verbose and git_commit.warnings:
65 for warning in git_commit.warnings:
66 print('WARN: %s' % warning)
c10aa1f0
ML
67 for error in git_commit.errors:
68 print('ERR: %s' % error)
af1bfcc0
ML
69 if args.verbose and error.details:
70 print(error.details)
c10aa1f0
ML
71 retval = 1
72
73exit(retval)