Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update generated files list and add diff=generated attribute #30745

Merged
merged 10 commits into from Jan 21, 2022
@@ -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,31 @@ 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
#
This conversation was marked as resolved by erlend-aasland

This comment has been minimized.

@vstinner

vstinner Jan 21, 2022
Member

Would you mind to add a quick documentation how to ignore generated files locally in git diff commands?

This comment has been minimized.

@zware

zware Jan 21, 2022
Member

That's the next two lines ;)

This comment has been minimized.

@vstinner

vstinner Jan 21, 2022
Member

On Discord, @erlend-aasland showed something like ``git diff :exclude:generated`, but I don't recall the command.

I understand that git config diff.generated.binary true does the same thing, but without having to specify it on the command line each time.

This comment has been minimized.

@erlend-aasland

erlend-aasland Jan 21, 2022
Author Contributor

The command I showed used a glob pattern instead of querying attributes:

$ git diff main -- . ":(exclude)*clinic*"  # Explicitly exclude files that matches the pattern "*clinic*"
$ git config diff.generated.binary true    # Configure git diff to treat files with the 'generated' attribute as binary files
$ git diff main                            # With the git config from above, git diff will treat all generated files as binary files

This comment has been minimized.

@zware

zware Jan 21, 2022
Member

With this change, there is now also the option to do something like git diff -- ":(attr:!generated)" to completely elide generated files from diff output. I'm not sure if it's worth it to document those options here, though.

This comment has been minimized.

@erlend-aasland

erlend-aasland Jan 21, 2022
Author Contributor

Is there a git cheat sheet in the devguide? We could add some tips and tricks there.

This comment has been minimized.

# To always hide generated files in local diffs, mark them as binary:
# $ git config diff.generated.binary true
#
[attr]generated linguist-generated=true diff=generated

**/clinic/*.c.h generated
*_db.h generated
Doc/library/token-list.inc generated
Include/internal/pycore_ast.h generated
Include/internal/pycore_ast_state.h generated
Include/opcode.h generated
Include/token.h generated
Lib/keyword.py generated
Lib/token.py generated
Objects/typeslots.inc generated
Parser/parser.c generated
Parser/token.c generated
Programs/test_frozenmain.h generated
Python/Python-ast.c generated
Python/opcode_targets.h generated
Python/stdlib_module_names.h generated
Tools/peg_generator/pegen/grammar_parser.py generated
aclocal.m4 generated
configure generated