changelog: add hint for a file mismatch
authorMartin Liska <mliska@suse.cz>
Mon, 30 Nov 2020 16:19:41 +0000 (17:19 +0100)
committerMartin Liska <mliska@suse.cz>
Mon, 30 Nov 2020 16:19:41 +0000 (17:19 +0100)
contrib/ChangeLog:

* gcc-changelog/git_commit.py: Suggest close file for
'unchanged file mentioned in a ChangeLog' error.
* gcc-changelog/test_email.py: Test it.

contrib/gcc-changelog/git_commit.py
contrib/gcc-changelog/test_email.py

index 57fba756d32ef67894d5c044942c0092e44b7fec..0c438165516f0271ecfce4945dda2a8c2234f2e3 100755 (executable)
@@ -16,6 +16,7 @@
 # along with GCC; see the file COPYING3.  If not see
 # <http://www.gnu.org/licenses/>.  */
 
+import difflib
 import os
 import re
 
@@ -576,6 +577,9 @@ class GitCommit:
         changed_files = set(cand)
         for file in sorted(mentioned_files - changed_files):
             msg = 'unchanged file mentioned in a ChangeLog'
+            candidates = difflib.get_close_matches(file, changed_files, 1)
+            if candidates:
+                msg += f' (did you mean "{candidates[0]}"?)'
             self.errors.append(Error(msg, file))
         for file in sorted(changed_files - mentioned_files):
             if not self.in_ignored_location(file):
index 48ecc1ee6a6e4d88e5f4a02b2d1335c75c50113e..8f5129edb123e82997aee5aa93c8ba2db7b4da3b 100755 (executable)
@@ -113,7 +113,9 @@ class TestGccChangelog(unittest.TestCase):
         email = self.from_patch_glob('0096')
         assert email.errors
         err = email.errors[0]
-        assert err.message == 'unchanged file mentioned in a ChangeLog'
+        assert err.message == 'unchanged file mentioned in a ChangeLog (did ' \
+            'you mean "gcc/testsuite/gcc.target/aarch64/' \
+            'advsimd-intrinsics/vdot-3-1.c"?)'
         assert err.line == 'gcc/testsuite/gcc.target/aarch64/' \
                            'advsimd-intrinsics/vdot-compile-3-1.c'