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