mirror of
https://github.com/newren/git-filter-repo.git
synced 2024-09-18 00:00:19 +02:00
a5d4d70876
Signed-off-by: Elijah Newren <newren@gmail.com>
28 lines
1.1 KiB
Python
Executable File
28 lines
1.1 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
# python makes importing files with dashes hard, sorry. Renaming would
|
|
# allow us to simplify this to
|
|
# import git_repo_filter
|
|
# However, since git style commands are dashed and git-filter-repo is used more
|
|
# as a tool than a library, renaming is not an option, so import is 5 lines:
|
|
import imp
|
|
import sys
|
|
sys.dont_write_bytecode = True # .pyc generation -> ugly 'git-filter-repoc' files
|
|
with open("../../../git-filter-repo") as f:
|
|
repo_filter = imp.load_source('repo_filter', "git-filter-repo", f)
|
|
# End of convoluted import of git-filter-repo
|
|
|
|
import re
|
|
|
|
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 = repo_filter.FilteringOptions.parse_args(['--force'])
|
|
filter = repo_filter.RepoFilter(args, blob_callback = strip_cvs_keywords)
|
|
filter.run()
|