git-filter-repo/t/t9391/commit_info.py
Elijah Newren 0b70b72150 filter-repo: provide extra metadata to some callbacks
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>
2019-05-30 22:07:48 -07:00

35 lines
996 B
Python
Executable File

#!/usr/bin/env python3
"""
Please see the
***** API BACKWARD COMPATIBILITY CAVEAT *****
near the top of git-filter-repo
"""
import re
import datetime
import git_filter_repo as fr
def change_up_them_commits(commit, metadata):
# Change the commit author
if commit.author_name == b"Copy N. Paste":
commit.author_name = b"Ima L. Oser"
commit.author_email = b"aloser@my.corp"
# Fix the author email
commit.author_email = re.sub(b"@my.crp", b"@my.corp", commit.author_email)
# Fix the committer date (bad timezone conversion in initial import)
oldtime = fr.string_to_date(commit.committer_date)
newtime = oldtime + datetime.timedelta(hours=-5)
commit.committer_date = fr.date_to_string(newtime)
# Fix the commit message
commit.message = re.sub(b"Marketing is staffed with pansies", b"",
commit.message)
args = fr.FilteringOptions.parse_args(['--force'])
filter = fr.RepoFilter(args, commit_callback = change_up_them_commits)
filter.run()