[PATCH RFC] mklog: add subject line skeleton

Jason Merrill jason@redhat.com
Thu Jun 17 03:42:26 GMT 2021


In the recent gcc-commit-mklog thread on gcc@ it occurred to me that the
command could also fill in part of the commit subject line.  If the first PR is
foo/1234, and the commit does not yet have a subject line, this will add

foo: [PR1234]

Does this seem like an improvement?

contrib/ChangeLog:

	* mklog.py: Add an initial component: [PRnnnnn] line when
	we have a PR.
---
 contrib/mklog.py | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/contrib/mklog.py b/contrib/mklog.py
index 5c93c707128..6113ae30a8e 100755
--- a/contrib/mklog.py
+++ b/contrib/mklog.py
@@ -39,6 +39,7 @@ import requests
 from unidiff import PatchSet
 
 pr_regex = re.compile(r'(\/(\/|\*)|[Cc*!])\s+(?P<pr>PR [a-z+-]+\/[0-9]+)')
+prnum_regex = re.compile(r'PR (?P<comp>[a-z+-]+)/(?P<num>[0-9]+)')
 dr_regex = re.compile(r'(\/(\/|\*)|[Cc*!])\s+(?P<dr>DR [0-9]+)')
 dg_regex = re.compile(r'{\s+dg-(error|warning)')
 identifier_regex = re.compile(r'^([a-zA-Z0-9_#].*)')
@@ -67,6 +68,7 @@ PATCH must be generated using diff(1)'s -up or -cp options
 script_folder = os.path.realpath(__file__)
 root = os.path.dirname(os.path.dirname(script_folder))
 
+firstpr = ''
 
 def find_changelog(path):
     folder = os.path.split(path)[0]
@@ -134,6 +136,7 @@ def generate_changelog(data, no_functions=False, fill_pr_titles=False):
     prs = []
     out = ''
     diff = PatchSet(data)
+    global firstpr;
 
     for file in diff:
         # skip files that can't be parsed
@@ -166,6 +169,9 @@ def generate_changelog(data, no_functions=False, fill_pr_titles=False):
                         # Found dg-warning/dg-error line
                         break
 
+    if prs:
+        firstpr = prs[0]
+
     if fill_pr_titles:
         out += get_pr_titles(prs)
 
@@ -308,8 +314,14 @@ if __name__ == '__main__':
             start = list(takewhile(lambda l: not l.startswith('#'), lines))
             end = lines[len(start):]
             with open(args.changelog, 'w') as f:
+                if (not start) or (start[0] == ''):
+                    # initial commit subject line 'component: [PRnnnnn]'
+                    m = prnum_regex.match(firstpr)
+                    if m:
+                        start.insert (0, m.group('comp') + ': [PR'
+                                      + m.group('num') + ']')
                 if start:
-                    # appent empty line
+                    # append empty line
                     if start[-1] != '':
                         start.append('')
                 else:

base-commit: ff4deb4b1d0c5947669ddc76fde4db83e28009d8
-- 
2.27.0



More information about the Gcc-patches mailing list