filter-repo: actually fix issue with pruning of empty commits

In commit 509a624 (filter-repo: fix issue with pruning of empty commits,
2019-10-03), it was noted that when the first parent is pruned away,
then we need to generate a corrected list of file changes relative to
the new first parent.  Unfortunately, we did not apply our set of file
filters to that new list of file changes, causing us to possibly
introduce many unwanted files from the second parent into the history.
The testcase added at the time was rather lax and totally missed this
problem (which possibly exacerbated the original bug being fixed rather
than helping).  Tighten the testcase, and fix the error by filtering the
generated list of file changes.

Signed-off-by: Elijah Newren <newren@gmail.com>
pull/43/head
Elijah Newren 5 years ago
parent 2b32276ca3
commit a9a93d9d83

@ -3298,14 +3298,6 @@ class RepoFilter(object):
orig_file_changes = set(commit.file_changes)
self._filter_files(commit)
# Find out which files were modified by the callbacks. Such paths could
# lead to sebsequent commits being empty (e.g. if removed a line containing
# a password from every version of a file that had the password, and some
# later commit did nothing more than remove that line)
final_file_changes = set(commit.file_changes)
differences = orig_file_changes.symmetric_difference(final_file_changes)
self._files_tweaked.update(x.filename for x in differences)
# Record ancestry graph
parents, orig_parents = commit.parents, aux_info['orig_parents']
if self._args.state_branch:
@ -3328,6 +3320,16 @@ class RepoFilter(object):
commit.file_changes = GitUtils.get_file_changes(self._repo_working_dir,
ID_TO_HASH[parents[0]],
commit.original_id)
orig_file_changes = set(commit.file_changes)
self._filter_files(commit)
# Find out which files were modified by the callbacks. Such paths could
# lead to sebsequent commits being empty (e.g. if removed a line containing
# a password from every version of a file that had the password, and some
# later commit did nothing more than remove that line)
final_file_changes = set(commit.file_changes)
differences = orig_file_changes.symmetric_difference(final_file_changes)
self._files_tweaked.update(x.filename for x in differences)
# Call the user-defined callback, if any
if self._commit_callback:

@ -1323,6 +1323,7 @@ test_expect_success 'degenerate merge with non-matching filenames' '
git reset --hard &&
mkdir -p pkg/list &&
test_commit pkg/list/whatever &&
test_commit unwanted_file &&
git checkout A &&
git merge --allow-unrelated-histories --no-commit B &&
@ -1333,8 +1334,9 @@ test_expect_success 'degenerate merge with non-matching filenames' '
git filter-repo --force --path pkg/list &&
! test_path_is_file pkg/list/whatever.t &&
git ls-files >files &&
! grep pkg/list/whatever.t files
git ls-files >actual
echo pkg/list/wanted >expect &&
test_cmp expect actual
)
'

Loading…
Cancel
Save