aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLehua Ding <lehua.ding@rivai.ai>2023-07-12 11:36:40 +0800
committerLehua Ding <lehua.ding@rivai.ai>2023-07-13 11:28:31 +0800
commit7f0700a689db8828e81e5dcaf7f6d474f2c4ec27 (patch)
tree3bd5a6f56ecf97fb9f5365541f08f284fd34d959
parentf048af2aa3dccec4d28c32056a1d5972f4049806 (diff)
downloadgcc-7f0700a689db8828e81e5dcaf7f6d474f2c4ec27.zip
gcc-7f0700a689db8828e81e5dcaf7f6d474f2c4ec27.tar.gz
gcc-7f0700a689db8828e81e5dcaf7f6d474f2c4ec27.tar.bz2
mklog: Add --append option to auto add generate ChangeLog to patch file
This tiny patch add --append option to mklog.py that support add generated change-log to the corresponding patch file. With this option there is no need to manually copy the generated change-log to the patch file. e.g.: Run `mklog.py --append /path/to/this/patch` will add the generated change-log to the right place of the /path/to/this/patch file. contrib/ChangeLog: * mklog.py: Add --append option. Signed-off-by: Lehua Ding <lehua.ding@rivai.ai>
-rwxr-xr-xcontrib/mklog.py27
1 files changed, 26 insertions, 1 deletions
diff --git a/contrib/mklog.py b/contrib/mklog.py
index 777212c..26230b9 100755
--- a/contrib/mklog.py
+++ b/contrib/mklog.py
@@ -358,6 +358,8 @@ if __name__ == '__main__':
'file')
parser.add_argument('--update-copyright', action='store_true',
help='Update copyright in ChangeLog files')
+ parser.add_argument('-a', '--append', action='store_true',
+ help='Append the generate ChangeLog to the patch file')
args = parser.parse_args()
if args.input == '-':
args.input = None
@@ -370,7 +372,30 @@ if __name__ == '__main__':
else:
output = generate_changelog(data, args.no_functions,
args.fill_up_bug_titles, args.pr_numbers)
- if args.changelog:
+ if args.append:
+ if (not args.input):
+ raise Exception("`-a or --append` option not support standard input")
+ lines = []
+ with open(args.input, 'r', newline='\n') as f:
+ # 1 -> not find the possible start of diff log
+ # 2 -> find the possible start of diff log
+ # 3 -> finish add ChangeLog to the patch file
+ maybe_diff_log = 1
+ for line in f:
+ if maybe_diff_log == 1 and line == "---\n":
+ maybe_diff_log = 2
+ elif maybe_diff_log == 2 and \
+ re.match("\s[^\s]+\s+\|\s\d+\s[+\-]+\n", line):
+ lines += [output, "---\n", line]
+ maybe_diff_log = 3
+ else:
+ # the possible start is not the true start.
+ if maybe_diff_log == 2:
+ maybe_diff_log = 1
+ lines.append(line)
+ with open(args.input, "w") as f:
+ f.writelines(lines)
+ elif args.changelog:
lines = open(args.changelog).read().split('\n')
start = list(takewhile(skip_line_in_changelog, lines))
end = lines[len(start):]