From cf460406d77669a2ec05ea85d8e50ce8799e271d Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Sat, 1 Sep 2018 12:08:01 -0700 Subject: [PATCH] filter-repo: code cleanup Slightly re-order the code to make input, output, and filtering sections distinct. Also, avoid running `git fast-import` at all when we're in --dry-run mode. Signed-off-by: Elijah Newren --- git-filter-repo | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/git-filter-repo b/git-filter-repo index b966bb2..4d2de96 100755 --- a/git-filter-repo +++ b/git-filter-repo @@ -1275,16 +1275,9 @@ def run_fast_filter(): if not os.path.isdir(results_tmp_dir): os.mkdir(results_tmp_dir) - # Do actual filtering + # Determine whether to make a copy of input fep_cmd = ['git', 'fast-export', '--no-data'] + args.revisions - fip_cmd = 'git fast-import --force --quiet'.split() fep = subprocess.Popen(fep_cmd, stdout=subprocess.PIPE) - fip = subprocess.Popen(fip_cmd, stdin=subprocess.PIPE) - filter = FastExportFilter( - commit_callback = lambda c : tweak_commit(args, c), - ) - - # Determine whether to make a copy of input input = fep.stdout if args.dry_run or args.debug: fe_orig = os.path.join(results_tmp_dir, 'fast-export.original') @@ -1295,16 +1288,23 @@ def run_fast_filter(): print(" (saving a copy of the output at {})".format(fe_orig)) # Determine where to send output - output = fip.stdin + if not args.dry_run: + fip_cmd = 'git fast-import --force --quiet'.split() + fip = subprocess.Popen(fip_cmd, stdin=subprocess.PIPE) if args.dry_run or args.debug: fe_filt = os.path.join(results_tmp_dir, 'fast-export.filtered') output = open(fe_filt, 'w') + else: + output = fip.stdin if args.debug: output = DualFileWriter(fip.stdin, output) print("[DEBUG] Running: {}".format(' '.join(fip_cmd))) print(" (using the following file as input: {})".format(fe_filt)) - # Run the filter + # Create and run the filter + filter = FastExportFilter( + commit_callback = lambda c : tweak_commit(args, c), + ) filter.run(input, output) # Close the output, ensure fast-export and fast-import have completed