From a694a02125f181afe2ae461dd8f35c6f5f54ad22 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Mon, 12 Apr 2021 13:16:22 +0200 Subject: mklog: support long filenames contrib/ChangeLog: * gcc-changelog/git_commit.py: Support long filenames in entries. * gcc-changelog/test_email.py: Test it. * gcc-changelog/test_patches.txt: Likewise. --- contrib/gcc-changelog/git_commit.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'contrib/gcc-changelog/git_commit.py') diff --git a/contrib/gcc-changelog/git_commit.py b/contrib/gcc-changelog/git_commit.py index 43fa7f4..90e908e 100755 --- a/contrib/gcc-changelog/git_commit.py +++ b/contrib/gcc-changelog/git_commit.py @@ -415,8 +415,10 @@ class GitCommit: if line != line.rstrip(): self.errors.append(Error('trailing whitespace', line)) if len(line.replace('\t', ' ' * TAB_WIDTH)) > LINE_LIMIT: - self.errors.append(Error('line exceeds %d character limit' - % LINE_LIMIT, line)) + # support long filenames + if not line.startswith('\t* ') or not line.endswith(':'): + self.errors.append(Error('line exceeds %d character limit' + % LINE_LIMIT, line)) m = changelog_regex.match(line) if m: last_entry = ChangeLogEntry(m.group(1).rstrip('/'), -- cgit v1.1 From 1c35444b919683be23208479312a45e73d23ed35 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Mon, 12 Apr 2021 14:11:27 +0200 Subject: gcc-changelog: do not allow space in long line contrib/ChangeLog: * gcc-changelog/git_commit.py: Do not allow space in long lines. --- contrib/gcc-changelog/git_commit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'contrib/gcc-changelog/git_commit.py') diff --git a/contrib/gcc-changelog/git_commit.py b/contrib/gcc-changelog/git_commit.py index 90e908e..b28f7de 100755 --- a/contrib/gcc-changelog/git_commit.py +++ b/contrib/gcc-changelog/git_commit.py @@ -416,7 +416,7 @@ class GitCommit: self.errors.append(Error('trailing whitespace', line)) if len(line.replace('\t', ' ' * TAB_WIDTH)) > LINE_LIMIT: # support long filenames - if not line.startswith('\t* ') or not line.endswith(':'): + if not line.startswith('\t* ') or not line.endswith(':') or ' ' in line[3:-1]: self.errors.append(Error('line exceeds %d character limit' % LINE_LIMIT, line)) m = changelog_regex.match(line) -- cgit v1.1 From fea26bad2e5b9078d6a6b16d5e48653e31794273 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Fri, 12 Mar 2021 09:31:37 +0100 Subject: gcc-changelog: Remove components that will be removed. contrib/ChangeLog: * gcc-changelog/git_commit.py: Remove components that will be removed. --- contrib/gcc-changelog/git_commit.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'contrib/gcc-changelog/git_commit.py') diff --git a/contrib/gcc-changelog/git_commit.py b/contrib/gcc-changelog/git_commit.py index b28f7de..89461cc 100755 --- a/contrib/gcc-changelog/git_commit.py +++ b/contrib/gcc-changelog/git_commit.py @@ -30,7 +30,6 @@ changelog_locations = { 'fixincludes', 'gcc/ada', 'gcc/analyzer', - 'gcc/brig', 'gcc/c', 'gcc/c-family', 'gcc', @@ -62,7 +61,6 @@ changelog_locations = { 'libgcc/config/libbid', 'libgfortran', 'libgomp', - 'libhsail-rt', 'libiberty', 'libitm', 'libobjc', -- cgit v1.1 From 3e5605f0a961f9688f4c84b59d3e62ad23530fc4 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Mon, 10 May 2021 13:44:18 +0200 Subject: Revert "gcc-changelog: Remove components that will be removed." This reverts commit fea26bad2e5b9078d6a6b16d5e48653e31794273. --- contrib/gcc-changelog/git_commit.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'contrib/gcc-changelog/git_commit.py') diff --git a/contrib/gcc-changelog/git_commit.py b/contrib/gcc-changelog/git_commit.py index 89461cc..b28f7de 100755 --- a/contrib/gcc-changelog/git_commit.py +++ b/contrib/gcc-changelog/git_commit.py @@ -30,6 +30,7 @@ changelog_locations = { 'fixincludes', 'gcc/ada', 'gcc/analyzer', + 'gcc/brig', 'gcc/c', 'gcc/c-family', 'gcc', @@ -61,6 +62,7 @@ changelog_locations = { 'libgcc/config/libbid', 'libgfortran', 'libgomp', + 'libhsail-rt', 'libiberty', 'libitm', 'libobjc', -- cgit v1.1 From c1d381f0079a8594957be0513a00627caa219b73 Mon Sep 17 00:00:00 2001 From: Tobias Burnus Date: Mon, 10 May 2021 14:36:52 +0200 Subject: contrib/gcc-changelog: Detect if same file appears twice contrib/ChangeLog: * gcc-changelog/git_commit.py (Error.__repr__): Add space after the colon. (GitCommit.check_mentioned_files): Check whether the same file has been specified multiple times. * gcc-changelog/test_email.py (TestGccChangelog.test_multi_same_file): New. * gcc-changelog/test_patches.txt (0001-OpenMP-Fix-SIMT): New test. --- contrib/gcc-changelog/git_commit.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'contrib/gcc-changelog/git_commit.py') diff --git a/contrib/gcc-changelog/git_commit.py b/contrib/gcc-changelog/git_commit.py index b28f7de..d9332cb 100755 --- a/contrib/gcc-changelog/git_commit.py +++ b/contrib/gcc-changelog/git_commit.py @@ -200,7 +200,7 @@ class Error: def __repr__(self): s = self.message if self.line: - s += ':"%s"' % self.line + s += ': "%s"' % self.line return s @@ -629,7 +629,12 @@ class GitCommit: assert not entry.folder.endswith('/') for file in entry.files: if not self.is_changelog_filename(file): - mentioned_files.add(os.path.join(entry.folder, file)) + item = os.path.join(entry.folder, file) + if item in mentioned_files: + msg = 'same file specified multiple times' + self.errors.append(Error(msg, file)) + else: + mentioned_files.add(item) for pattern in entry.file_patterns: mentioned_patterns.append(os.path.join(entry.folder, pattern)) -- cgit v1.1 From 772e5e82e3114f6faccb549cfcc30c06b4678354 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Mon, 10 May 2021 13:51:22 +0200 Subject: gcc-changelog: Accept ref_name argument in GitCommit. contrib/ChangeLog: * gcc-changelog/git_commit.py: Remove ChangeLog locations based on ref_name. * gcc-changelog/git_repository.py: Likewise. --- contrib/gcc-changelog/git_commit.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'contrib/gcc-changelog/git_commit.py') diff --git a/contrib/gcc-changelog/git_commit.py b/contrib/gcc-changelog/git_commit.py index d9332cb..4a3f969 100755 --- a/contrib/gcc-changelog/git_commit.py +++ b/contrib/gcc-changelog/git_commit.py @@ -19,8 +19,9 @@ import difflib import os import re +import sys -changelog_locations = { +default_changelog_locations = { 'c++tools', 'config', 'contrib', @@ -287,7 +288,7 @@ class GitInfo: class GitCommit: - def __init__(self, info, strict=True, commit_to_info_hook=None): + def __init__(self, info, strict=True, commit_to_info_hook=None, ref_name=None): self.original_info = info self.info = info self.message = None @@ -300,6 +301,7 @@ class GitCommit: self.cherry_pick_commit = None self.revert_commit = None self.commit_to_info_hook = commit_to_info_hook + self.init_changelog_locations(ref_name) # Skip Update copyright years commits if self.info.lines and self.info.lines[0] == 'Update copyright years.': @@ -361,15 +363,14 @@ class GitCommit: else: return False - @classmethod - def find_changelog_location(cls, name): + def find_changelog_location(self, name): if name.startswith('\t'): name = name[1:] if name.endswith(':'): name = name[:-1] if name.endswith('/'): name = name[:-1] - return name if name in changelog_locations else None + return name if name in self.changelog_locations else None @classmethod def format_git_author(cls, author): @@ -389,6 +390,17 @@ class GitCommit: modified_files.append((parts[2], 'A')) return modified_files + def init_changelog_locations(self, ref_name): + self.changelog_locations = list(default_changelog_locations) + if ref_name: + version = sys.maxsize + if ref_name.startswith('refs/heads/releases/gcc-'): + version = int(ref_name.split('-')[-1]) + if version >= 12: + # HSA and BRIG were removed in GCC 12 + self.changelog_locations.remove('gcc/brig') + self.changelog_locations.remove('libhsail-rt') + def parse_lines(self, all_are_ignored): body = self.info.lines @@ -586,7 +598,7 @@ class GitCommit: for file in entry.files: location = self.get_file_changelog_location(file) if (location == '' - or (location and location in changelog_locations)): + or (location and location in self.changelog_locations)): if changelog and changelog != location: msg = 'could not deduce ChangeLog file, ' \ 'not unique location' @@ -606,11 +618,10 @@ class GitCommit: return True return False - @classmethod - def get_changelog_by_path(cls, path): + def get_changelog_by_path(self, path): components = path.split('/') while components: - if '/'.join(components) in changelog_locations: + if '/'.join(components) in self.changelog_locations: break components = components[:-1] return '/'.join(components) -- cgit v1.1 From 8f67bf25a48a6fd235bdba13c8708a686d942772 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Mon, 10 May 2021 14:13:53 +0200 Subject: gcc-changelog: Remove non-strict mode. contrib/ChangeLog: * gcc-changelog/git_check_commit.py: Remove --non-strict-mode. * gcc-changelog/git_commit.py: Remove strict mode. * gcc-changelog/git_email.py: Likewise. * gcc-changelog/git_repository.py: Likewise. * gcc-changelog/test_email.py: Likewise. * gcc-changelog/test_patches.txt: Update patches so that they don't contain a ChangeLog file changes. --- contrib/gcc-changelog/git_commit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'contrib/gcc-changelog/git_commit.py') diff --git a/contrib/gcc-changelog/git_commit.py b/contrib/gcc-changelog/git_commit.py index 4a3f969..c70279e 100755 --- a/contrib/gcc-changelog/git_commit.py +++ b/contrib/gcc-changelog/git_commit.py @@ -288,7 +288,7 @@ class GitInfo: class GitCommit: - def __init__(self, info, strict=True, commit_to_info_hook=None, ref_name=None): + def __init__(self, info, commit_to_info_hook=None, ref_name=None): self.original_info = info self.info = info self.message = None @@ -325,7 +325,7 @@ class GitCommit: if len(project_files) == len(self.info.modified_files): # All modified files are only MISC files return - elif project_files and strict: + elif project_files: self.errors.append(Error('ChangeLog, DATESTAMP, BASE-VER and ' 'DEV-PHASE updates should be done ' 'separately from normal commits')) -- cgit v1.1 From 5caadfbde2c0d4cb97db23bab74b52c56bb1be9e Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Wed, 12 May 2021 10:37:12 +0200 Subject: gcc-changelog: respect branch in git_update_version.py. contrib/ChangeLog: * gcc-changelog/git_commit.py: Simplify needle lookup. * gcc-changelog/git_update_version.py: Pass ref_name to parse_git_revisions. --- contrib/gcc-changelog/git_commit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'contrib/gcc-changelog/git_commit.py') diff --git a/contrib/gcc-changelog/git_commit.py b/contrib/gcc-changelog/git_commit.py index c70279e..8f9b266 100755 --- a/contrib/gcc-changelog/git_commit.py +++ b/contrib/gcc-changelog/git_commit.py @@ -394,7 +394,7 @@ class GitCommit: self.changelog_locations = list(default_changelog_locations) if ref_name: version = sys.maxsize - if ref_name.startswith('refs/heads/releases/gcc-'): + if 'releases/gcc-' in ref_name: version = int(ref_name.split('-')[-1]) if version >= 12: # HSA and BRIG were removed in GCC 12 -- cgit v1.1 From ae3e0b8bc204d1f6ce858c2637e1e72b636af3a2 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Fri, 14 May 2021 10:44:33 +0200 Subject: gcc-changelog: detect Co-Authored-By before ChangeLog entries contrib/ChangeLog: * gcc-changelog/git_commit.py: Support Co-Authored-By before a first ChangeLog entry. --- contrib/gcc-changelog/git_commit.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'contrib/gcc-changelog/git_commit.py') diff --git a/contrib/gcc-changelog/git_commit.py b/contrib/gcc-changelog/git_commit.py index 8f9b266..4958ab9 100755 --- a/contrib/gcc-changelog/git_commit.py +++ b/contrib/gcc-changelog/git_commit.py @@ -409,7 +409,8 @@ class GitCommit: continue if (changelog_regex.match(b) or self.find_changelog_location(b) or star_prefix_regex.match(b) or pr_regex.match(b) - or dr_regex.match(b) or author_line_regex.match(b)): + or dr_regex.match(b) or author_line_regex.match(b) + or b.lower().startswith(CO_AUTHORED_BY_PREFIX)): self.changes = body[i:] return if not all_are_ignored: -- cgit v1.1 From 9d38e096c5e3b1c2233b28d0e6ff8ee81517af56 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Mon, 24 May 2021 09:16:01 +0200 Subject: gcc-changelog: Add note about ChangeLog entries contrib/ChangeLog: * gcc-changelog/git_commit.py: Add note that ChangeLog entries are added automatically. * gcc-changelog/test_email.py: Update test. --- contrib/gcc-changelog/git_commit.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'contrib/gcc-changelog/git_commit.py') diff --git a/contrib/gcc-changelog/git_commit.py b/contrib/gcc-changelog/git_commit.py index 4958ab9..bd8c1ff 100755 --- a/contrib/gcc-changelog/git_commit.py +++ b/contrib/gcc-changelog/git_commit.py @@ -326,9 +326,11 @@ class GitCommit: # All modified files are only MISC files return elif project_files: - self.errors.append(Error('ChangeLog, DATESTAMP, BASE-VER and ' - 'DEV-PHASE updates should be done ' - 'separately from normal commits')) + err = 'ChangeLog, DATESTAMP, BASE-VER and DEV-PHASE updates ' \ + 'should be done separately from normal commits\n' \ + '(note: ChangeLog entries will be automatically ' \ + 'added by a cron job)' + self.errors.append(Error(err)) return all_are_ignored = (len(project_files) + len(ignored_files) -- cgit v1.1 From d554f43c98eb07f222afef5e90b5582d65519f7e Mon Sep 17 00:00:00 2001 From: Tobias Burnus Date: Sun, 13 Jun 2021 07:46:54 +0200 Subject: contrib/gcc-changelog: Check that PR in subject is in changelog This patch checks that a '[PRnnnn]' and '(PRnnnn)' also appears as PR in the changelog part of the commit message. And it does likewise for 'PR comp/nnnn' except that then also the component name is checked. (Note that the reverse is permitted, i.e. PR(s) only appearing in the changelog.) To avoid false positives, PR numbers in the subject line are ignored, if 'revert' appears. Additionally, reject commits with a nonempty second line. contrib/ChangeLog: * gcc-changelog/git_commit.py (pr_regex): Add ?P for group('pr'). (subject_pr_regex, subject_pr2_regex): New. (GitInfo.__init__, GitCommit.parse_changelog): Check subject PRs. * gcc-changelog/git_email.py (SUBJECT_PREFIX, subject_patch_regex): New. (GitEmail.__init__): Parse 'Subject:' and pass it to GitInfo. * gcc-changelog/test_email.py (test_pr_only_in_subject, test_wrong_pr_comp_in_subject, test_copyright_years): New. * gcc-changelog/test_patches.txt (0030-PR-c-92746, pr-check1.patch): Update to avoid triggering the new check. (0001-rs6000-Support-doubleword, pr-wrong-comp.patch, copyright-years.patch): New. --- contrib/gcc-changelog/git_commit.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'contrib/gcc-changelog/git_commit.py') diff --git a/contrib/gcc-changelog/git_commit.py b/contrib/gcc-changelog/git_commit.py index bd8c1ff..d1646bd 100755 --- a/contrib/gcc-changelog/git_commit.py +++ b/contrib/gcc-changelog/git_commit.py @@ -156,7 +156,9 @@ author_line_regex = \ re.compile(r'^(?P\d{4}-\d{2}-\d{2})\ {2}(?P.* <.*>)') additional_author_regex = re.compile(r'^\t(?P\ *)?(?P.* <.*>)') changelog_regex = re.compile(r'^(?:[fF]or +)?([a-z0-9+-/]*)ChangeLog:?') -pr_regex = re.compile(r'\tPR (?P[a-z+-]+\/)?([0-9]+)$') +subject_pr_regex = re.compile(r'(^|\W)PR\s+(?P[a-zA-Z+-]+)/(?P\d{4,7})') +subject_pr2_regex = re.compile(r'[(\[]PR\s*(?P\d{4,7})[)\]]') +pr_regex = re.compile(r'\tPR (?P[a-z+-]+\/)?(?P[0-9]+)$') dr_regex = re.compile(r'\tDR ([0-9]+)$') star_prefix_regex = re.compile(r'\t\*(?P\ *)(?P.*)') end_of_location_regex = re.compile(r'[\[<(:]') @@ -298,6 +300,7 @@ class GitCommit: self.top_level_authors = [] self.co_authors = [] self.top_level_prs = [] + self.subject_prs = set() self.cherry_pick_commit = None self.revert_commit = None self.commit_to_info_hook = commit_to_info_hook @@ -307,6 +310,9 @@ class GitCommit: if self.info.lines and self.info.lines[0] == 'Update copyright years.': return + if self.info.lines and len(self.info.lines) > 1 and self.info.lines[1]: + self.errors.append(Error('Expected empty second line in commit message', info.lines[0])) + # Identify first if the commit is a Revert commit for line in self.info.lines: m = revert_regex.match(line) @@ -316,6 +322,19 @@ class GitCommit: if self.revert_commit: self.info = self.commit_to_info_hook(self.revert_commit) + # The following happens for get_email.py: + if not self.info: + return + + # Extract PR numbers form the subject line + # Match either [PRnnnn] / (PRnnnn) or PR component/nnnn + if self.info.lines and not self.revert_commit: + self.subject_prs = {m.group('pr') for m in subject_pr2_regex.finditer(info.lines[0])} + for m in subject_pr_regex.finditer(info.lines[0]): + if not m.group('component') in bug_components: + self.errors.append(Error('invalid PR component in subject', info.lines[0])) + self.subject_prs.add(m.group('pr')) + # Allow complete deletion of ChangeLog files in a commit project_files = [f for f in self.info.modified_files if (self.is_changelog_filename(f[0], allow_suffix=True) and f[1] != 'D') @@ -346,6 +365,9 @@ class GitCommit: if not self.errors: self.check_mentioned_files() self.check_for_correct_changelog() + if self.subject_prs: + self.errors.append(Error('PR %s in subject but not in changelog' % + ', '.join(self.subject_prs), self.info.lines[0])) @property def success(self): @@ -460,7 +482,9 @@ class GitCommit: else: author_tuple = (m.group('name'), None) elif pr_regex.match(line): - component = pr_regex.match(line).group('component') + m = pr_regex.match(line) + component = m.group('component') + pr = m.group('pr') if not component: self.errors.append(Error('missing PR component', line)) continue @@ -469,6 +493,8 @@ class GitCommit: continue else: pr_line = line.lstrip() + if pr in self.subject_prs: + self.subject_prs.remove(pr) elif dr_regex.match(line): pr_line = line.lstrip() -- cgit v1.1