gcc-changelog: Add warning for auto-added files

Message ID f5c3e7dc-2244-99ca-c584-f157eca131b4@codesourcery.com
State New
Headers
Series gcc-changelog: Add warning for auto-added files |

Commit Message

Tobias Burnus Dec. 16, 2022, 12:33 p.m. UTC
  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 <filename>'
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~10000..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
Checking e205ec03f0794aeac3e8a89e947c12624d5a274e: OK
WARN: Auto-added new file 'libgomp/testsuite/libgomp.fortran/allocate-4.f90'
--
Checking 1eee94d351774cdc2efc8ee508b82d065184c6ee: OK
WARN: Auto-added new file 'gcc/doc/gm2.texi'
WARN: Auto-added 5 new files in 'gcc/m2'
WARN: Auto-added 2 new files in 'libgm2'
--
Checking 97705b4459b645770ffb6c01ff6177de6774ef3c: OK
WARN: Auto-added new file 'gcc/testsuite/rust/compile/rawbytestring.rs'
--
Checking 4500baaccb6e4d696e223c338bbdf7705c3646dd: OK
WARN: Auto-added new file 'gcc/testsuite/gcc.c-torture/execute/pr107879.c'
--
Checking 566c5f1aaae120d2283103e68ecf1c1a83dd4459: OK
WARN: Auto-added 12 new files in 'gcc'
--
Checking 4c451631f722c9939260a5c2fc209802a47e525f: OK
WARN: Auto-added new file 'gcc/testsuite/gcc.dg/tree-ssa/pr107052.c'
--
Checking 11a113d501ff64fa4843e28d0a21b3f4e9d0d3de: OK
WARN: Auto-added new file 'gcc/config/aarch64/aarch64-feature-deps.h'
--
Checking 303976a6076f2839354702fd2caa049fa7cbbdc2: OK
WARN: Auto-added new file 'gcc/testsuite/g++.dg/cpp23/static-operator-call3.C'
--
Checking 61c4c989034548f481d1f10198447be27fb9a55f: OK
WARN: Auto-added new file 'gcc/testsuite/gcc.dg/vect/bb-slp-layout-12.c'
--
Checking 6602a2b2dee16af6e2d451c704789356042b5881: OK
WARN: Auto-added new file 'gcc/testsuite/g++.dg/cpp0x/Wpessimizing-move9.C'
--
Checking e7a7fed818d238d45b18dfd927cde93b4711052d: OK
WARN: Auto-added new file 'gcc/testsuite/gcc.dg/vect/pr106250.c'
--
Checking eccbd7fcee5bbfc47731e8de83c44eee2e3dcc4b: OK
WARN: Auto-added 13 new files in 'gcc/testsuite'
--
Checking eb3f2e9348e8057f4219859a96739ff1ba350611: OK
WARN: Auto-added 7 new files in 'gcc/testsuite'
--
Checking ec0f53a3a542e762f8fc8c22b9d345f922be5867: OK
WARN: Auto-added new file 'gcc/testsuite/g++.dg/cpp0x/constexpr-attribute4.C'
--
Checking 96ee5ce5f82f86ea78254a83037ac6f8cb9ad423: OK
WARN: Auto-added 28 new files in 'gcc/testsuite'
--
Checking 6384eff56dba1fac071c1b525f7e49cf03f2737f: OK
WARN: Auto-added new file 'gcc/testsuite/gdc.dg/special1.d'
--
Checking 958448a9441ee54e012c67cfc3cf88083f3d0e4a: OK
WARN: Auto-added 2 new files in 'gcc/testsuite'
--
Checking da2bf62d9e2a25f2d6a99176144c250b51fbdee7: OK
WARN: Auto-added new file 'gcc/testsuite/gcc.dg/vect/pr102832.c'
--
Checking c2b610e7c6c89fd422c5c31f01023bcddf3cf4a5: OK
WARN: Auto-added 2 new files in 'gcc/testsuite'
--
Checking cc3bf3404e4b1cdd1110e450bd5df45fdaaaae85: OK
WARN: Auto-added new file 'libstdc++-v3/testsuite/20_util/from_chars/7.cc'
--
Checking 86e3b476d5defaa79c94d40b76cbeec21cd02e5f: OK
WARN: Auto-added new file 'gcc/testsuite/gfortran.dg/ieee/signaling_3.f90'
WARN: Auto-added new file 'libgfortran/ieee/issignaling_fallback.h'
--
Checking 49ad4d2c30387ec916b16ddc1e235bcb5e53b3b2: FAILED
WARN: Auto-added new file 'libgfortran/m4/ifunc.m4'
--
Checking 6447f6f983ffeaecb8753ef685d702bf2594968b: OK
WARN: Auto-added new file 'gcc/testsuite/gfortran.dg/c-interop/pr103390-5.f90'
--
Checking 29df53fe349073a9210df70ae45662cb3f4a0556: OK
WARN: Auto-added 11 new files in 'gcc/testsuite'
--
Checking 5fee5ec362f7a243f459e6378fd49dfc89dc9fb5: OK
WARN: Auto-added 36 new files in 'libphobos'
--
Checking 407eaad25f45ccba6e45e6f07d6c69c51cc567f3: OK
WARN: Auto-added 2 new files in 'gcc/testsuite'
--
Checking f6d012338bf87f427b7420f2f309963c29fe33ba: OK
WARN: Auto-added new file 'gcc/testsuite/gcc.dg/tree-ssa/ssa-thread-backedge.c'
--
Checking 51d9ef7747b2dc439f7456303f0784faf5cdb1d3: OK
WARN: Auto-added new file 'gcc/testsuite/gfortran.dg/assumed_rank_23.f90'
--
Checking 5f9ccf17de7f7581412c6bffd4a37beca9a79836: OK
WARN: Auto-added new file 'gcc/testsuite/gcc.dg/tree-ssa/pr102546.c'
--
Checking 76b75018b3d053a890ebe155e47814de14b3c9fb: OK
WARN: Auto-added new file 'gcc/testsuite/g++.dg/warn/Winterference-2.C'
  

