mirror of
https://github.com/newren/git-filter-repo.git
synced 2024-09-19 00:00:08 +02:00
0b70b72150
For other programs importing git-filter-repo as a library and passing a blob, commit, tag, or reset callback to RepoFilter, pass a second parameter to these functions with extra metadata they might find useful. For simplicity of implementation, this technically changes the calling signature of the --*-callback functions passed on the command line, but we hide that behind a _do_not_use_this_variable parameter for now, leave it undocumented, and encourage folks who want to use it to write an actual python program that imports git-filter-repo. In the future, we may modify the --*-callback functions to not pass this extra parameter, or if it is deemed sufficiently useful, then we'll rename the second parameter and document it. As already noted in our API compatibilty caveat near the top of git-filter-repo, I am not guaranteeing API backwards compatibility. That especially applies to this metadata argument, other than the fact that it'll be a dict mapping strings to some kind of value. I might add more keys, rename them, change the corresponding value, or even remove keys that used to be part of metadata. Signed-off-by: Elijah Newren <newren@gmail.com>
42 lines
1.1 KiB
Python
Executable File
42 lines
1.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
"""
|
|
Please see the
|
|
***** API BACKWARD COMPATIBILITY CAVEAT *****
|
|
near the top of git-filter-repo
|
|
"""
|
|
|
|
import sys
|
|
import git_filter_repo as fr
|
|
|
|
if len(sys.argv) != 3:
|
|
raise SystemExit("Syntax:\n %s SOURCE_REPO TARGET_REPO")
|
|
source_repo = sys.argv[1]
|
|
target_repo = sys.argv[2]
|
|
|
|
total_objects = fr.GitUtils.get_total_objects(source_repo) # blobs+trees
|
|
total_commits = fr.GitUtils.get_commit_count(source_repo)
|
|
object_count = 0
|
|
commit_count = 0
|
|
|
|
def print_progress():
|
|
global object_count, commit_count, total_objects, total_commits
|
|
print("\rRewriting commits... %d/%d (%d objects)"
|
|
% (commit_count, total_commits, object_count), end='')
|
|
|
|
def my_blob_callback(blob, metadata):
|
|
global object_count
|
|
object_count += 1
|
|
print_progress()
|
|
|
|
def my_commit_callback(commit, metadata):
|
|
global commit_count
|
|
commit_count += 1
|
|
print_progress()
|
|
|
|
args = fr.FilteringOptions.parse_args(['--force', '--quiet'])
|
|
filter = fr.RepoFilter(args,
|
|
blob_callback = my_blob_callback,
|
|
commit_callback = my_commit_callback)
|
|
filter.run()
|