mirror of
https://github.com/newren/git-filter-repo.git
synced 2024-09-16 00:02:00 +02:00
filter-repo: restructure RepoFilter callbacks to allow derived callbacks
I want to allow callbacks that could operate on similar pieces of commit or reset or tag objects (e.g. reference names, email addresses); restructure the current ones slightly to both allow more general ones to be added and to make the existing ones slightly clearer. Signed-off-by: Elijah Newren <newren@gmail.com>
This commit is contained in:
parent
623792ee31
commit
44b1f2b819
|
@ -2643,7 +2643,7 @@ class RepoFilter(object):
|
||||||
for regex, replacement in args.replace_text['regexes']:
|
for regex, replacement in args.replace_text['regexes']:
|
||||||
blob.data = regex.sub(replacement, blob.data)
|
blob.data = regex.sub(replacement, blob.data)
|
||||||
|
|
||||||
def tweak_commit(self, args, commit):
|
def tweak_commit(self, commit):
|
||||||
def filename_matches(path_expression, pathname):
|
def filename_matches(path_expression, pathname):
|
||||||
if path_expression == '':
|
if path_expression == '':
|
||||||
return True
|
return True
|
||||||
|
@ -2674,6 +2674,7 @@ class RepoFilter(object):
|
||||||
return pathname if (wanted == filtering_is_inclusive) else None
|
return pathname if (wanted == filtering_is_inclusive) else None
|
||||||
|
|
||||||
# Change the author & committer according to mailmap rules
|
# Change the author & committer according to mailmap rules
|
||||||
|
args = self._args
|
||||||
if args.mailmap:
|
if args.mailmap:
|
||||||
commit.author_name, commit.author_email = \
|
commit.author_name, commit.author_email = \
|
||||||
args.mailmap.translate(commit.author_name, commit.author_email)
|
args.mailmap.translate(commit.author_name, commit.author_email)
|
||||||
|
@ -2682,7 +2683,8 @@ class RepoFilter(object):
|
||||||
|
|
||||||
# Sometimes the 'branch' given is a tag; if so, rename it as requested so
|
# Sometimes the 'branch' given is a tag; if so, rename it as requested so
|
||||||
# we don't get any old tagnames
|
# we don't get any old tagnames
|
||||||
commit.branch = RepoFilter.new_tagname(args, commit.branch)
|
if self._args.tag_rename:
|
||||||
|
commit.branch = RepoFilter.do_tag_rename(args.tag_rename, commit.branch)
|
||||||
|
|
||||||
# Filter the list of file changes
|
# Filter the list of file changes
|
||||||
new_file_changes = {}
|
new_file_changes = {}
|
||||||
|
@ -2715,27 +2717,28 @@ class RepoFilter(object):
|
||||||
commit.file_changes = new_file_changes.values()
|
commit.file_changes = new_file_changes.values()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def new_tagname(args, tagname, shortname = False):
|
def do_tag_rename(rename_pair, tagname):
|
||||||
replace = args.tag_rename
|
old, new = rename_pair.split(':', 1)
|
||||||
if not replace:
|
|
||||||
return tagname
|
|
||||||
old, new = replace.split(':', 1)
|
|
||||||
if not shortname:
|
|
||||||
old, new = 'refs/tags/'+old, 'refs/tags/'+new
|
old, new = 'refs/tags/'+old, 'refs/tags/'+new
|
||||||
if tagname.startswith(old):
|
if tagname.startswith(old):
|
||||||
return tagname.replace(old, new, 1)
|
return tagname.replace(old, new, 1)
|
||||||
return tagname
|
return tagname
|
||||||
|
|
||||||
@staticmethod
|
def handle_tag(self, tag):
|
||||||
def handle_tag(args, tag, shortname = False):
|
# Tweak the tag name according to tag_rename rules
|
||||||
tag.ref = RepoFilter.new_tagname(args, tag.ref, shortname)
|
if self._args.tag_rename:
|
||||||
if args.mailmap:
|
fullref = 'refs/tags/'+tag.ref
|
||||||
tag.tagger_name, tag.tagger_email = \
|
fullref = RepoFilter.do_tag_rename(self._args.tag_rename, fullref)
|
||||||
args.mailmap.translate(tag.tagger_name, tag.tagger_email)
|
tag.ref = fullref[len('refs/tags/'):]
|
||||||
|
|
||||||
@staticmethod
|
# Tweak the tagger according to mailmap rules
|
||||||
def handle_reset(args, reset, shortname = False):
|
if self._args.mailmap:
|
||||||
reset.ref = RepoFilter.new_tagname(args, reset.ref, shortname)
|
tag.tagger_name, tag.tagger_email = \
|
||||||
|
self._args.mailmap.translate(tag.tagger_name, tag.tagger_email)
|
||||||
|
|
||||||
|
def handle_reset(self, reset):
|
||||||
|
if self._args.tag_rename:
|
||||||
|
reset.ref = RepoFilter.do_tag_rename(self._args.tag_rename, reset.ref)
|
||||||
|
|
||||||
def results_tmp_dir(self, create_if_missing=True):
|
def results_tmp_dir(self, create_if_missing=True):
|
||||||
working_dir = self._args.target or self._args.source or '.'
|
working_dir = self._args.target or self._args.source or '.'
|
||||||
|
@ -2868,13 +2871,13 @@ class RepoFilter(object):
|
||||||
RepoFilter.tweak_blob(self._args, b)
|
RepoFilter.tweak_blob(self._args, b)
|
||||||
self._blob_callback and self._blob_callback(b)
|
self._blob_callback and self._blob_callback(b)
|
||||||
def actual_commit_callback(c):
|
def actual_commit_callback(c):
|
||||||
self.tweak_commit(self._args, c)
|
self.tweak_commit(c)
|
||||||
self._commit_callback and self._commit_callback(c)
|
self._commit_callback and self._commit_callback(c)
|
||||||
def actual_tag_callback(t):
|
def actual_tag_callback(t):
|
||||||
RepoFilter.handle_tag(self._args, t, shortname = True)
|
self.handle_tag(t)
|
||||||
self._tag_callback and self._tag_callback(t)
|
self._tag_callback and self._tag_callback(t)
|
||||||
def actual_reset_callback(r):
|
def actual_reset_callback(r):
|
||||||
RepoFilter.handle_reset(self._args, r)
|
self.handle_reset(r)
|
||||||
self._reset_callback and self._reset_callback(r)
|
self._reset_callback and self._reset_callback(r)
|
||||||
actual_blob_callback = self._blob_callback
|
actual_blob_callback = self._blob_callback
|
||||||
if self._args.replace_text:
|
if self._args.replace_text:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user