Re: [Patch] gcc-changelog: Add warning for auto-added files

2022-12-16 Thread Martin Liška
On 12/16/22 13:33, Tobias Burnus wrote:
> Thus, the auto-add feature does not seem to be an often used feature - 
> neither on
> purpose nor accidentally. And glancing at the results, I think it was as 
> often used
> on purpose as it was used accidentally.

Hello.

Understood, I do support the newly added warning with a small patch tweak.

> 
> I was wondering whether the commit hook should print this warning/note or not.

I would print it.

> It can be helpful in case something too much got committed, but for the usual
> case that the file was missed, it simply comes too late. (Frankly, I don't
> know whether the hook currently runs with '-v' or not.)

Cheers,
Martindiff --git a/contrib/gcc-changelog/git_commit.py b/contrib/gcc-changelog/git_commit.py
index b9a60312099..e82fbcacd3e 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',
@@ -707,7 +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 = {}
+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:
@@ -740,10 +741,7 @@ class GitCommit:
 file = file[len(entry.folder):].lstrip('/')
 entry.lines.append('\t* %s: New file.' % file)
 entry.files.append(file)
-if entry.folder not in auto_add_warnings:
-auto_add_warnings[entry.folder] = [file]
-else:
-auto_add_warnings[entry.folder].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))
@@ -763,11 +761,9 @@ class GitCommit:
 self.errors.append(Error(error, pattern))
 for entry, val in auto_add_warnings.items():
 if len(val) == 1:
-self.warnings.append('Auto-added new file \'%s/%s\''
- % (entry, val[0]))
+self.warnings.append(f"Auto-added new file '{entry}/{val[0]}'")
 else:
-self.warnings.append('Auto-added %d new files in \'%s\''
- % (len(val), entry))
+self.warnings.append(f"Auto-added {len(val)} new files in '{entry}'")
 
 def check_for_correct_changelog(self):
 for entry in self.changelog_entries:



[Patch] gcc-changelog: Add warning for auto-added files

2022-12-16 Thread Tobias Burnus

This patch adds a warning for automatically added files. For check_email,
it is always printed - for git_check_commit.py only in verbose mode.

The './check_email.py' variant that implicitly uses the 'patches' directory does
not seem to get used that often, given that I had to remove the ', False'.
The same change was already done for the usage './check_email.py '
in commit r12-868-g7b4bae0acb14a1076df3234e905442bbdf9503dd !

Regarding the patch: I keep wondering whether it should be WARN/warnings or
note/inform.

Disclaimer: I have an older flake8/python-flake8 - thus, my pytest might
have missed some test issues. I think it did test sufficiently many,
but I don't know.

OK for mainline?

 * * *

Running './contrib/gcc-changelog/git_check_commit.py -v HEAD~1..HEAD' and
ignoring those commits without WARN, I only see the following commits
(see attached file).

Namely, 30 commits with:
One commit with 3 ChangeLog directories (single file, 5, and 2 new files, 
respectively)
One commit with 2 ChangeLog directories (one file each)
28 commits with files only auto-added to a single ChangeLog file.

Over all ChangeLog files and commits, there were:
22 new single file additions
11 multi-file additions: 4 times two new files, and then: 5, 7, 11, 12, 13, 28, 
36.

Thus, all in all 0.33% of the commits have auto-added files. It looks as if 
several
had just missed that file - and adding a single file or two seems to be fine.

In cases of eccbd7fcee5bbfc47731e8de83c44eee2e3dcc4b it was moving testcases 
into a
new directory; the commit log stated only their original location (and in the 
description
the new directory).

In case of 5fee5ec362f7a243f459e6378fd49dfc89dc9fb5, the commit log was already
quite long and the 'd: Import' patch had "WARN: Auto-added 36 new files in 
'libphobos'".
This, seems to be one of the more useful cases.

While the modula import commit 1eee94d351774cdc2efc8ee508b82d065184c6ee 
seemingly
only missed to list the (1+5+2) files, given the long list of '(New file)', it
seems as if they were just missed.

* * *

Thus, the auto-add feature does not seem to be an often used feature - neither 
on
purpose nor accidentally. And glancing at the results, I think it was as often 
used
on purpose as it was used accidentally.

I was wondering whether the commit hook should print this warning/note or not.
It can be helpful in case something too much got committed, but for the usual
case that the file was missed, it simply comes too late. (Frankly, I don't
know whether the hook currently runs with '-v' or not.)

Tobias
-
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 
München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas 
Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht 
München, HRB 106955
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.

diff --git a/contrib/gcc-changelog/git_check_commit.py b/contrib/gcc-changelog/git_check_commit.py
index 2e3e8cbeb77..2b9f2381f20 100755
--- a/contrib/gcc-changelog/git_check_commit.py
+++ b/contrib/gcc-changelog/git_check_commit.py
@@ -42,7 +42,13 @@ for git_commit in parse_git_revisions(args.git_path, args.revisions):
 if git_commit.success:
 if args.print_changelog:
 git_commit.print_output()
+if args.verbose and git_commit.warnings:
+for warning in git_commit.warnings:
+print('WARN: %s' % warning)
 else:
+if args.verbose and git_commit.warnings:
+for warning in git_commit.warnings:
+print('WARN: %s' % warning)
 for error in git_commit.errors:
 print('ERR: %s' % error)
 if args.verbose and error.details:
diff --git a/contrib/gcc-changelog/git_commit.py b/contrib/gcc-changelog/git_commit.py
index 66d68de03a5..b9a60312099 100755
--- a/contrib/gcc-changelog/git_commit.py
+++ b/contrib/gcc-changelog/git_commit.py
@@ -304,6 +304,7 @@ class GitCommit:
 self.changes = None
 self.changelog_entries = []
 self.errors = []
+self.warnings = []
 self.top_level_authors = []
 self.co_authors = []
 self.top_level_prs = []
@