aboutsummaryrefslogtreecommitdiff
path: root/contrib/gcc-changelog/git_commit.py
diff options
context:
space:
mode:
authorTobias Burnus <tobias@codesourcery.com>2022-12-19 12:12:16 +0100
committerTobias Burnus <tobias@codesourcery.com>2022-12-19 12:12:16 +0100
commit2b2cec58ff502966004f79d1c9a2862c756b8509 (patch)
treee3e8e5c423530a5fdafef77c587f0238dd90224c /contrib/gcc-changelog/git_commit.py
parent03fb35f8753d87148b29b3f34b6154abe7db4c41 (diff)
downloadgcc-2b2cec58ff502966004f79d1c9a2862c756b8509.zip
gcc-2b2cec58ff502966004f79d1c9a2862c756b8509.tar.gz
gcc-2b2cec58ff502966004f79d1c9a2862c756b8509.tar.bz2
gcc-changelog: Add warning for auto-added files
git_email.py prints now a warning for files added automatically. git_check_commit.py does likewise but only with --verbose. It prints one line per ChangeLog file, either stating the file or if more than one the number of files. contrib/ChangeLog: * gcc-changelog/git_check_commit.py (__main__): With -v print a warning for the auto-added files. * gcc-changelog/git_commit.py (GitCommit.__init__): Add self.warnings. (GitCommit.check_mentioned_files): Add warning for auto-added files. (GitCommit.print_warnings): New function. * gcc-changelog/git_email.py (__main__): Remove bogus argument to GitEmail constructor; print auto-added-files warning. * gcc-changelog/test_email.py (test_auto_add_file_1, test_auto_add_file_2): New tests. * gcc-changelog/test_patches.txt: Add two test cases.
Diffstat (limited to 'contrib/gcc-changelog/git_commit.py')
-rwxr-xr-xcontrib/gcc-changelog/git_commit.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/contrib/gcc-changelog/git_commit.py b/contrib/gcc-changelog/git_commit.py
index 66d68de..e82fbca 100755
--- a/contrib/gcc-changelog/git_commit.py
+++ b/contrib/gcc-changelog/git_commit.py
@@ -22,6 +22,7 @@ import difflib
import os
import re
import sys
+from collections import defaultdict
default_changelog_locations = {
'c++tools',
@@ -304,6 +305,7 @@ class GitCommit:
self.changes = None
self.changelog_entries = []
self.errors = []
+ self.warnings = []
self.top_level_authors = []
self.co_authors = []
self.top_level_prs = []
@@ -706,6 +708,7 @@ class GitCommit:
msg += f' (did you mean "{candidates[0]}"?)'
details = '\n'.join(difflib.Differ().compare([file], [candidates[0]])).rstrip()
self.errors.append(Error(msg, file, details))
+ auto_add_warnings = defaultdict(list)
for file in sorted(changed_files - mentioned_files):
if not self.in_ignored_location(file):
if file in self.new_files:
@@ -738,6 +741,7 @@ class GitCommit:
file = file[len(entry.folder):].lstrip('/')
entry.lines.append('\t* %s: New file.' % file)
entry.files.append(file)
+ auto_add_warnings[entry.folder].append(file)
else:
msg = 'new file in the top-level folder not mentioned in a ChangeLog'
self.errors.append(Error(msg, file))
@@ -755,6 +759,11 @@ class GitCommit:
if pattern not in used_patterns:
error = "pattern doesn't match any changed files"
self.errors.append(Error(error, pattern))
+ for entry, val in auto_add_warnings.items():
+ if len(val) == 1:
+ self.warnings.append(f"Auto-added new file '{entry}/{val[0]}'")
+ else:
+ self.warnings.append(f"Auto-added {len(val)} new files in '{entry}'")
def check_for_correct_changelog(self):
for entry in self.changelog_entries:
@@ -830,6 +839,12 @@ class GitCommit:
for error in self.errors:
print(error)
+ def print_warnings(self):
+ if self.warnings:
+ print('Warnings:')
+ for warning in self.warnings:
+ print(warning)
+
def check_commit_email(self):
# Parse 'Martin Liska <mliska@suse.cz>'
email = self.info.author.split(' ')[-1].strip('<>')