xref: /netbsd-src/external/gpl3/gcc/dist/contrib/gcc-changelog/git_check_commit.py (revision a448f87c3717b704e85b1f0e5d631e4b5a0aae17)
1fb8a8121Smrg#!/usr/bin/env python3
2fb8a8121Smrg#
3fb8a8121Smrg# This file is part of GCC.
4fb8a8121Smrg#
5fb8a8121Smrg# GCC is free software; you can redistribute it and/or modify it under
6fb8a8121Smrg# the terms of the GNU General Public License as published by the Free
7fb8a8121Smrg# Software Foundation; either version 3, or (at your option) any later
8fb8a8121Smrg# version.
9fb8a8121Smrg#
10fb8a8121Smrg# GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11fb8a8121Smrg# WARRANTY; without even the implied warranty of MERCHANTABILITY or
12fb8a8121Smrg# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13fb8a8121Smrg# for more details.
14fb8a8121Smrg#
15fb8a8121Smrg# You should have received a copy of the GNU General Public License
16fb8a8121Smrg# along with GCC; see the file COPYING3.  If not see
17fb8a8121Smrg# <http://www.gnu.org/licenses/>.  */
18fb8a8121Smrg
19fb8a8121Smrgimport argparse
20fb8a8121Smrg
21fb8a8121Smrgfrom git_repository import parse_git_revisions
22fb8a8121Smrg
23fb8a8121Smrgparser = argparse.ArgumentParser(description='Check git ChangeLog format '
24fb8a8121Smrg                                 'of a commit')
25fb8a8121Smrgparser.add_argument('revisions', default='HEAD', nargs='?',
26*a448f87cSmrg                    help='Git revisions (e.g. hash~5..hash or just hash) - '
27*a448f87cSmrg                    'if not specified: HEAD')
28fb8a8121Smrgparser.add_argument('-g', '--git-path', default='.',
29fb8a8121Smrg                    help='Path to git repository')
30fb8a8121Smrgparser.add_argument('-p', '--print-changelog', action='store_true',
31fb8a8121Smrg                    help='Print final changelog entires')
32*a448f87cSmrgparser.add_argument('-v', '--verbose', action='store_true',
33*a448f87cSmrg                    help='Print verbose information')
34fb8a8121Smrgargs = parser.parse_args()
35fb8a8121Smrg
36fb8a8121Smrgretval = 0
37*a448f87cSmrgfor git_commit in parse_git_revisions(args.git_path, args.revisions):
38fb8a8121Smrg    res = 'OK' if git_commit.success else 'FAILED'
39fb8a8121Smrg    print('Checking %s: %s' % (git_commit.original_info.hexsha, res))
40fb8a8121Smrg    if git_commit.success:
41fb8a8121Smrg        if args.print_changelog:
42fb8a8121Smrg            git_commit.print_output()
43fb8a8121Smrg    else:
44fb8a8121Smrg        for error in git_commit.errors:
45fb8a8121Smrg            print('ERR: %s' % error)
46*a448f87cSmrg            if args.verbose and error.details:
47*a448f87cSmrg                print(error.details)
48fb8a8121Smrg        retval = 1
49fb8a8121Smrg
50fb8a8121Smrgexit(retval)
51