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