filter-repo (python3): ensure stdin and args are bytes instead of strings

Signed-off-by: Elijah Newren <newren@gmail.com>
This commit is contained in:
Elijah Newren 2019-04-27 11:32:40 -07:00
parent effcd5b9ff
commit 8b8d6b4b43
2 changed files with 15 additions and 11 deletions

View File

@ -1897,16 +1897,17 @@ class FilteringOptions(object):
"files matching none of those options.")) "files matching none of those options."))
path.add_argument('--path-match', '--path', metavar='DIR_OR_FILE', path.add_argument('--path-match', '--path', metavar='DIR_OR_FILE',
type=os.fsencode,
action=FilteringOptions.AppendFilter, dest='path_changes', action=FilteringOptions.AppendFilter, dest='path_changes',
help=_("Exact paths (files or directories) to include in filtered " help=_("Exact paths (files or directories) to include in filtered "
"history. Multiple --path options can be specified to get " "history. Multiple --path options can be specified to get "
"a union of paths.")) "a union of paths."))
path.add_argument('--path-glob', metavar='GLOB', path.add_argument('--path-glob', metavar='GLOB', type=os.fsencode,
action=FilteringOptions.AppendFilter, dest='path_changes', action=FilteringOptions.AppendFilter, dest='path_changes',
help=_("Glob of paths to include in filtered history. Multiple " help=_("Glob of paths to include in filtered history. Multiple "
"--path-glob options can be specified to get a union of " "--path-glob options can be specified to get a union of "
"paths.")) "paths."))
path.add_argument('--path-regex', metavar='REGEX', path.add_argument('--path-regex', metavar='REGEX', type=os.fsencode,
action=FilteringOptions.AppendFilter, dest='path_changes', action=FilteringOptions.AppendFilter, dest='path_changes',
help=_("Regex of paths to include in filtered history. Multiple " help=_("Regex of paths to include in filtered history. Multiple "
"--path-regex options can be specified to get a union of " "--path-regex options can be specified to get a union of "
@ -1914,31 +1915,32 @@ class FilteringOptions(object):
rename = parser.add_argument_group(title=_("Renaming based on paths")) rename = parser.add_argument_group(title=_("Renaming based on paths"))
rename.add_argument('--path-rename', '--path-rename-prefix', rename.add_argument('--path-rename', '--path-rename-prefix',
metavar='OLD_NAME:NEW_NAME', dest='path_changes', metavar='OLD_NAME:NEW_NAME', dest='path_changes', type=os.fsencode,
action=FilteringOptions.AppendFilter, action=FilteringOptions.AppendFilter,
help=_("Prefix to rename; if filename starts with OLD_NAME, " help=_("Prefix to rename; if filename starts with OLD_NAME, "
"replace that with NEW_NAME. Multiple --path-rename " "replace that with NEW_NAME. Multiple --path-rename "
"options can be specified.")) "options can be specified."))
refrename = parser.add_argument_group(title=_("Renaming of refs")) refrename = parser.add_argument_group(title=_("Renaming of refs"))
refrename.add_argument('--tag-rename', metavar='OLD:NEW', refrename.add_argument('--tag-rename', metavar='OLD:NEW', type=os.fsencode,
help=_("Rename tags starting with OLD to start with NEW. For " help=_("Rename tags starting with OLD to start with NEW. For "
"example, --tag-rename foo:bar will rename tag foo-1.2.3 " "example, --tag-rename foo:bar will rename tag foo-1.2.3 "
"to bar-1.2.3; either OLD or NEW can be empty.")) "to bar-1.2.3; either OLD or NEW can be empty."))
helpers = parser.add_argument_group(title=_("Shortcuts")) helpers = parser.add_argument_group(title=_("Shortcuts"))
helpers.add_argument('--subdirectory-filter', metavar='DIRECTORY', helpers.add_argument('--subdirectory-filter', metavar='DIRECTORY',
action=FilteringOptions.HelperFilter, action=FilteringOptions.HelperFilter, type=os.fsencode,
help=_("Only look at history that touches the given subdirectory " help=_("Only look at history that touches the given subdirectory "
"and treat that directory as the project root. Equivalent " "and treat that directory as the project root. Equivalent "
"to using '--path DIRECTORY/ --path-rename DIRECTORY/:'")) "to using '--path DIRECTORY/ --path-rename DIRECTORY/:'"))
helpers.add_argument('--to-subdirectory-filter', metavar='DIRECTORY', helpers.add_argument('--to-subdirectory-filter', metavar='DIRECTORY',
action=FilteringOptions.HelperFilter, action=FilteringOptions.HelperFilter, type=os.fsencode,
help=_("Treat the project root as instead being under DIRECTORY. " help=_("Treat the project root as instead being under DIRECTORY. "
"Equivalent to using '--path-rename :DIRECTORY/'")) "Equivalent to using '--path-rename :DIRECTORY/'"))
people = parser.add_argument_group(title=_("Filtering of names/emails")) people = parser.add_argument_group(title=_("Filtering of names/emails"))
people.add_argument('--mailmap', dest='mailmap', metavar='FILENAME', people.add_argument('--mailmap', dest='mailmap', metavar='FILENAME',
type=os.fsencode,
help=_("Use specified mailmap file (see git-shortlog(1) for " help=_("Use specified mailmap file (see git-shortlog(1) for "
"details on the format) when rewriting author, committer, " "details on the format) when rewriting author, committer, "
"and tagger names and emails. If the specified file is " "and tagger names and emails. If the specified file is "
@ -1988,8 +1990,9 @@ class FilteringOptions(object):
"CALLBACKS section below.")) "CALLBACKS section below."))
location = parser.add_argument_group(title=_("Location to filter from/to")) location = parser.add_argument_group(title=_("Location to filter from/to"))
location.add_argument('--source', help=_("Git repository to read from")) location.add_argument('--source', type=os.fsencode,
location.add_argument('--target', help=_("Git repository to read from"))
location.add_argument('--target', type=os.fsencode,
help=_("Git repository to overwrite with filtered history")) help=_("Git repository to overwrite with filtered history"))
misc = parser.add_argument_group(title=_("Miscellaneous options")) misc = parser.add_argument_group(title=_("Miscellaneous options"))
@ -2947,7 +2950,8 @@ class RepoFilter(object):
def _setup_input(self, use_done_feature): def _setup_input(self, use_done_feature):
if self._args.stdin: if self._args.stdin:
self._input = sys.stdin self._input = sys.stdin.detach()
sys.stdin = None # Make sure no one tries to accidentally use it
self._fe_orig = None self._fe_orig = None
else: else:
skip_blobs = (self._blob_callback is None and skip_blobs = (self._blob_callback is None and

View File

@ -58,8 +58,8 @@ filter = fr.FastExportFilter('.',
checkpoint_callback = handle_checkpoint, checkpoint_callback = handle_checkpoint,
everything_callback = track_everything) everything_callback = track_everything)
filter.run(input = sys.stdin, filter.run(input = sys.stdin.detach(),
output = open(os.devnull, 'w'), output = open(os.devnull, 'wb'),
fast_import_pipes = None, fast_import_pipes = None,
quiet = True) quiet = True)
# DO NOT depend upon or use _IDS directly you external script writers. I'm # DO NOT depend upon or use _IDS directly you external script writers. I'm