summaryrefslogtreecommitdiff
path: root/contrib/mklog.py
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2020-05-22 18:40:35 -0400
committerMartin Liska <mliska@suse.cz>2020-05-26 08:38:24 +0200
commit757dbb59c1f2cd88c84a6dc7dc038e4da750b035 (patch)
treeb23b29e0cb81510b99e04b750ae88adb70a0a4e0 /contrib/mklog.py
parentb8e5f22671e900d9c7757f6289cc10d0c4fd0f03 (diff)
downloadgcc-757dbb59c1f2cd88c84a6dc7dc038e4da750b035.tar.gz
gcc-git: Add prepare-commit-msg hook.
This patch introduces a prepare-commit-msg hook that appends a ChangeLog skeleton to a commit message when the GCC_FORCE_MKLOG environment variable is set, and a 'git commit-mklog' command set that variable while running 'git commit'. contrib/ChangeLog: * prepare-commit-msg: New file. * gcc-git-customization.sh: Install it. Add commit-mklog alias. * mklog.py: Add new option -c which appends to a ChangeLog file.
Diffstat (limited to 'contrib/mklog.py')
-rwxr-xr-xcontrib/mklog.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/contrib/mklog.py b/contrib/mklog.py
index 7a19b5d0949..fb58661b5eb 100755
--- a/contrib/mklog.py
+++ b/contrib/mklog.py
@@ -30,6 +30,7 @@ import argparse
import os
import re
import sys
+from itertools import takewhile
import requests
@@ -221,6 +222,9 @@ if __name__ == '__main__':
help='Do not generate function names in ChangeLogs')
parser.add_argument('-p', '--fill-up-bug-titles', action='store_true',
help='Download title of mentioned PRs')
+ parser.add_argument('-c', '--changelog',
+ help='Append the ChangeLog to a git commit message '
+ 'file')
args = parser.parse_args()
if args.input == '-':
args.input = None
@@ -229,4 +233,21 @@ if __name__ == '__main__':
data = input.read()
output = generate_changelog(data, args.no_functions,
args.fill_up_bug_titles)
- print(output, end='')
+ if args.changelog:
+ lines = open(args.changelog).read().split('\n')
+ start = list(takewhile(lambda l: not l.startswith('#'), lines))
+ end = lines[len(start):]
+ with open(args.changelog, 'w') as f:
+ if start:
+ # appent empty line
+ if start[-1] != '':
+ start.append('')
+ else:
+ # append 2 empty lines
+ start = 2 * ['']
+ f.write('\n'.join(start))
+ f.write('\n')
+ f.write(output)
+ f.write('\n'.join(end))
+ else:
+ print(output, end='')