From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpbguseast1.qq.com (smtpbguseast1.qq.com [54.204.34.129]) by sourceware.org (Postfix) with ESMTPS id 7F87C3858C62 for ; Wed, 12 Jul 2023 04:01:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7F87C3858C62 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivai.ai Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivai.ai X-QQ-mid: bizesmtp74t1689134494tgvcqdac Received: from server1.localdomain ( [58.60.1.22]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 12 Jul 2023 12:01:33 +0800 (CST) X-QQ-SSF: 01400000000000B0F000000A0000000 X-QQ-FEAT: CRJwvrMA7Ii2GhQ2sHDdByJvUpOdZEE+Nk9YIr4UPwDQReGFtdnCQK+u+2aNc hyxIwyzJvM5vpYK4rFtXqd4Y0W+3vUJynRwWBMNzAe8MM4itBy033CIHncFGgx4mb4PID4x gXYmgH7RSZEMIbnipI9eu4aAuISsRYy0V+yQvStSkrVuHgfGCowUPt0LYb3bfLPyj+lCwld 1R0sK28V1vK8L/iv71LfgRI+l80RaCNeL0ivGIq9jqiYuxhitGvHu3La+DS6AF4zV/8mLnu Lito8AZqZh7i/9KrjthwDNCOGbHl5PDgPBprKjf7PSU8daA1xN1GkZYltWy44OEU8c8c2VM MzRyrdDrz/5+qT0AAEt0lDL0oCE+VKwmeJ38/3qPDsuvkW3ChgkAa4As2IqExMBcOmIktKA X-QQ-GoodBg: 2 X-BIZMAIL-ID: 11739323170074619884 From: Lehua Ding To: gcc-patches@gcc.gnu.org Cc: juzhe.zhong@rivai.ai, jeffreyalaw@gmail.com, mliska@suse.cz Subject: [PATCH] mklog: Add --append option to auto add generate ChangeLog to patch file Date: Wed, 12 Jul 2023 12:01:33 +0800 Message-Id: <20230712040133.88791-1-lehua.ding@rivai.ai> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:rivai.ai:qybglogicsvrgz:qybglogicsvrgz6a-0 X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_STATUS,RCVD_IN_BARRACUDACENTRAL,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi, This tiny patch add --append option to mklog.py that support add generated ChangeLog to the corresponding patch file. With this option there is no need to manually copy the generated ChangeLog to the patch file. e.g.: Run `mklog.py -a /path/to/this/patch` will add the generated ChangeLog ``` contrib/ChangeLog: * mklog.py: ``` to the right place of the /path/to/this/patch file. Best, Lehua contrib/ChangeLog: * mklog.py: Add --append option. --- contrib/mklog.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/contrib/mklog.py b/contrib/mklog.py index 777212c98d7..26230b9b4f2 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):] -- 2.36.1