Skip to content

Commit ad73b5e

Browse files
committed
filter-repo: minor cleanups of RepoFilter function names
Fix visibility of several functions, and make the callbacks have a more consistent naming. Signed-off-by: Elijah Newren <[email protected]>
1 parent 27f08be commit ad73b5e

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

git-filter-repo

+21-21
Original file line numberDiff line numberDiff line change
@@ -2639,7 +2639,7 @@ class RepoFilter(object):
26392639
assert new_hash is not None
26402640
return new_hash[0:orig_len]
26412641

2642-
def trim_extra_parents(self, orig_parents, parents):
2642+
def _trim_extra_parents(self, orig_parents, parents):
26432643
'''Due to pruning of empty commits, some parents could be non-existent
26442644
(None) or otherwise redundant. Remove the non-existent parents, and
26452645
remove redundant parents so long as that doesn't transform a merge
@@ -2722,7 +2722,7 @@ class RepoFilter(object):
27222722

27232723
return parents, None
27242724

2725-
def prunable(self, commit, new_1st_parent, had_file_changes, orig_parents):
2725+
def _prunable(self, commit, new_1st_parent, had_file_changes, orig_parents):
27262726
parents = commit.parents
27272727

27282728
if self._args.empty_pruning == 'never':
@@ -2810,7 +2810,7 @@ class RepoFilter(object):
28102810

28112811
return True
28122812

2813-
def record_remapping(self, commit, orig_parents):
2813+
def _record_remapping(self, commit, orig_parents):
28142814
new_id = None
28152815
# Record the mapping of old commit hash to new one
28162816
if commit.original_id and self._import_pipes:
@@ -2828,7 +2828,7 @@ class RepoFilter(object):
28282828
if len(orig_parents) >= 2 and len(commit.parents) < 2:
28292829
self._commits_no_longer_merges.append((commit.original_id, new_id))
28302830

2831-
def tweak_blob(self, blob):
2831+
def _tweak_blob(self, blob):
28322832
if self._args.replace_text:
28332833
for literal, replacement in self._args.replace_text['literals']:
28342834
blob.data = blob.data.replace(literal, replacement)
@@ -2838,7 +2838,7 @@ class RepoFilter(object):
28382838
if self._blob_callback:
28392839
self._blob_callback(blob)
28402840

2841-
def tweak_commit(self, commit, aux_info):
2841+
def _tweak_commit(self, commit, aux_info):
28422842
def filename_matches(path_expression, pathname):
28432843
''' Returns whether path_expression matches pathname or a leading
28442844
directory thereof, allowing path_expression to not have a trailing
@@ -2904,7 +2904,7 @@ class RepoFilter(object):
29042904
# Sometimes the 'branch' given is a tag; if so, rename it as requested so
29052905
# we don't get any old tagnames
29062906
if self._args.tag_rename:
2907-
commit.branch = RepoFilter.do_tag_rename(args.tag_rename, commit.branch)
2907+
commit.branch = RepoFilter._do_tag_rename(args.tag_rename, commit.branch)
29082908
if self._refname_callback:
29092909
commit.branch = self._refname_callback(commit.branch)
29102910

@@ -2977,7 +2977,7 @@ class RepoFilter(object):
29772977
self._orig_graph.add_commit_and_parents(commit.old_id, orig_parents)
29782978

29792979
# Prune parents (due to pruning of empty commits) if relevant
2980-
parents, new_1st_parent = self.trim_extra_parents(orig_parents, parents)
2980+
parents, new_1st_parent = self._trim_extra_parents(orig_parents, parents)
29812981
commit.parents = parents
29822982

29832983
# Call the user-defined callback, if any
@@ -2986,11 +2986,11 @@ class RepoFilter(object):
29862986

29872987
# Now print the resulting commit, or if prunable skip it
29882988
if not commit.dumped:
2989-
if not self.prunable(commit, new_1st_parent, aux_info['had_file_changes'],
2990-
orig_parents):
2989+
if not self._prunable(commit, new_1st_parent,
2990+
aux_info['had_file_changes'], orig_parents):
29912991
self._seen_refs[commit.branch] = None # was seen, doesn't need reset
29922992
commit.dump(self._output)
2993-
self.record_remapping(commit, orig_parents)
2993+
self._record_remapping(commit, orig_parents)
29942994
else:
29952995
rewrite_to = new_1st_parent or commit.first_parent()
29962996
# We skip empty commits, but want to keep track to make sure our branch
@@ -3006,23 +3006,23 @@ class RepoFilter(object):
30063006
self._progress_writer.show(self._parsed_message % self._num_commits)
30073007

30083008
@staticmethod
3009-
def do_tag_rename(rename_pair, tagname):
3009+
def _do_tag_rename(rename_pair, tagname):
30103010
old, new = rename_pair.split(b':', 1)
30113011
old, new = b'refs/tags/'+old, b'refs/tags/'+new
30123012
if tagname.startswith(old):
30133013
return tagname.replace(old, new, 1)
30143014
return tagname
30153015

3016-
def handle_tag(self, tag):
3016+
def _tweak_tag(self, tag):
30173017
# Tweak the tag message according to callbacks
30183018
if self._message_callback:
30193019
tag.message = self._message_callback(tag.message)
30203020

3021-
# Tweak the tag name according to callbacks
3021+
# Tweak the tag name according to tag-name-related callbacks
30223022
tag_prefix = b'refs/tags/'
30233023
fullref = tag_prefix+tag.ref
30243024
if self._args.tag_rename:
3025-
fullref = RepoFilter.do_tag_rename(self._args.tag_rename, fullref)
3025+
fullref = RepoFilter._do_tag_rename(self._args.tag_rename, fullref)
30263026
if self._refname_callback:
30273027
fullref = self._refname_callback(fullref)
30283028
if not fullref.startswith(tag_prefix):
@@ -3045,13 +3045,13 @@ class RepoFilter(object):
30453045
if tag.from_ref:
30463046
self._seen_refs[fullref] = None
30473047

3048-
# Tweak all aspects of the tag according to callback
3048+
# Call general purpose tag callback
30493049
if self._tag_callback:
30503050
self._tag_callback(tag)
30513051

3052-
def handle_reset(self, reset):
3052+
def _tweak_reset(self, reset):
30533053
if self._args.tag_rename:
3054-
reset.ref = RepoFilter.do_tag_rename(self._args.tag_rename, reset.ref)
3054+
reset.ref = RepoFilter._do_tag_rename(self._args.tag_rename, reset.ref)
30553055
if self._refname_callback:
30563056
reset.ref = self._refname_callback(reset.ref)
30573057
if self._reset_callback:
@@ -3344,10 +3344,10 @@ class RepoFilter(object):
33443344
if self._input:
33453345
# Create and run the filter
33463346
self._repo_working_dir = self._args.source or b'.'
3347-
fef = FastExportParser(blob_callback = self.tweak_blob,
3348-
commit_callback = self.tweak_commit,
3349-
tag_callback = self.handle_tag,
3350-
reset_callback = self.handle_reset,
3347+
fef = FastExportParser(blob_callback = self._tweak_blob,
3348+
commit_callback = self._tweak_commit,
3349+
tag_callback = self._tweak_tag,
3350+
reset_callback = self._tweak_reset,
33513351
done_callback = self._handle_final_commands)
33523352
fef.run(self._input, self._output)
33533353
if not self._finalize_handled:

0 commit comments

Comments
 (0)