xref: /netbsd-src/external/gpl3/gcc/dist/contrib/git-commit-mklog.py (revision a448f87c3717b704e85b1f0e5d631e4b5a0aae17)
1*a448f87cSmrg#!/usr/bin/env python3
2*a448f87cSmrg
3*a448f87cSmrg# Copyright (C) 2020 Free Software Foundation, Inc.
4*a448f87cSmrg#
5*a448f87cSmrg# This file is part of GCC.
6*a448f87cSmrg#
7*a448f87cSmrg# GCC is free software; you can redistribute it and/or modify
8*a448f87cSmrg# it under the terms of the GNU General Public License as published by
9*a448f87cSmrg# the Free Software Foundation; either version 3, or (at your option)
10*a448f87cSmrg# any later version.
11*a448f87cSmrg#
12*a448f87cSmrg# GCC is distributed in the hope that it will be useful,
13*a448f87cSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
14*a448f87cSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*a448f87cSmrg# GNU General Public License for more details.
16*a448f87cSmrg#
17*a448f87cSmrg# You should have received a copy of the GNU General Public License
18*a448f87cSmrg# along with GCC; see the file COPYING.  If not, write to
19*a448f87cSmrg# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20*a448f87cSmrg# Boston, MA 02110-1301, USA.
21*a448f87cSmrg#
22*a448f87cSmrg# The script is wrapper for git commit-mklog alias where it parses
23*a448f87cSmrg# -b/--pr-numbers argument and passes it via environment variable
24*a448f87cSmrg# to mklog.py script.
25*a448f87cSmrg
26*a448f87cSmrgimport argparse
27*a448f87cSmrgimport os
28*a448f87cSmrgimport subprocess
29*a448f87cSmrg
30*a448f87cSmrgif __name__ == '__main__':
31*a448f87cSmrg    children_args = []
32*a448f87cSmrg    myenv = os.environ.copy()
33*a448f87cSmrg
34*a448f87cSmrg    parser = argparse.ArgumentParser(description='git-commit-mklog wrapped')
35*a448f87cSmrg    parser.add_argument('-b', '--pr-numbers', action='store',
36*a448f87cSmrg                        type=lambda arg: arg.split(','), nargs='?',
37*a448f87cSmrg                        help='Add the specified PRs (comma separated)')
38*a448f87cSmrg    parser.add_argument('-p', '--fill-up-bug-titles', action='store_true',
39*a448f87cSmrg                        help='Download title of mentioned PRs')
40*a448f87cSmrg    parser.add_argument('--co',
41*a448f87cSmrg                        help='Add Co-Authored-By trailer (comma separated)')
42*a448f87cSmrg    args, unknown_args = parser.parse_known_args()
43*a448f87cSmrg
44*a448f87cSmrg    myenv['GCC_FORCE_MKLOG'] = '1'
45*a448f87cSmrg    mklog_args = []
46*a448f87cSmrg    if args.pr_numbers:
47*a448f87cSmrg        mklog_args.append(f'-b {",".join(args.pr_numbers)}')
48*a448f87cSmrg    if args.fill_up_bug_titles:
49*a448f87cSmrg        mklog_args.append('-p')
50*a448f87cSmrg
51*a448f87cSmrg    if mklog_args:
52*a448f87cSmrg        myenv['GCC_MKLOG_ARGS'] = ' '.join(mklog_args)
53*a448f87cSmrg
54*a448f87cSmrg    if args.co:
55*a448f87cSmrg        for author in args.co.split(','):
56*a448f87cSmrg            unknown_args.append(f'--trailer "Co-Authored-By: {author}"')
57*a448f87cSmrg
58*a448f87cSmrg    commit_args = ' '.join(unknown_args)
59*a448f87cSmrg    subprocess.run(f'git commit {commit_args}', shell=True, env=myenv)
60