git-filter-repo/t/t9391/strip-cvs-keywords.py
Elijah Newren e5955f397f filter-repo (python3): shebang and imports
Signed-off-by: Elijah Newren <newren@gmail.com>
2019-05-08 08:57:51 -07:00

28 lines
912 B
Python
Executable File

#!/usr/bin/env python3
"""
Please see the
***** API BACKWARD COMPATIBILITY CAVEAT *****
near the top of git-filter-repo.
Also, note that splicing repos may need some special care as fast-export
only shows the files that changed relative to the first parent, so there
may be gotchas if you are to splice near merge commits; this example does
not try to handle any such special cases.
"""
import re
import git_filter_repo as fr
def strip_cvs_keywords(blob):
# FIXME: Should first check if blob is a text file to avoid ruining
# binaries. Could use python.magic here, or just output blob.data to
# the unix 'file' command
pattern = r'\$(Id|Date|Source|Header|CVSHeader|Author|Revision):.*\$'
replacement = r'$\1$'
blob.data = re.sub(pattern, replacement, blob.data)
args = fr.FilteringOptions.parse_args(['--force'])
filter = fr.RepoFilter(args, blob_callback = strip_cvs_keywords)
filter.run()