filter-repo: add --subdirectory-filter and --to-subdirectory-filter

Signed-off-by: Elijah Newren <newren@gmail.com>
This commit is contained in:
Elijah Newren 2018-11-09 11:32:38 -08:00
parent e36a62c2c7
commit c8a96d4684

View File

@ -1514,6 +1514,19 @@ class AppendFilter(argparse.Action):
items.append((mod_type, match_type, values))
setattr(namespace, self.dest, items)
class HelperFilter(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
af = AppendFilter(dest='path_changes', option_strings=None)
dirname = values if values[-1] == '/' else values+'/'
if option_string == '--subdirectory-filter':
af(parser, namespace, dirname, '--path-match')
af(parser, namespace, dirname+':', '--path-rename')
elif option_string == '--to-subdirectory-filter':
af(parser, namespace, ':'+dirname, '--path-rename')
else:
raise SystemExit("Error: HelperFilter given invalid option_string: {}"
.format(option_string))
def get_args():
# Include usage in the summary, so we can put the description first
summary = '''Rewrite (or analyze) repository history
@ -1598,6 +1611,19 @@ def get_args():
tag foo-1.2.3 to bar-1.2.3; either OLD or NEW
can be empty.''')
helpers = parser.add_argument_group(title='Shortcuts')
helpers.add_argument('--subdirectory-filter', metavar='DIRECTORY',
action=HelperFilter,
help='''Only look at history that touches the given
subdirectory and treat that directory as the
project root. Equivalent to using
"--path DIRECTORY/ --path-rename DIRECTORY/:"''')
helpers.add_argument('--to-subdirectory-filter', metavar='DIRECTORY',
action=HelperFilter,
help='''Treat the project root as instead being under
DIRECTORY. Equivalent to using
"--path-rename :DIRECTORY/"''')
misc = parser.add_argument_group(title='Miscellaneous options')
misc.add_argument('--help', '-h', action='store_true',
help='''Show this help message and exit.''')