Comments

Martin Liška Dec. 16, 2022, 1:36 p.m. UTC | #1
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,
Martin
  

Patch

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 = []
@@ -706,6 +707,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 = {}
         for file in sorted(changed_files - mentioned_files):
             if not self.in_ignored_location(file):
                 if file in self.new_files:
@@ -738,6 +740,10 @@  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)
                     else:
                         msg = 'new file in the top-level folder not mentioned in a ChangeLog'
                         self.errors.append(Error(msg, file))
@@ -755,6 +761,13 @@  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('Auto-added new file \'%s/%s\''
+                                     % (entry, val[0]))
+            else:
+                self.warnings.append('Auto-added %d new files in \'%s\''
+                                     % (len(val), entry))
 
     def check_for_correct_changelog(self):
         for entry in self.changelog_entries:
@@ -830,6 +843,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('<>')
diff --git a/contrib/gcc-changelog/git_email.py b/contrib/gcc-changelog/git_email.py
index f3773f178ea..5468efcd0d5 100755
--- a/contrib/gcc-changelog/git_email.py
+++ b/contrib/gcc-changelog/git_email.py
@@ -119,11 +119,13 @@  if __name__ == '__main__':
 
         success = 0
         for full in sorted(allfiles):
-            email = GitEmail(full, False)
+            email = GitEmail(full)
             print(email.filename)
             if email.success:
                 success += 1
                 print('  OK')
+                for warning in email.warnings:
+                    print('  WARN: %s' % warning)
             else:
                 for error in email.errors:
                     print('  ERR: %s' % error)
@@ -135,6 +137,7 @@  if __name__ == '__main__':
         if email.success:
             print('OK')
             email.print_output()
+            email.print_warnings()
         else:
             if not email.info.lines:
                 print('Error: patch contains no parsed lines', file=sys.stderr)
diff --git a/contrib/gcc-changelog/test_email.py b/contrib/gcc-changelog/test_email.py
index 89960d307c9..79f8e0b8604 100755
--- a/contrib/gcc-changelog/test_email.py
+++ b/contrib/gcc-changelog/test_email.py
@@ -461,3 +461,17 @@  class TestGccChangelog(unittest.TestCase):
     def test_CR_in_patch(self):
         email = self.from_patch_glob('0001-Add-M-character.patch')
         assert (email.errors[0].message == 'cannot find a ChangeLog location in message')
+
+    def test_auto_add_file_1(self):
+        email = self.from_patch_glob('0001-Auto-Add-File.patch')
+        assert not email.errors
+        assert (len(email.warnings) == 1)
+        assert (email.warnings[0]
+                == "Auto-added new file 'libgomp/testsuite/libgomp.fortran/allocate-4.f90'")
+
+    def test_auto_add_file_2(self):
+        email = self.from_patch_glob('0002-Auto-Add-File.patch')
+        assert not email.errors
+        assert (len(email.warnings) == 2)
+        assert (email.warnings[0] == "Auto-added new file 'gcc/doc/gm2.texi'")
+        assert (email.warnings[1] == "Auto-added 2 new files in 'gcc/m2'")
diff --git a/contrib/gcc-changelog/test_patches.txt b/contrib/gcc-changelog/test_patches.txt
index c378c32423a..6004608a8f9 100644
--- a/contrib/gcc-changelog/test_patches.txt
+++ b/contrib/gcc-changelog/test_patches.txt
@@ -3636,3 +3636,99 @@  index 0000000..d75da75
 -- 
 2.38.1
 
