Repository: python/cpython
Pull request: Update generated files list and add `diff=generated` attribute
As a side effect, the list of generated files is relocated after the language aware diff settings.

Closes python/core-workflow#425
<!--
Thanks for your contribution!
Please read this comment in its entirety. It's quite important.

# Pull Request title

It should be in the following format:

```
bpo-NNNN: Summary of the changes made
```

Where: bpo-NNNN refers to the issue number in the https://bugs.python.org.

Most PRs will require an issue number. Trivial changes, like fixing a typo, do not need an issue.

# Backport Pull Request title

If this is a backport PR (PR made against branches other than `main`),
please ensure that the PR title is in the following format:

```
[X.Y] <title from the original PR> (GH-NNNN)
```

Where: [X.Y] is the branch name, e.g. [3.6].

GH-NNNN refers to the PR number from `main`.

-->

Automerge-Triggered-By: GH:zware

Problem statement:
Mark generated files with custom `generated` git diff driver
In `.gitattributes`, add `diff=generated` to generated files so one conveniently can configure `git diff` to ignore them, for example by marking them as "binary files" (`git config diff.generated.binary true`). This should not impact how GitHub renders such diffs.

Suggestion stolen from @zware on Discord :sunglasses:

Hints from issue discussion:
See also:
- https://git-scm.com/docs/diff-config
- https://git-scm.com/docs/gitattributes
If someone takes over, here is a prepared list from a year back. Probably it got changed a lot, but might be useful base https://github.com/python/cpython/pull/20314
See also https://bugs.python.org/issue40729

Commit message: Add missing configure and aclocal.m4

Patch to review:
diff --git a/.gitattributes b/.gitattributes
index 05b0420714e1bf..ae7cd26dbe6958 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -40,24 +40,6 @@ Lib/test/test_importlib/namespacedata01/* -text
 PCbuild/readme.txt text eol=crlf
 PC/readme.txt text eol=crlf
 
-# Generated files
-# https://github.com/github/linguist/blob/master/docs/overrides.md
-**/clinic/*.h               linguist-generated=true
-Python/deepfreeze/*.c       linguist-generated=true
-Python/frozen_modules/*.h   linguist-generated=true
-Python/frozen_modules/MANIFEST  linguist-generated=true
-Include/internal/pycore_ast.h   linguist-generated=true
-Python/Python-ast.c         linguist-generated=true
-Include/opcode.h            linguist-generated=true
-Python/opcode_targets.h     linguist-generated=true
-Objects/typeslots.inc       linguist-generated=true
-*_db.h                      linguist-generated=true
-Doc/library/token-list.inc  linguist-generated=true
-Include/token.h             linguist-generated=true
-Lib/token.py                linguist-generated=true
-Parser/token.c              linguist-generated=true
-Programs/test_frozenmain.h  linguist-generated=true
-
 # Language aware diff headers
 # https://tekin.co.uk/2020/10/better-git-diff-output-for-ruby-python-elixir-and-more
 # https://gist.github.com/tekin/12500956bd56784728e490d8cef9cb81
@@ -67,3 +49,33 @@ Programs/test_frozenmain.h  linguist-generated=true
 *.html  diff=html
 *.py    diff=python
 *.md    diff=markdown
+
+# Generated files
+# https://github.com/github/linguist/blob/master/docs/overrides.md
+#
+# To always hide generated files in local diffs, mark them as binary:
+# $ git config diff.generated.binary true
+#
+**/clinic/*.h                       linguist-generated=true diff=generated
+*_db.h                              linguist-generated=true diff=generated
+Doc/library/token-list.inc          linguist-generated=true diff=generated
+Include/internal/pycore_ast.h       linguist-generated=true diff=generated
+Include/internal/pycore_ast_state.h linguist-generated=true diff=generated
+Include/opcode.h                    linguist-generated=true diff=generated
+Include/token.h                     linguist-generated=true diff=generated
+Lib/keyword.py                      linguist-generated=true diff=generated
+Lib/token.py                        linguist-generated=true diff=generated
+Modules/config.c                    linguist-generated=true diff=generated
+Objects/typeslots.inc               linguist-generated=true diff=generated
+Parser/parser.c                     linguist-generated=true diff=generated
+Parser/token.c                      linguist-generated=true diff=generated
+Programs/test_frozenmain.h          linguist-generated=true diff=generated
+Python/Python-ast.c                 linguist-generated=true diff=generated
+Python/deepfreeze/*.c               linguist-generated=true diff=generated
+Python/frozen_modules/*.h           linguist-generated=true diff=generated
+Python/frozen_modules/MANIFEST      linguist-generated=true diff=generated
+Python/opcode_targets.h             linguist-generated=true diff=generated
+Python/stdlib_module_names.h        linguist-generated=true diff=generated
+Tools/peg_generator/pegen/grammar_parser.py linguist-generated=true diff=generated
+aclocal.m4                          linguist-generated=true diff=generated
+configure                           linguist-generated=true diff=generated


Code review comments:
diff_hunk: @@ -67,3 +49,33 @@ Programs/test_frozenmain.h  linguist-generated=true
 *.html  diff=html
 *.py    diff=python
 *.md    diff=markdown
+
+# Generated files
+# https://github.com/github/linguist/blob/master/docs/overrides.md
+#
+# To always hide generated files in local diffs, mark them as binary:
+# $ git config diff.generated.binary true
+#
+**/clinic/*.h                       linguist-generated=true diff=generated
+*_db.h                              linguist-generated=true diff=generated
+Doc/library/token-list.inc          linguist-generated=true diff=generated
+Include/internal/pycore_ast.h       linguist-generated=true diff=generated
+Include/internal/pycore_ast_state.h linguist-generated=true diff=generated
+Include/opcode.h                    linguist-generated=true diff=generated
+Include/token.h                     linguist-generated=true diff=generated
+Lib/keyword.py                      linguist-generated=true diff=generated
+Lib/token.py                        linguist-generated=true diff=generated
+Modules/config.c                    linguist-generated=true diff=generated
+Objects/typeslots.inc               linguist-generated=true diff=generated
+Parser/parser.c                     linguist-generated=true diff=generated
+Parser/token.c                      linguist-generated=true diff=generated
+Programs/test_frozenmain.h          linguist-generated=true diff=generated
+Python/Python-ast.c                 linguist-generated=true diff=generated
+Python/deepfreeze/*.c               linguist-generated=true diff=generated
+Python/frozen_modules/*.h           linguist-generated=true diff=generated
+Python/frozen_modules/MANIFEST      linguist-generated=true diff=generated
+Python/opcode_targets.h             linguist-generated=true diff=generated
+Python/stdlib_module_names.h        linguist-generated=true diff=generated
+Tools/peg_generator/pegen/grammar_parser.py linguist-generated=true diff=generated
+aclocal.m4                          linguist-generated=true diff=generated
+configure                           linguist-generated=true diff=generated
path: .gitattributes
text: @user1:
Does `linguist` follow `[attr]` declarations in `.gitattributes`?  If so, it might be nicer to add `[attr]generated linguist-generated diff=generated`, and then we just need to tag the generated files with `generated` rather than the full `linguist-generated=true diff=generated`.  That also makes it just one place to change things if we later want to add another tag to generated files.

@author:
Oooooh, that's a nice thought. I'll check if that is possible.

@author:
Tested and verified on my fork. Thanks! 🍰 🥳 🎉 

@author:
(I'll update the no-EOL and CRLF sections with macros in a separate PR.)