filter-repo: simplify import in lib-usage examples
Python wants filenames with underscores instead of hyphens and with a .py extension. We really want the main file named git-filter-repo, but we can add a git_filter_repo.py symlink. Doing so dramatically simplifies the steps needed to import it as a library in external python scripts. Signed-off-by: Elijah Newren <newren@gmail.com>pull/13/head
parent
6dba1f200c
commit
cbacb6cd82
@ -0,0 +1 @@
|
|||||||
|
git-filter-repo
|
@ -1,22 +1,12 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
# python makes importing files with dashes hard, sorry. Renaming would
|
import git_filter_repo as fr
|
||||||
# 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
|
|
||||||
|
|
||||||
def my_commit_callback(commit):
|
def my_commit_callback(commit):
|
||||||
if commit.branch == "refs/heads/master":
|
if commit.branch == "refs/heads/master":
|
||||||
commit.branch = "refs/heads/develop"
|
commit.branch = "refs/heads/develop"
|
||||||
|
|
||||||
args = repo_filter.FilteringOptions.default_options()
|
args = fr.FilteringOptions.default_options()
|
||||||
args.force = True
|
args.force = True
|
||||||
filter = repo_filter.RepoFilter(args, commit_callback = my_commit_callback)
|
filter = fr.RepoFilter(args, commit_callback = my_commit_callback)
|
||||||
filter.run()
|
filter.run()
|
||||||
|
Loading…
Reference in New Issue