+=== 0001-Auto-Add-File.patch ====
+From e205ec03f0794aeac3e8a89e947c12624d5a274e Mon Sep 17 00:00:00 2001
+From: Tobias Burnus <tobias@codesourcery.com>
+Date: Thu, 15 Dec 2022 12:25:07 +0100
+Subject: [PATCH] libgfortran's ISO_Fortran_binding.c: Use GCC11 version for
+ backward-only code [PR108056]
+
+libgfortran/ChangeLog:
+
+	PR libfortran/108056
+	* runtime/ISO_Fortran_binding.c (cfi_desc_to_gfc_desc,
+	gfc_desc_to_cfi_desc): Mostly revert to GCC 11 version for
+	those backward-compatiblity-only functions.
+---
+ libgfortran/runtime/ISO_Fortran_binding.c     | 151 +++---------------
+ .../testsuite/libgomp.fortran/allocate-4.f90  |  42 +++++
+ 2 files changed, 64 insertions(+), 129 deletions(-)
+ create mode 100644 libgomp/testsuite/libgomp.fortran/allocate-4.f90
+
+diff --git a/libgfortran/runtime/ISO_Fortran_binding.c b/libgfortran/runtime/ISO_Fortran_binding.c
+index 342df4275b9..e63a717a69b 100644
+--- a/libgfortran/runtime/ISO_Fortran_binding.c
++++ b/libgfortran/runtime/ISO_Fortran_binding.c
+@@ -41,1 +41,1 @@ export_proto(cfi_desc_to_gfc_desc);
+-  signed char type;
++  size_t type;
+diff --git a/libgomp/testsuite/libgomp.fortran/allocate-4.f90 b/libgomp/testsuite/libgomp.fortran/allocate-4.f90
+new file mode 100644
+index 00000000000..ddb507ba8e4
+--- /dev/null
++++ b/libgomp/testsuite/libgomp.fortran/allocate-4.f90
+@@ -0,0 +1,1 @@
++end
+-- 
+2.25.1
+
+=== 0002-Auto-Add-File.patch ====
+From 1eee94d351774cdc2efc8ee508b82d065184c6ee Mon Sep 17 00:00:00 2001
+From: Gaius Mulley <gaiusmod2@gmail.com>
+Date: Wed, 14 Dec 2022 17:43:08 +0000
+Subject: [PATCH 363/400] Merge modula-2 front end onto gcc.
+
+This commit merges the devel/modula2 into master.
+The libraries reside in libgm2, the compiler in gcc/m2
+and the testsuite in gcc/testsuite/gm2.
+
+gcc/ChangeLog:
+
+	* configure.ac (HAVE_PYTHON): Test for Python3 added.
+	* doc/install.texi: Add m2 as a language.  (--disable-libgm2)
+
+Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
+---
+ gcc/configure.ac                              |    15 +-
+ gcc/doc/gm2.texi                              |  2838 ++
+ gcc/doc/install.texi                          |    53 +-
+ gcc/m2/COPYING.FDL                            |   397 +
+ gcc/m2/COPYING.RUNTIME                        |    73 +
+diff --git a/gcc/configure.ac b/gcc/configure.ac
+index 7ca08726efa..5efbf11793c 100644
+--- a/gcc/configure.ac
++++ b/gcc/configure.ac
+@@ -7651,3 +7665,2 @@ done
+ [subdirs='$subdirs'])
+ AC_OUTPUT
+-
+diff --git a/gcc/doc/gm2.texi b/gcc/doc/gm2.texi
+new file mode 100644
+index 00000000000..513fdd3ec7f
+--- /dev/null
++++ b/gcc/doc/gm2.texi
+@@ -0,0 +1,1 @@
++\input texinfo
+diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
+index 89ff6a6734b..6884a74936b 100644
+--- a/gcc/doc/install.texi
++++ b/gcc/doc/install.texi
+@@ -308,1 +308,2 @@ On some targets, @samp{libphobos} isn't enabled by default, but compiles
+ 
++@item @anchor{GM2-prerequisite}GM2
+diff --git a/gcc/m2/COPYING.FDL b/gcc/m2/COPYING.FDL
+new file mode 100644
+index 00000000000..9854856fa81
+--- /dev/null
++++ b/gcc/m2/COPYING.FDL
+@@ -0,0 +1,1 @@
++		GNU Free Documentation License
+diff --git a/gcc/m2/COPYING.RUNTIME b/gcc/m2/COPYING.RUNTIME
+new file mode 100644
+index 00000000000..649af5e573a
+--- /dev/null
++++ b/gcc/m2/COPYING.RUNTIME
+@@ -0,0 +1,1 @@
++GCC RUNTIME LIBRARY EXCEPTION
+-- 
+2.25.1