Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance(diff): faster rename detection #550

Merged
merged 18 commits into from
Aug 13, 2024
Merged
Prev Previous commit
Next Next commit
Make test case illustrate edge case
  • Loading branch information
Northo committed Aug 12, 2024
commit cccf5e0039735a97eb1a6b1a3e463a1a5390c448
23 changes: 14 additions & 9 deletions tests/index/test_diff.py
Original file line number Diff line number Diff line change
@@ -70,32 +70,37 @@ def entry(key):
)

old_foo_entry = entry(("foo",))
old_bar_entry = entry(("bar",))
old = DataIndex({
("foo",): old_foo_entry,
old_foo_entry.key: old_foo_entry,
old_bar_entry.key: old_bar_entry,
})

assert set(diff(old, old, with_unchanged=True)) == {
Change(UNCHANGED, old_foo_entry, old_foo_entry),
Change(UNCHANGED, old_bar_entry, old_bar_entry),
}
assert set(diff(old, old, with_renames=True, with_unchanged=True)) == {
Change(UNCHANGED, old_foo_entry, old_foo_entry),
Change(UNCHANGED, old_bar_entry, old_bar_entry),
}

new_foo_1 = entry(("a/foo.txt",))
new_foo_2 = entry(("foo.md",))
new_foo_entry = entry(("foo.txt",))
new_bar_entry = entry(("zab", "bar",))
new = DataIndex({
new_foo_1.key: new_foo_1,
new_foo_2.key: new_foo_2,
new_foo_entry.key: new_foo_entry,
new_bar_entry.key: new_bar_entry,
})

assert set(diff(old, new, with_unchanged=True)) == {
Change(ADD, None, new_foo_1),
Change(ADD, None, new_foo_2),
Change(ADD, None, new_foo_entry),
Change(ADD, None, new_bar_entry),
Change(DELETE, old_foo_entry, None),
Change(DELETE, old_bar_entry, None),
}
assert set(diff(old, new, with_renames=True, with_unchanged=True)) == {
Change(RENAME, old_foo_entry, new_foo_1),
Change(ADD, None, new_foo_2),
Change(RENAME, old_foo_entry, new_foo_entry),
Change(RENAME, old_bar_entry, new_bar_entry),
}