From c8a96d468455df2640f33e0de2f305ee30f37805 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Fri, 9 Nov 2018 11:32:38 -0800 Subject: [PATCH] filter-repo: add --subdirectory-filter and --to-subdirectory-filter Signed-off-by: Elijah Newren --- git-filter-repo | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/git-filter-repo b/git-filter-repo index 01768af..ed3e8af 100755 --- a/git-filter-repo +++ b/git-filter-repo @@ -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.''')