Skip to content

Commit

Permalink
Merge branch 'ta/cleanup-callback-scope'
Browse files Browse the repository at this point in the history
Signed-off-by: Elijah Newren <newren@gmail.com>
  • Loading branch information
newren committed Jul 7, 2024
2 parents ca28194 + 2cb3bcb commit 4c5ad09
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions git-filter-repo
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ __all__ = ["Blob", "Reset", "FileChange", "Commit", "Tag", "Progress",
"string_to_date", "date_to_string",
"record_id_rename", "GitUtils", "FilteringOptions", "RepoFilter"]

# The globals to make visible to callbacks. They will see all our imports for
# free, as well as our public API.
public_globals = ["__builtins__", "argparse", "collections", "fnmatch",
"gettext", "io", "os", "platform", "re", "shutil",
"subprocess", "sys", "time", "textwrap", "tzinfo",
"timedelta", "datetime"] + __all__

deleted_hash = b'0'*40
write_marks = True
date_format_permissive = True
Expand Down Expand Up @@ -2844,9 +2851,11 @@ class RepoFilter(object):

def _handle_arg_callbacks(self):
def make_callback(argname, str):
callback_globals = {g: globals()[g] for g in public_globals}
callback_locals = {}
exec('def callback({}, _do_not_use_this_var = None):\n'.format(argname)+
' '+'\n '.join(str.splitlines()), globals())
return callback #namespace['callback']
' '+'\n '.join(str.splitlines()), callback_globals, callback_locals)
return callback_locals['callback']
def handle(type):
callback_field = '_{}_callback'.format(type)
code_string = getattr(self._args, type+'_callback')
Expand Down

0 comments on commit 4c5ad09

Please sign in to comment.