The desire to format or lint code throughout history has arisen several
times. It's more natural to do this in filter-branch since it somewhat
forces people to run external commands, but we have an example contrib
demo that shows how to run an external command on each file in history
that I created even before any of these requests came in and yet I still
periodically get requests about it.
Make lint-history ever-so-slightly easier to apply to a subset of
filenames, and include its usage as an extra cheat sheet comparison for
filter-branch-vs-filter-repo commands.
Signed-off-by: Elijah Newren <newren@gmail.com>
Feel free to take a look and adopt some of their ideas.
Feel free to take a look and adopt some of their ideas. Most of these
modifications are probably strictly unnecessary since you could just make
a lint-script that takes the filename, checks that it matches what you
want, and then calls the real linter. But I guess folks don't like making
an intermediate script. So I eventually added the --relevant flag for
picking out certain files providing yet another way to handle it.
"""
"""
"""
"""
@ -22,7 +27,8 @@ Please see the
near the top of git-filter-repo.
near the top of git-filter-repo.
"""
"""
# Technically, this program could be replaced by a "one-liner"; e.g.
# Technically, if you are only running on all non-binary files and don't care
# about filenames, then this program could be replaced by a "one-liner"; e.g.
# git filter-repo --force --blob-callback '
# git filter-repo --force --blob-callback '
# if not any(x == b"0" for x in blob.data[0:8192]):
# if not any(x == b"0" for x in blob.data[0:8192]):
# filename = '.git/info/tmpfile'
# filename = '.git/info/tmpfile'
@ -34,7 +40,7 @@ near the top of git-filter-repo.
# os.remove(filename)
# os.remove(filename)
# '
# '
# but let's do it as a full-fledged program that imports git_filter_repo
# but let's do it as a full-fledged program that imports git_filter_repo
# anyway...
# and show how to also do it with filename handling...
import argparse
import argparse
import os
import os
@ -45,8 +51,34 @@ try:
except ImportError:
except ImportError:
raise SystemExit("Error: Couldn't find git_filter_repo.py. Did you forget to make a symlink to git-filter-repo named git_filter_repo.py or did you forget to put the latter in your PYTHONPATH?")
raise SystemExit("Error: Couldn't find git_filter_repo.py. Did you forget to make a symlink to git-filter-repo named git_filter_repo.py or did you forget to put the latter in your PYTHONPATH?")
parser = argparse.ArgumentParser(
example_text = '''CALLBACK
description='Lint all files in history')
When you pass --relevant 'BODY', the following style of function
will be compiled and called:
def is_relevant(filename):
BODY
Thus, to only run on files with a ".txt" extension you would run